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 FawltyDeps to automatically discover Python environments inside the project #326

Merged
merged 6 commits into from
Jul 14, 2023

Conversation

jherland
Copy link
Member

@jherland jherland commented May 8, 2023

(Depends on #325)

This is at the heart of solving #249, and IMHO one of the major pieces remaining in the Mapping Strategy milestone.

With this, FawltyDeps is able to:

  • automatically find Python environments inside the project directory (basepath)
  • automatically disregard files inside the Python environment for .code and .deps

Commits:

  • traverse_project: Add support for finding/validating Python environments
  • main: Use PyEnvSource objects when resolving dependencies
  • Update documentation related to Python environments

@jherland jherland added this to the Mapping strategy milestone May 8, 2023
@jherland jherland self-assigned this May 8, 2023
@jherland jherland requested review from mknorps and Nour-Mws May 8, 2023 20:15
@jherland jherland force-pushed the jherland/prepare-for-traversing-pyenvs branch from 626aa6c to b3d8bef Compare May 10, 2023 01:13
@jherland jherland force-pushed the jherland/traverse-pyenvs branch 2 times, most recently from f8b8261 to b6aa14e Compare May 10, 2023 01:22
@jherland jherland force-pushed the jherland/prepare-for-traversing-pyenvs branch from b3d8bef to 598c293 Compare May 12, 2023 09:17
@jherland jherland force-pushed the jherland/traverse-pyenvs branch from b6aa14e to 935cf82 Compare May 12, 2023 09:18
@jherland jherland force-pushed the jherland/prepare-for-traversing-pyenvs branch from 598c293 to 36a78ab Compare May 30, 2023 11:42
@jherland jherland force-pushed the jherland/traverse-pyenvs branch from 935cf82 to 6f455b1 Compare May 30, 2023 11:43
Base automatically changed from jherland/prepare-for-traversing-pyenvs to main June 6, 2023 07:48
@dpulls
Copy link

dpulls bot commented Jun 6, 2023

🎉 All dependencies have been resolved !

@jherland jherland force-pushed the jherland/traverse-pyenvs branch 2 times, most recently from 76d61c8 to 12fadc0 Compare June 6, 2023 09:21
Copy link
Collaborator

@mknorps mknorps left a comment

Choose a reason for hiding this comment

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

As usual Johan, your PRs are elegant, well written and are a great contribution to the project <3

I am posting a comment, not approval for now, as I have to go through tests and documentation. The comments are mostly nits or me making sure that I follow your line of thoughts :)

fawltydeps/types.py Show resolved Hide resolved
fawltydeps/cli_parser.py Outdated Show resolved Hide resolved
fawltydeps/packages.py Show resolved Hide resolved
fawltydeps/traverse_project.py Show resolved Hide resolved
fawltydeps/traverse_project.py Show resolved Hide resolved
fawltydeps/traverse_project.py Show resolved Hide resolved
fawltydeps/traverse_project.py Show resolved Hide resolved
Copy link
Collaborator

@mknorps mknorps left a comment

Choose a reason for hiding this comment

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

I think this is good to go 🚀 🎸

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
jherland added 5 commits July 14, 2023 12:25
In addition to finding/creating CodeSource and DepsSource objects in
traverse_project.find_sources(), we now also add support for PyEnvSource
objects. Each of these objects encapsulate a single directory within a
Python environment where we expect to find Python packages installed.

In addition to validating the settings.pyenvs paths (similar to what the
LocalPackageResolver constructor already does), this also adds the logic
to find new Python environments within the directories being traversed.

That is, until now we have only supported entries in settings.pyenvs
pointing directly to (a directory within) a Python environment, but with
this commit we can also start finding Python environments beneath a
given directory.

In others words: given a project containing a ".venv" subdir, we
previously needed 'pyenvs' to point directly at ".venv" in order to find
this Python environment, but with this commit we can soon support
'pyenvs' pointing at the project root and still be able to automatically
find ".venv" inside the project.

