Fix setup.py to read dependencies from requirements.in#6
Fix setup.py to read dependencies from requirements.in#6
Conversation
…uirements.txt The previous implementation incorrectly parsed pip-compile generated requirements.txt which included comment lines. This fix properly reads from the source requirements.in file and filters out comments and empty lines, ensuring only pycasbin (not casbin) is used as a dependency. Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Ensure the source requirements file is included in the package distribution since setup.py now reads from it. Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where setup.py was incorrectly parsing dependencies from the pip-compile generated requirements.txt file, which contained comment lines that were being treated as actual dependencies. The fix switches to reading from the clean requirements.in source file and adds proper filtering logic.
Key Changes
- Changed dependency source from
requirements.txttorequirements.infor clean, pip-compile-free declarations - Added filtering logic to skip empty lines and comment lines (lines starting with
#) - Included
requirements.inindata_filesfor source distribution alongsiderequirements.txt
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| all_reqs = f.read().split("\n") | ||
|
|
||
| install_requires = [x.strip() for x in all_reqs if "git+" not in x] | ||
| install_requires = [x.strip() for x in all_reqs if x.strip() and not x.startswith("#") and "git+" not in x] |
There was a problem hiding this comment.
The comment filtering check not x.startswith("#") is applied to the unstripped line x, while the empty line check uses x.strip(). This means a line with leading whitespace followed by # (e.g., " # comment") would not be filtered out and could be included in install_requires.
Apply the startswith("#") check to the stripped version:
install_requires = [x.strip() for x in all_reqs if x.strip() and not x.strip().startswith("#") and "git+" not in x]Or more efficiently, strip once:
stripped_reqs = [x.strip() for x in all_reqs]
install_requires = [x for x in stripped_reqs if x and not x.startswith("#") and "git+" not in x]| install_requires = [x.strip() for x in all_reqs if x.strip() and not x.startswith("#") and "git+" not in x] | |
| stripped_reqs = [x.strip() for x in all_reqs] | |
| install_requires = [x for x in stripped_reqs if x and not x.startswith("#") and "git+" not in x] |
The
setup.pywas reading dependencies from the pip-compile generatedrequirements.txt, which includes comment lines (e.g.,# via pydantic). These comments were incorrectly being parsed as dependencies.Changes
requirements.ininstead ofrequirements.txtfor clean dependency declarationsrequirements.inindata_filesfor source distributionPackage now correctly declares:
fastapi,pycasbin >= 2.0.0,pydantic >= 2.11.7, < 3.0.0Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.