Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dynamic dependencies with setuptools #724

Closed

Conversation

lispandfound
Copy link
Contributor

@lispandfound lispandfound commented Jun 6, 2024

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

This pull request adds support for dependencies dynamically specified when using setuptools. This fixes #421. The changes should not affect users of setuptools that do not use dynamic dependencies, as in this case it will revert to the PEP621 compliant dependency checker.

Known issue: if the specified file to source dependencies from does not exist, this code will crash. @fpgmaas what is the best way to present this error to the user?

@lispandfound
Copy link
Contributor Author

Will add tests and things later.

@lispandfound lispandfound marked this pull request as ready for review June 7, 2024 00:42
Copy link

codecov bot commented Jun 8, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.

Project coverage is 92.3%. Comparing base (8a3b0bd) to head (d7e9263).
Report is 150 commits behind head on main.

Files with missing lines Patch % Lines
python/deptry/dependency_getter/builder.py 77.7% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #724     +/-   ##
=======================================
- Coverage   92.8%   92.3%   -0.5%     
=======================================
  Files         35      35             
  Lines        920     946     +26     
  Branches     165     168      +3     
=======================================
+ Hits         854     874     +20     
- Misses        52      57      +5     
- Partials      14      15      +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fpgmaas
Copy link
Owner

fpgmaas commented Jun 8, 2024

Hey! Thanks for your contribution. I will check it out soon, I first need to sort out the bug in the CI/CD pipeline :)

@fpgmaas
Copy link
Owner

fpgmaas commented Jun 9, 2024

Could you please add a functional test? i.e.

@fpgmaas
Copy link
Owner

fpgmaas commented Jun 9, 2024

Looks like there were a few formatting issues; https://github.com/fpgmaas/deptry/actions/runs/9409803890/job/25970899533?pr=724. You can resolve this by installing the pre-commit hooks locally with poetry run pre-commit install.

@fpgmaas fpgmaas requested review from mkniewallner and fpgmaas June 9, 2024 08:27
@fpgmaas
Copy link
Owner

fpgmaas commented Jun 9, 2024

Known issue: if the specified file to source dependencies from does not exist, this code will crash. @fpgmaas what is the best way to present this error to the user?

I think in this case, it would be best to catch the FileNotFoundError, display a logging message to the user and exit.

docs/usage.md Outdated Show resolved Hide resolved
docs/usage.md Outdated Show resolved Hide resolved
)

raise DependencySpecificationNotFoundError(self.requirements_files)

def _project_uses_setuptools(self, pyproject_toml: dict[str, Any]) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _project_uses_setuptools(self, pyproject_toml: dict[str, Any]) -> bool:
@staticmethod
def _project_uses_setuptools(pyproject_toml: dict[str, Any]) -> bool:

)
return False

def _project_uses_dynamic_dependencies(self, pyproject_toml: dict[str, Any]) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _project_uses_dynamic_dependencies(self, pyproject_toml: dict[str, Any]) -> bool:
@staticmethod
def _project_uses_dynamic_dependencies(pyproject_toml: dict[str, Any]) -> bool:

)
return False

def _project_dynamic_requirements_file(self, pyproject_toml: dict[str, Any]) -> tuple[str, ...]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _project_dynamic_requirements_file(self, pyproject_toml: dict[str, Any]) -> tuple[str, ...]:
@staticmethod
def _project_dynamic_requirements_file(pyproject_toml: dict[str, Any]) -> tuple[str, ...]:

)

raise DependencySpecificationNotFoundError(self.requirements_files)

def _project_uses_setuptools(self, pyproject_toml: dict[str, Any]) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you move the 3 new methods between _project_uses_pdm and _project_uses_pep_621? That way we use the same order as the order methods are called from build method.

)
return False

def _project_dynamic_requirements_file(self, pyproject_toml: dict[str, Any]) -> tuple[str, ...]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can remove this method and make _project_uses_dynamic_dependencies return a tuple[bool, tuple[str, ...]], like

def _project_uses_requirements_files(self) -> tuple[bool, tuple[str, ...]]:
?

3. a `[tool.setuptools.dynamic]` section containing `dependencies = { file = [some_requirements_file] }`,

then _deptry_ will assume the project uses setuptools with dynamic dependencies. It will extract dependencies
from the file specified in the `[tool.setuptools.dynamic]` section.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
from the file specified in the `[tool.setuptools.dynamic]` section.
from the files specified in the `[tool.setuptools.dynamic]` section.

since this could be a list of files?

@mkniewallner mkniewallner added this to the 0.17 milestone Jun 16, 2024
@mkniewallner mkniewallner modified the milestones: 0.17, 0.18 Jul 21, 2024
@mkniewallner mkniewallner modified the milestones: 0.18, 0.20 Aug 10, 2024
@mkniewallner mkniewallner modified the milestones: 0.20, 0.21.0 Aug 27, 2024
@mkniewallner mkniewallner removed this from the 0.21.0 milestone Oct 21, 2024
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.

KeyError when pyproject.toml dependencies are dynamically read from requirements.txt
3 participants