Nothing of this is user-visible yet, as we still require the high-level
business logic in fawltydeps.main to actually request, and use the new
PyEnvSource objects created in this commit.

Based on the recent additions to test_sample_projects and
sample_projects, we add a bunch of tests to verify that we are able to
both precisely specify which Python environments should be included in
our analysis, as well as being able to automatically find and use many
different Python environments given a more general specification.
This starts requesting PyEnvSource objects when we call
traverse_project.find_sources(), and pass the paths from these object on
to resolve_dependencies().

In other words, this commit is when we first start actually using the
new traversal logic for Python environments in FawltyDeps.

On the test side, we can finally remove the overly explicit
specification needed to correctly traverse/parse the pyenv_galore sample
project. Instead, this project is now successfully handled with default
settings:
 - pyenvs set to the project root is able to auto-detect all the Python
   environments found within.
 - As a result, there is no code, nor any deps files found (since the
   project consists of Python environments only).
Update README.md to reflect that we're now using the _current_ Python
environment (i.e. 'sys.path') only as an ultimate fallback when

 (a) `--pyenv` is not used, and
 (b) we're unable to find Python environments under 'basepath'.

Update the related FAQs accordingly.

Also update the --help text to reflect that `basepath` now also affect
Python environment calculation.
Add descriptions of each instance member in our new *Source classes.

Suggested-by: Maria Knorps <[email protected]>
The --code/--deps/--pyenv options was documented as defaulting to the
current directory (which is only true when basepaths is not used), and
basepaths was NOT documented as defaulting to the current directory.

The correct way to document this (which reflects the actual logic in the
code) is that --code/--deps/--pyenv all default to basepaths when not
given, and that basepaths default to the current directory when not
given.

With this change, a casual reader might have to follow the reference
from --code/--deps/--pyenv to basepaths to discover that the _ultimate_
default for these options is indeed the current directory. But at least
the relationships involving basepaths are now _correctly_ reflected in
out documentation.

Suggested-by: Maria Knorps <[email protected]>
@jherland jherland force-pushed the jherland/traverse-pyenvs branch from 488cf80 to 92f3f0d Compare July 14, 2023 14:11
@jherland jherland merged commit afde9fa into main Jul 14, 2023
@jherland jherland deleted the jherland/traverse-pyenvs branch July 14, 2023 14:28
jherland added a commit that referenced this pull request Jul 28, 2023
This is a rather embarrasing omission from PR #326 (Teach FawltyDeps to
automatically discover Python environments inside the project):

Although that PR did include code to traverse within a given --pyenv
path to find Python environments, the PR "forgot" to actually switch the
_default_ behavior of --pyenv:

The default value of settings.pyenvs remained an empty set, and there
were no changes to have basepath influence the value of settings.pyenvs.

This commit fixes that:

- When neither --pyenv nor basepath is given, settings.pyenvs should
  default to the current directory.
- When --pyenv is not given, but basepath is given, basepath should
  override the default settings.pyenvs.
- When --pyenv is given, it overrides basepath.

In short settings.pyenvs should behave exactly like .code and .deps.
jherland added a commit that referenced this pull request Jul 31, 2023
This is a rather embarrasing omission from PR #326 (Teach FawltyDeps to
automatically discover Python environments inside the project):

Although that PR did include code to traverse within a given --pyenv
path to find Python environments, the PR "forgot" to actually switch the
_default_ behavior of --pyenv:

The default value of settings.pyenvs remained an empty set, and there
were no changes to have basepath influence the value of settings.pyenvs.

This commit fixes that:

- When neither --pyenv nor basepath is given, settings.pyenvs should
  default to the current directory.
- When --pyenv is not given, but basepath is given, basepath should
  override the default settings.pyenvs.
- When --pyenv is given, it overrides basepath.

In short settings.pyenvs should behave exactly like .code and .deps.
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.

3 participants