forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the dep inference scripts source root bug. (pantsbuild#18164)
The dep inference script used to be a single file that did no importing (except from the stdlib). And we treated the script as both a resource, for writing into the dep inference sandbox at Pants run time, and as a Python source, so we can fmt/lint/typecheck it at Pants build time. But pantsbuild#17997 split up that script to make it more modular, so that it now imports other script code, relative to the scripts dir. Now, for the fmt/lint/typecheck to succeed, those imports have to correspond to a source root, so we added `src/python/pants/backend/python/dependency_inference/scripts/` as a source root. But this means that when packaging the `pantsbuild.pants` wheel, those scripts will be placed relative to the root package, rather than nested in `pants.backend.python.dependency_inference.scripts`. And we loading the script contents as resources relative to that package. This PR: - Fixes this by removing that nested source root (which is confusing anyway). So those inter-script imports must now specify the entire `pants.backend.python.dependency_inference.scripts` prefix. - Gets rid of the `_pants_dep_parser` script package, which was intended to namespace the scripts under the nested source root, since we now have `pants.backend.python.dependency_inference.scripts` as a namespace. - Ensures that all the intermediate `__init__.py` are present in the scripts sandbox, so the scripts can import on Python 2. - Gets rid of the resource/code duality in the BUILD file. Python can load source file contents as resources, so just depending on the scripts as python_sources is fine.
- Loading branch information
Showing
7 changed files
with
47 additions
and
28 deletions.
There are no files selected for viewing
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
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
11 changes: 1 addition & 10 deletions
11
src/python/pants/backend/python/dependency_inference/scripts/BUILD
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,4 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
# Scripts are consumed at runtime as resources. | ||
resources( | ||
sources=["**/*.py"], | ||
) | ||
|
||
# Also expose the scripts as python sources so they get formatted/linted/checked. | ||
python_sources( | ||
name="py_sources", | ||
sources=["**/*.py"], | ||
) | ||
python_sources() |
File renamed without changes.
File renamed without changes.
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
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