lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.18-20-g90044e2

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.18-20-g90044e2



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  90044e27d9cbe49c8d8374732dfa8ddc10685ce0 (commit)
      from  62d15e9a446035288ec63f2a6e3882eda1a6ae5c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=90044e27d9cbe49c8d8374732dfa8ddc10685ce0

commit 90044e27d9cbe49c8d8374732dfa8ddc10685ce0
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri May 12 15:33:37 2023 +0200

    Add automated checking for correct license header

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c2f6643..1c13ee6 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -46,7 +46,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        tox_job: [docs, flake8]
+        tox_job: [docs, flake8, license]
     steps:
       - uses: actions/checkout@v3
       - name: Set up Python
diff --git a/scripts/check_license_headers.py b/scripts/check_license_headers.py
new file mode 100755
index 0000000..366fb79
--- /dev/null
+++ b/scripts/check_license_headers.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+
+# check_license_headers - check that all source files have licensing 
information
+#
+# Copyright (C) 2023 Arthur de Jong
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+"""This script checks that all source files have licensing information."""
+
+import glob
+import re
+import sys
+import textwrap
+
+
+# Regex to match standard license blurb
+license_re = re.compile(textwrap.dedent(r'''
+    [# ]*This library is free software; you can redistribute it and/or
+    [# ]*modify it under the terms of the GNU Lesser General Public
+    [# ]*License as published by the Free Software Foundation; either
+    [# ]*version 2.1 of the License, or .at your option. any later version.
+    [# ]*
+    [# ]*This library is distributed in the hope that it will be useful,
+    [# ]*but WITHOUT ANY WARRANTY; without even the implied warranty of
+    [# ]*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    [# ]*Lesser General Public License for more details.
+    [# ]*
+    [# ]*You should have received a copy of the GNU Lesser General Public
+    [# ]*License along with this library; if not, write to the Free Software
+    [# ]*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    [# ]*02110-1301 USA
+    ''').strip(), re.MULTILINE)
+
+
+def file_has_correct_license(filename):
+    """Check that the file contains a valid license header."""
+    with open(filename, 'rt') as f:
+        # Only read the first 2048 bytes to avoid loading too much and the
+        # license information should be in the first part anyway.
+        contents = f.read(2048)
+        return bool(license_re.search(contents))
+
+
+if __name__ == '__main__':
+    files_to_check = (
+        glob.glob('*.py') +
+        glob.glob('stdnum/**/*.py', recursive=True) +
+        glob.glob('tests/**/*.doctest', recursive=True) +
+        glob.glob('scripts/*', recursive=True) +
+        glob.glob('update/**/*.py', recursive=True) +
+        glob.glob('online_check/*.wsgi', recursive=True) +
+        glob.glob('online_check/check.js', recursive=True)
+    )
+
+    incorrect_files = [f for f in files_to_check if not 
file_has_correct_license(f)]
+    if incorrect_files:
+        print('Files with incorrect license information:')
+        print('\n'.join(incorrect_files))
+        sys.exit(1)
diff --git a/tox.ini b/tox.ini
index 3431c58..81c352b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py{27,35,36,37,38,39,310,311,py,py3},flake8,docs
+envlist = py{27,35,36,37,38,39,310,311,py,py3},flake8,docs,license
 skip_missing_interpreters = true
 
 [testenv]
@@ -34,3 +34,8 @@ commands = flake8 .
 use_develop = true
 deps = Sphinx
 commands = sphinx-build -N -b html docs {envtmpdir}/sphinx -W
+
+[testenv:license]
+skip_install = true
+deps =
+commands = python scripts/check_license_headers.py

-----------------------------------------------------------------------

Summary of changes:
 .github/workflows/test.yml       |  2 +-
 scripts/check_license_headers.py | 73 ++++++++++++++++++++++++++++++++++++++++
 tox.ini                          |  7 +++-
 3 files changed, 80 insertions(+), 2 deletions(-)
 create mode 100755 scripts/check_license_headers.py


hooks/post-receive
-- 
python-stdnum