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

Experiment: "deselecting" default dependencies using extras #18

Closed
wants to merge 2 commits into from

Conversation

abravalheri
Copy link
Contributor

This is an experiment to test the waters regarding the possibility discussed in pypa/setuptools#4457 (comment):

Yeah, I bemoan these transitive dependencies too. I would like to refactor some of these supporting libraries so that they have fewer unused dependencies (as inflect and autocommand are in many cases). This problem would be easier if packages could have "default extras" that could be deselected on install (or vendoring).

Although we don't yet have the concept of "default" extras in Python, we can implement "exclusion" extras with an environment marker: dependency==0.42; extra != "xyz".

This does however mean that the code has to be written in a way that it allows for the "deselected dependency" to lazily evaluated or not evaluated at all. When the import statement resides in an isolated submodule that is easy and does not require many changes. However if the import statement is in __init__.py or in a submodule that is imported in other parts of the codebase, things start to be more complicated.

The reason why I decided to try the experiment with jaraco.text is because it seems to be the dependency of setuptools that brings most transient dependencies with itself. According to pipdeptree:

importlib_metadata==8.2.0
  zipp==3.20.0
jaraco.text==4.0.0
  autocommand==2.2.2
  importlib_resources==6.4.2
    zipp==3.20.0
  jaraco.context==5.3.0
    backports.tarfile==1.2.0
  jaraco.functools==4.0.2
    more-itertools==10.4.0
  more-itertools==10.4.0
ordered-set==4.1.0
packaging==24.1
platformdirs==4.2.2
tomli==2.0.1
wheel==0.44.0

This PR is by no means exhaustive, I only implemented the 2 most obvious optional exclusions to me.

@@ -637,7 +648,8 @@ def lines_from(input):
"""
Generate lines from a :class:`importlib.resources.abc.Traversable` path.

>>> lines = lines_from(files(__name__).joinpath('Lorem ipsum.txt'))
>>> # from importlib_metadata import files as _files
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this comment here to help clarifying to the end-user reading the docstring where is the files function coming from.

@abravalheri abravalheri marked this pull request as ready for review August 16, 2024 11:29
@Avasam
Copy link
Contributor

Avasam commented Aug 16, 2024

If this solution is found acceptable (I think the main point of difference here being that it's for a temporary backport). Would a similar approach be applicable for jaraco.context's backports.tarfile? (see rejected #15 )

@abravalheri
Copy link
Contributor Author

abravalheri commented Aug 21, 2024

I did some tests and I was under the impression that the extra != ... marker works. I even remember seeing the output of pip list. But I was wrong and my memories deceiving.

extra != ... does not work, as explained in pypa/pip#8686 (comment).

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.

2 participants