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

Adding ASDF support to interpreter-search-paths #12028

Merged
merged 1 commit into from
Jul 14, 2021

Conversation

cjntaylor
Copy link
Contributor

Adding ASDF (https://asdf-vm.com) support to the python interpreter-search-paths option, through an additional special strings (<ASDF>, <ASDF_LOCAL>). ASDF wraps pyenv (and python-build) internally, but relocates and adapts its layout and configuration so it conforms to the standards it employs.

The implementation avoids calling ASDF directly as it requires heavy use of an agumented shell (source $ASDF_DIR/asdf.sh) and a supported interpreter. Instead, it minimally re-implements the configuration and layout algorithm used by the tool to find the direct path to python interpreters, based on its standard mode of operation. This is to say, the implementation is ASDF "compatible", but may need adaptation as the tool and python plugin change over time (although the basic principles used are very unlikely to change in any way that would affect functionality).

ASDF does provide support for many other languages/interpreters; additional tools could be added in the future (how they should be integrated, and how that would affect this plugin is TBD).

@cjntaylor cjntaylor force-pushed the asdf branch 2 times, most recently from 3aa364c to 641d7c5 Compare May 13, 2021 04:42
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Hey @cjntaylor, pardon for the really long delay on this! The past two weeks were really busy with Pycon.

Thank you for the contribution!

src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
@njgrisafi
Copy link

@cjntaylor this PR is great! We're looking to also use asdf with Pants as well. @chipola and I would be happy to help implement feedback if needed.

Copy link
Contributor Author

@cjntaylor cjntaylor left a comment

Choose a reason for hiding this comment

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

Sorry for the huge delay all - I got called away to a rather complicated project for work and I just now resurfaced. I made the adjustments you requested @Eric-Arellano, and I rebased this branch up to the current master just to make things current. Everything you suggested was reasonable, with the exception of a few things I left open below. Let me know what you think.

Thanks for your help 😄

src/python/pants/python/python_setup.py Show resolved Hide resolved
@cjntaylor
Copy link
Contributor Author

@cjntaylor this PR is great! We're looking to also use asdf with Pants as well. @chipola and I would be happy to help implement feedback if needed.

Yay! Great to know that there are others out there who are also part of the ASDF user community. It's helpful to motivate that I'm not an isolated case 😅

Apologies for the delay, and thanks for the offer of help - I think we're good to go on implementation but I'll definitely take you up on that in the future 👍. It's really nice to get actual feedback and eager participants over just a bunch of +1's for once 😁

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks for following up on this @cjntaylor!

src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Show resolved Hide resolved
src/python/pants/python/python_setup_test.py Outdated Show resolved Hide resolved
@@ -49,6 +53,57 @@ def fake_pyenv_root(fake_versions, fake_local_version):
yield pyenv_root, fake_version_dirs, fake_local_version_dirs


def materialize_indices(sequence: Sequence[_T], indices: Iterable[int]) -> Tuple[_T, ...]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be better as an inner function defined inside fake_asdf_root. It's only used there currently, and would help with namespacing.

Copy link
Contributor Author

@cjntaylor cjntaylor Jul 9, 2021

Choose a reason for hiding this comment

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

It's actually also used in test_get_asdf_paths and test_expand_interpreter_search_paths as well. I believe that's why it was pulled out in the first place (it's a tiny helper function; normally I would have done exactly as you're suggesting - just writtten it as an inner function instead).

src/python/pants/python/python_setup_test.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
src/python/pants/python/python_setup.py Outdated Show resolved Hide resolved
@cjntaylor cjntaylor force-pushed the asdf branch 4 times, most recently from 5cebed9 to 4c7803f Compare July 13, 2021 15:57
@cjntaylor
Copy link
Contributor Author

cjntaylor commented Jul 13, 2021

I fixed the issue with the typing. I'll try to remember in the future I need to run typecheck in addition to lint - it's a bit odd to me that these two goals are separate; I didn't even realize the former was a thing until I went looking for it.

@Eric-Arellano
Copy link
Contributor

I'll try to remember in the future I need to run typecheck in addition to lint - it's a bit odd to me that these two goals are separate; I didn't even realize the former was a thing until I went looking for it.

We went with this design in large part to facilitate that you normally want to run ./pants --changed-since=HEAD lint but ./pants --changed-since=HEAD --changed-dependees=transitive typcheck. But agreed they are similar.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! One non-blocking comment, and one blocking comment.

src/python/pants/python/python_setup.py Show resolved Hide resolved
@@ -255,6 +391,16 @@ def get_pyenv_paths(env: Environment, *, pyenv_local: bool = False) -> List[str]
return paths


def get_asdf_dir(env: Environment) -> PurePath | None:
"""See https://asdf-vm.com/#/core-configuration?id=environment-variables."""
asdf_dir = env.get("ASDF_DIR", env.get("ASDF_DATA_DIR"))
Copy link
Member

Choose a reason for hiding this comment

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

These environment variables have not been include-listed into the Environment that will be exposed to the @rules which call PythonSetup.interpreter_search_paths: the primary caller we care about is find_pex_pythons:

pex_relevant_environment = await Get(
Environment, EnvironmentRequest(["PATH", "HOME", "PYENV_ROOT"])
)
.

Without doing so, this code will never observe those variables, because they will be filtered out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless I've misunderstood, I've added the requested variables to the whitelist so that it will function as expected. Is there more that needs to be done?

Copy link
Member

@stuhood stuhood Jul 14, 2021

Choose a reason for hiding this comment

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

Not that I know of off the top of my head, but: actually trying it on your machine and confirming that you're seeing it working is your best bet. I don't have ASDF installed (yet), and it doesn't seem worth the trouble to bootstrap it in your integration tests (yet).

Adding [ASDF](https://asdf-vm.com) support to the python interpreter-search-paths option, through an additional special strings (<ASDF>, <ASDF_LOCAL>). ASDF actually wraps pyenv (and python-build) internally, but relocates and adapts its layout and configuration so it conforms to the standards it employs.

The implementation avoids calling ASDF directly as it requires heavy use of an agumented shell (source $ASDF_DIR/asdf.sh) and a supported interpreter. Instead, it minimally re-implements the configuration and layout algorithm used by the tool to find the direct path to python interpreters, based on its standard mode of operation. This is to say, the implementation is ASDF "compatible", but may need adaptation as the tool and python plugin change over time (although the basic principles used are very unlikely to change in any way that would affect functionality).

ASDF does provide support for many other languages/interpreters; additional tools could be added in the future (how they should be integrated, and how that would affect this plugin is TBD).

[ci skip-rust]

[ci skip-build-wheels]
@stuhood stuhood merged commit 7c544fd into pantsbuild:main Jul 14, 2021
@Eric-Arellano
Copy link
Contributor

Thanks for the contribution @cjntaylor ! This will go out into the upcoming 2.7 release on Friday.

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.

4 participants