Skip to content

Commit

Permalink
REF: improvements to pyproject.toml vs setup.py license file handling (
Browse files Browse the repository at this point in the history
  • Loading branch information
lizgehret authored Aug 23, 2024
1 parent c8cd6b8 commit e0a79a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
python-version: 3.9

- name: install dependencies
run: python -m pip install --upgrade pip
run: |
python -m pip install --upgrade pip
pip install toml
- name: lint and test
run: |
Expand Down
25 changes: 23 additions & 2 deletions q2lint/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pathlib
import sys
import re
import toml


YEAR_PLACEHOLDER = "COPYRIGHT_YEARS" # chosen to avoid re.escape replacement
Expand Down Expand Up @@ -103,8 +104,28 @@ def validate_project(install_requires):
else:
errors.append('Missing LICENSE file')

for filepath in (pathlib.Path('.').glob('**/*.py')
and pathlib.Path('.').glob('**/pyproject.toml')):
# setup some filepath shortcuts
pyproject_toml = pathlib.Path('pyproject.toml')
setup_py = pathlib.Path('setup.py')

# Handle license file for pyproject.toml & setup.py
if pyproject_toml.exists():
data = toml.load(pyproject_toml)
try:
license_info = data.get('project', {}).get('license', {})
if not license_info or license_info != {'file': 'LICENSE'}:
errors.append(
"Missing BSD-3-Clause license in `pyproject.toml`")
except Exception as e:
errors.append(f'Error parsing `pyproject.toml`: {e}')
else:
with setup_py.open('r') as fh:
text = fh.read()
if ("license='BSD-3-Clause'" not in text and
'license="BSD-3-Clause"' not in text):
errors.append("Missing BSD-3-Clause license in `setup.py`")

for filepath in pathlib.Path('.').glob('**/*.py'):
if str(filepath).startswith('build/'):
continue
if filepath.name in ('_version.py', 'versioneer.py'):
Expand Down

0 comments on commit e0a79a4

Please sign in to comment.