Skip to content

Fix setup.py to read dependencies from requirements.in#6

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-fastapi-casbin-dependency
Closed

Fix setup.py to read dependencies from requirements.in#6
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-fastapi-casbin-dependency

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

The setup.py was reading dependencies from the pip-compile generated requirements.txt, which includes comment lines (e.g., # via pydantic). These comments were incorrectly being parsed as dependencies.

Changes

  • Read from requirements.in instead of requirements.txt for clean dependency declarations
  • Add filtering to skip empty lines and comments
  • Include requirements.in in data_files for source distribution
# Before: parsed all lines including comments
with open(path.join(here, "requirements.txt"), encoding="utf-8") as f:
    all_reqs = f.read().split("\n")
install_requires = [x.strip() for x in all_reqs if "git+" not in x]

# After: reads clean source file with proper filtering
with open(path.join(here, "requirements.in"), encoding="utf-8") as f:
    all_reqs = f.read().split("\n")
install_requires = [x.strip() for x in all_reqs if x.strip() and not x.startswith("#") and "git+" not in x]

Package now correctly declares: fastapi, pycasbin >= 2.0.0, pydantic >= 2.11.7, < 3.0.0

Original prompt

This section details on the original issue you should resolve

<issue_title>Casbin/PyCasbin Dependency Issue</issue_title>
<issue_description>fastapi-casbin-auth==1.20.0 seems to depend on casbin==1.43.0 instead of pycasbin.

From what I understood in Casbin vs. PyCasbin thread, it should depend on pycasbin.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI and others added 2 commits December 2, 2025 04:36
…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>
Copilot AI changed the title [WIP] Fix fastapi-casbin-auth dependency issue Fix setup.py to read dependencies from requirements.in Dec 2, 2025
Copilot AI requested a review from hsluoyz December 2, 2025 04:40
@hsluoyz hsluoyz marked this pull request as ready for review December 2, 2025 12:44
@hsluoyz hsluoyz requested a review from Copilot December 2, 2025 13:05
@hsluoyz hsluoyz closed this Dec 2, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.txt to requirements.in for clean, pip-compile-free declarations
  • Added filtering logic to skip empty lines and comment lines (lines starting with #)
  • Included requirements.in in data_files for source distribution alongside requirements.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]
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Suggested change
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]

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Casbin/PyCasbin Dependency Issue

2 participants