-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Make default module mapping logic consistent and easy to understand #20513
Conversation
c103685
to
6a1e8ad
Compare
6a1e8ad
to
6d3c78a
Compare
5f10a36
to
7f60f74
Compare
src/python/pants/backend/python/dependency_inference/default_module_mapping.py
Show resolved
Hide resolved
re.compile(r"""^stubs_(.+)"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^types_(.+)"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^stubs-(.+)"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^types-(.+)"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^(.+)_stubs"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^(.+)_types"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^(.+)-stubs"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^(.+)-types"""): [first_group_hyphen_to_underscore], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these do the work of the fallback[6:]
/fallback[:6]
before, without needing to check for those, or assuming prefix length
|
||
|
||
@functools.cache | ||
def generate_mappings(proj_name: str, fallback_value: str) -> Iterable[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore; essentially, the only thing that should care about the fallback logic should be the main loop. The rest should just deal with their own domains.
@@ -355,23 +349,23 @@ async def map_third_party_modules_to_addresses( | |||
for tgt in all_python_targets.third_party: | |||
resolve = tgt[PythonRequirementResolveField].normalized_value(python_setup) | |||
|
|||
def add_modules(modules: Iterable[str], *, type_stub: bool = False) -> None: | |||
def add_modules(modules: Iterable[str], *, is_type_stub: bool) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed default to ensure explicitness of something critical
src/python/pants/backend/python/dependency_inference/module_mapper_test.py
Show resolved
Hide resolved
assert generate_mappings_from_pattern(proj_name, is_type_stub=False) == expected_modules | ||
|
||
|
||
@pytest.mark.parametrize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the new test
for pattern, replacements in [ | ||
*DEFAULT_MODULE_PATTERN_MAPPING.items(), | ||
*DEFAULT_TYPE_STUB_MODULE_PATTERN_MAPPING.items(), | ||
]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and the above add symmetry between the two. From here till the last comment in this file are just pants fmt
changes
re.compile(r"""^stubs[_-](.+)"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^types[_-](.+)"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^(.+)[_-]stubs"""): [first_group_hyphen_to_underscore], | ||
re.compile(r"""^(.+)[_-]types"""): [first_group_hyphen_to_underscore], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these do the work of fallback[6:]
/fallback[:6]
before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sane.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There's a few approvals here, is this waiting on something before merge? (thanks all for contributing and reviewing!) |
Nothing but a little time for us to find if we overlooked something during review, I think. Thanks for bumping. |
This was motivated by trying to add some additional module and stub-related mappings.
While doing that, I realized the patterns only applied to implementation modules only, and realized that a
refactor would be the easiest way forward, while also making the logic easier to step through.
I haven't added any of those module mappings in this PR since I wanted this to only be the logic change.
Changes
python-pkg-types
)test_generate_type_stub_mappings_from_pattern_matches_para
, which is the main new logic herepants fmt
Testing
python src/python/pants/backend/python/dependency_inference/default_module_mapping.py
passespants test src/python/pants/backend/python/dependency_inference/::
passes