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

Support multiple --pyenv options #321

Merged
merged 3 commits into from
May 11, 2023
Merged

Support multiple --pyenv options #321

merged 3 commits into from
May 11, 2023

Conversation

jherland
Copy link
Member

@jherland jherland commented May 6, 2023

These are the commits that were originally part of #313, but now split into this PR.

Commits:

  • LocalPackageResolver: Accept multiple pyenvs
  • Add support for multiple --pyenv options
  • settings.print_toml_config(): Represent sets as sorted lists

@jherland jherland self-assigned this May 6, 2023
@jherland jherland requested review from mknorps and Nour-Mws May 6, 2023 01:05
@jherland jherland added this to the Mapping strategy milestone May 6, 2023
@jherland jherland force-pushed the jherland/multiple-pyenvs-2 branch from 654103d to 1b5204a Compare May 6, 2023 01:12
@jherland jherland force-pushed the jherland/multiple-pyenvs branch from 517775d to a10e43a Compare May 8, 2023 13:25
Base automatically changed from jherland/multiple-pyenvs to main May 8, 2023 13:50
@dpulls
Copy link

dpulls bot commented May 8, 2023

🎉 All dependencies have been resolved !

Copy link
Collaborator

@Nour-Mws Nour-Mws left a comment

Choose a reason for hiding this comment

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

Looks great as usual!
There's nothing that blocks this PR per se. Just a couple small questions that I hope will be straightforward. I am also fine either way for the suggestions I made.

tests/test_cmdline.py Outdated Show resolved Hide resolved
tests/test_settings.py Show resolved Hide resolved
tests/test_cmdline.py Show resolved Hide resolved
fawltydeps/packages.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@Nour-Mws Nour-Mws left a comment

Choose a reason for hiding this comment

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

Approving 🎉
I added comments to two conversations and resolved them.

This adds the core logic for FawltyDeps to become able to handle
multiple --pyenv arguments.

Instead of taking an optional 'pyenv_path', we now take a 'pyenv_paths'
set of paths; the new behavior is an extension of the old:

 - An empty set (corresponds to pyenv_path == None) implies that we use
   sys.path to look up packages.
 - A single-element set (corresponds to pyenv_path != None) will use the
   Python environment found at that path instead.
 - A multi-element set (new in this commit) causes packages to be looked
   up in _all_ the given Python environments. For packages that occur in
   more than one of these environments, the resulting Package object
   will _merge_ all the imports found among the various copies of this
   package (similar to how we deal with the same package occurring
   across multiple user-defined mappings).
@jherland jherland force-pushed the jherland/multiple-pyenvs-2 branch from ed8b82a to 4f26b83 Compare May 11, 2023 14:07
jherland added 2 commits May 11, 2023 16:15
This makes the support for multiple Python environment that was added
to LocalPackageResolver in the previous commit available to the rest of
FawltyDeps:

 - resolve_dependencies() now takes a pyenv_paths set instead of the
   previous optional pyenv_path.
 - Settings now has a 'pyenvs: Set[Path]' member instead of the previous
   'pyenv: Optional[Path]' member.
 - The CLI parser now accepts _multiple_ --pyenv argument values and
   collects them all into the 'pyenvs' set, similar to what we already
   do for --code and --deps.
 - A new paragraph in README.md explains that multiple --pyenv options
   are accepted, and how they are merged into one coherent package-to-
   import-names mapping.
 - The list of configuration directives updates the description for
   'pyenv' into 'pyenvs' accordingly.
In our --json output, we customize pydantic's JSON encoder to represent
sets as sorted lists (thus yielding stable output). Do the same for when
we generate TOML config output (which goes via a JSON encoding step, and
thus is subject to the same issue with how sets are encoded).

This was discovered while attempting to test how multiple 'pyenvs' were
represented in our TOML output.
@jherland jherland force-pushed the jherland/multiple-pyenvs-2 branch from 4f26b83 to af07e8e Compare May 11, 2023 14:16
@jherland jherland merged commit 9f34777 into main May 11, 2023
@jherland jherland deleted the jherland/multiple-pyenvs-2 branch May 11, 2023 14:22
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