Conversation
📝 WalkthroughWalkthroughReplace setuptools/setup.py packaging with a PEP 517 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/fosslight_prechecker/cli.py`:
- Around line 76-80: Wrap the call to importlib.metadata.files
(pkg_files(PKG_NAME)) in a try-except that catches
importlib.metadata.PackageNotFoundError so the code falls back to an empty
iterable instead of raising; update the block that builds license_files (the
list comprehension using pkg_files and PKG_NAME) to handle the exception and set
license_files = [] when the distribution is not found, ensuring downstream logic
that reads license_files still works.
- Around line 89-90: The blind "except Exception:" in the license output block
should be replaced with targeted exception handling: catch expected errors such
as FileNotFoundError, OSError, and UnicodeDecodeError around the file
reading/printing operation (the block currently guarded by "except Exception:"
in the license notice printing code) and write a concise warning including the
exception message to stderr (or use the existing logger) so users know the
notice couldn't be printed; let any other unexpected exceptions propagate rather
than silently swallowing them.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3b5104a3-0218-49a5-b6af-9b8d6f337d17
📒 Files selected for processing (2)
pyproject.tomlsrc/fosslight_prechecker/cli.py
| from importlib.metadata import files as pkg_files | ||
| license_files = [ | ||
| str(f.locate()) for f in (pkg_files(PKG_NAME) or []) | ||
| if 'licenses' in str(f).lower() and f.locate().is_file() | ||
| ] |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In Python importlib.metadata, what does files('<missing-distribution>') do? Does it raise PackageNotFoundError?
💡 Result:
In Python's importlib.metadata, calling files('<missing-distribution>') raises PackageNotFoundError because the distribution name '<missing-distribution>' does not correspond to an installed package. The files function first attempts to locate the named distribution, and if not found, it raises PackageNotFoundError before accessing any file metadata. The official documentation confirms: importlib.metadata.files(distribution_name) "Raises PackageNotFoundError if the named distribution package is not installed in the current Python environment." It returns None only if the distribution is found but the file listing metadata (RECORD or SOURCES.txt) is missing.
Citations:
- 1: https://docs.python.org/3/library/importlib.metadata.html
- 2: https://docs.python.org/3.11/library/importlib.metadata.html
- 3: https://importlib-metadata.readthedocs.io/en/stable/api.html
- 4: https://runebook.dev/en/docs/python/library/importlib.metadata/importlib.metadata.files
Handle missing distribution metadata explicitly.
The importlib.metadata.files() function raises PackageNotFoundError when the named distribution is not installed. The current code at lines 76–80 does not explicitly catch this exception, which could cause --notice to fail instead of degrading gracefully. Wrap the call to pkg_files(PKG_NAME) in a try-except block to catch PackageNotFoundError and fall back to an empty list.
🔧 Proposed fix
except AttributeError:
from importlib.metadata import files as pkg_files, PackageNotFoundError
- license_files = [
- str(f.locate()) for f in (pkg_files(PKG_NAME) or [])
+ try:
+ dist_files = pkg_files(PKG_NAME) or []
+ except PackageNotFoundError:
+ dist_files = []
+ license_files = [
+ str(f.locate()) for f in dist_files
if 'licenses' in str(f).lower() and f.locate().is_file()
]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| from importlib.metadata import files as pkg_files | |
| license_files = [ | |
| str(f.locate()) for f in (pkg_files(PKG_NAME) or []) | |
| if 'licenses' in str(f).lower() and f.locate().is_file() | |
| ] | |
| except AttributeError: | |
| from importlib.metadata import files as pkg_files, PackageNotFoundError | |
| try: | |
| dist_files = pkg_files(PKG_NAME) or [] | |
| except PackageNotFoundError: | |
| dist_files = [] | |
| license_files = [ | |
| str(f.locate()) for f in dist_files | |
| if 'licenses' in str(f).lower() and f.locate().is_file() | |
| ] |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/fosslight_prechecker/cli.py` around lines 76 - 80, Wrap the call to
importlib.metadata.files (pkg_files(PKG_NAME)) in a try-except that catches
importlib.metadata.PackageNotFoundError so the code falls back to an empty
iterable instead of raising; update the block that builds license_files (the
list comprehension using pkg_files and PKG_NAME) to handle the exception and set
license_files = [] when the distribution is not found, ensuring downstream logic
that reads license_files still works.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.github/workflows/publish-release.yml (1)
108-114: Pinbuildandtwineversions, and usepython -mfor consistency.Line 108 installs floating versions (
pip install build twine), which can break releases when upstream changes. Pin these tools explicitly and usepython -m pip installfor consistency. Additionally, line 115 uses directtwine uploadinstead ofpython -m twine upload, which should be aligned with thepython -m buildpattern.Suggested workflow diff
- pip install build twine + python -m pip install "build==1.4.2" "twine==6.2.0" ... - twine upload dist/* + python -m twine upload dist/*🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/publish-release.yml around lines 108 - 114, Update the "Build and publish" step to pin the versions of build and twine and to invoke pip and twine via python -m for consistency: replace the pip install command in the "Build and publish" job so it uses "python -m pip install build==<PIN_VERSION> twine==<PIN_VERSION>" (choose concrete versions), keep TWINE_USERNAME/TWINE_PASSWORD env, run "python -m build" (already used) and change the upload invocation to "python -m twine upload ..." so all tooling is executed via python -m and uses pinned versions; locate these changes in the "Build and publish" job block in the workflow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.github/workflows/publish-release.yml:
- Around line 108-114: Update the "Build and publish" step to pin the versions
of build and twine and to invoke pip and twine via python -m for consistency:
replace the pip install command in the "Build and publish" job so it uses
"python -m pip install build==<PIN_VERSION> twine==<PIN_VERSION>" (choose
concrete versions), keep TWINE_USERNAME/TWINE_PASSWORD env, run "python -m
build" (already used) and change the upload invocation to "python -m twine
upload ..." so all tooling is executed via python -m and uses pinned versions;
locate these changes in the "Build and publish" job block in the workflow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 75de6d35-0310-4df1-836e-331e6617a5ed
📒 Files selected for processing (10)
.bumpversion.cfg.github/workflows/publish-release.yml.reuse/dep5MANIFEST.inpyproject.tomlrequirements-dev.txtrequirements.txtsetup.pysrc/fosslight_prechecker/cli.pytox.ini
💤 Files with no reviewable changes (5)
- MANIFEST.in
- .bumpversion.cfg
- requirements-dev.txt
- requirements.txt
- setup.py
✅ Files skipped from review due to trivial changes (1)
- .reuse/dep5
🚧 Files skipped from review as they are similar to previous changes (2)
- src/fosslight_prechecker/cli.py
- pyproject.toml
Description
Summary by CodeRabbit
Bug Fixes
New Features
Chores