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

Teach packages.LocalPackageLookup to look at other venvs #215

Merged
merged 5 commits into from
Mar 14, 2023

Conversation

jherland
Copy link
Member

@jherland jherland commented Mar 13, 2023

This is the most basic building block towards decoupling the venv that FawltyDeps is installed in, from the venv that FawltyDeps is run against. From this we can work towards several goals in future PRs:

  • No longer require pip install fawltydeps into your project's venv, but instead e.g. pipx install fawltydeps to make FD available to all your projects.
  • Pass --venv as a command line option
  • Passing more than one venv
  • Auto-detecting and adding venvs under basepath (i.e. make --venv somewhat similar to --code and --deps)
  • Supporting a first approximation to using PyPI, by downloading/installing packages from PyPI into a temporary venv, and then pointing FD at that venv.
  • Changing our real_projects tests to no longer have to install/uninstall FD in the experiment's venv.

This PR is directly relevant to #161, and as such is also related to task 2 in the roadmap: #195. As far as #142 is still relevant, I suspect this might go a way towards fixing that as well. Furthermore, revisiting #187 is probably warranted after this PR is merged.

Commits:

  • pyproject.toml: Use latest importlib_metadata across all Python versions
  • Use importlib_metadata instead of importlib.metadata everywhere
  • packages: Teach LocalPackageLookup to start looking at other venvs
  • test_real_projects: Verify that all requirements are present
  • packages.LocalPackageLookup: Remove redundant sanity check

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.

Looking already great!

@jherland
Copy link
Member Author

Looking already great!

Thanks! Still have a fair amount of wrangling with Mypy (and Pylint, I suspect) to do. But I like the core structure of this.

@jherland jherland force-pushed the jherland/look-at-other-venv branch from a3c3f93 to 6ba869e Compare March 13, 2023 14:55
@jherland jherland marked this pull request as ready for review March 13, 2023 15:00
@jherland jherland changed the title WIP: packages: Teach LocalPackageLookup to start looking at other venvs Teach packages.LocalPackageLookup to look at other venvs Mar 13, 2023
@jherland jherland self-assigned this Mar 14, 2023
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 good. I haven't found anything to complain about :)

We're about to start relying on internal functions from
importlib_metadata. Although these are available via the stdlib module
importlib.metadata in Python v3.11, we are likely keep relying on
upcoming bugfixes from the importlib_metadata project, and it is
probably safer for us to _pin_ this 3rd-party dependency, so that we can
avoid breakage if/when its internal functions change.
We now depend on importlib_metadata for all of our supported Python
versions, so there's no need to differentiate between these imports.
This builds the base for making FawltyDeps able to find dep -> import
name mappings in a different venv to where FD itself is runnning,
including being able to peek at a virtualenv associated with a different
Python version (within reason).

We use some internal functions and functionality from importlib_metadata
to decouple ourselves from the current sys.path (and sys.meta_path), and
instead peek into the site-packages directory of another virtualenv
directory.

This commit adds the LocalPackageLookup API to fo this "remote" lookup,
and also adds a few basic tests to verify this new functionality.
LocalPackageLookup recently learned how to peek into another venv and
find its installed packages. Use this feature in test_real_projects to
verify that the requirements declared for the current Experiment are in
fact present, before we proceed with testing the expected result from
running FD on this Experiment.

This is a relatively cheap way, both to verify that our cached venvs are
OK, and to test that LocalPackageLookup in a different venv works
correctly.
When we added the venv_path argument to LocalPackageLookup, we retained
a sanity check for the default venv_path=None case, where we compared
the new method of building .packages against the old method method
(using packages_distributions()), and aborted if these were not 100%
equivalent.

After adding a test to test_real_projects, we have now verified that
this sanity check holds for all of the venvs we use as part of our
real_projects test. Since the sanity check has not triggered, we can
conclude that these methods are in fact equivalent, and we can drop
this sanity check.
@jherland jherland force-pushed the jherland/look-at-other-venv branch from 6ba869e to e75553d Compare March 14, 2023 11:37
@jherland jherland merged commit 5cb8e3e into main Mar 14, 2023
@jherland jherland deleted the jherland/look-at-other-venv branch March 14, 2023 11:44
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