-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Pants plugins: pack_metadata/python_imports #6260
Draft
cognifloyd
wants to merge
32
commits into
master
Choose a base branch
from
pants-plugins-pack_metadata-python-imports
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+1,435
−11
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now pack_metadata targets will generate pack_content_resource instead of just resource. pack_content_resource is still a resource, but this setup allows us to find the generated resource targets more simply. This also harmonizes the implementation of pack_metadata to follow the fields definition of resources (esp moving dependencies into moved_fields instead of core_fields).
…esource targets This will allow rules to look up just action and sensor metadata (for example).
… module mapping Only handles the actual action/sensor python files. It does not yet handle: - <pack>/lib - <pack>/actions/lib
…thon module mapping This makes dependency inference aware of these which may be on the PYTHONPATH. - <pack>/lib - <pack>/actions/lib
The pack_metadata plugin now handles identifying these imports for dep inference. Next step, modify the PYTHONPATH as well.
…ython_content_rules
…_content and related rules
…TRA_SYS_PATH for tests This won't work until pants gets support for injecting path entries.
…xture Writes various test scenarios in the test sandbox. This should avoid repeating the setup in every test.
And fix the identified issues.
…ules And fix the identified mistake in conftest.
…_dependencies rule
pull-request-size
bot
added
the
size/XXL
PR that changes 1000+ lines. You should absolutely split your PR into several.
label
Oct 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
pantsbuild
python3
size/XXL
PR that changes 1000+ lines. You should absolutely split your PR into several.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR has commits extracted from #6202 where I'm working on getting all of our unit tests to run under pants+pytest.
Overview
This has pants+pytest run pack tests directly instead of using
st2-run-pack-tests
, which has some issues detailed below.This enhances
pants-plugins/pack_metadata
so that it can inject the customPYTHONPATH
entries that st2 adds when running python in packs like actions and sensors. We have several special lib directories to support:<pack>/lib
is the shared lib dir that gets added for both actions and sensors when[packs].enable_common_libs = True
inst2.conf
.<pack>/actions/lib
for actions (allowingimport foo
to import<pack>/actions/lib/foo.py
in an action)entry_point
parent directory for sensors and actionsThat last point is actually not handled correctly in
st2-run-pack-tests
which only adds<pack>/actions/
and<pack>/sensors/
to PYTHONPATH, which assumes that the python file is directly in those directories. The python files can, however be in a sub directory, and that sub directory gets added to PYTHONPATH. So, thispants-plugins/pack_metadata
enhancement allows pants to accurately reflect the logic st2 actually uses.Another reason that this does not use
st2-run-pack-tests
, is that it obscures thePYTHONPATH
logic that pants needs to carefully manage. Pants uses PEX to make sure that tests are run in a hermetic sandbox that cannot be influenced by things like packages installed withpip install --user
. So, the python dependencies detected by this plugin actually get passed asPEX_EXTRA_SYS_PATH
notPYTHONPATH
which is ignored when running python hermetically.Eventually, I would like to publish
pants-plugins/pack_metadata
so it can be used in pack repos to run tests with pants+pytest instead ofst2-run-pack-tests
.TODO expand your PR description with a guided tour of the plugin components.