From ac24a35474fc62cc2a87e606b5d59ee62c1f3d93 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Tue, 2 Aug 2022 17:27:53 -0700 Subject: [PATCH] Make `VERSION` resource loadable without upsetting the rest of the pants distribution # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] --- src/python/pants/BUILD | 4 ++-- src/python/pants/__init__.py | 0 src/python/pants/backend/python/dependency_inference/BUILD | 4 +++- .../dependency_inference/parse_python_dependencies.py | 2 +- .../pants/backend/python/dependency_inference/scripts/BUILD | 6 ++++-- .../scripts/{dependency_parser.py => dependency_parser_py} | 0 src/python/pants/bin/BUILD | 2 ++ src/python/pants/bin/VERSION | 1 + src/python/pants/version.py | 2 +- 9 files changed, 14 insertions(+), 7 deletions(-) delete mode 100644 src/python/pants/__init__.py rename src/python/pants/backend/python/dependency_inference/scripts/{dependency_parser.py => dependency_parser_py} (100%) create mode 120000 src/python/pants/bin/VERSION diff --git a/src/python/pants/BUILD b/src/python/pants/BUILD index e09db9f10dd..1f33ff68322 100644 --- a/src/python/pants/BUILD +++ b/src/python/pants/BUILD @@ -5,7 +5,7 @@ python_sources( overrides={ # Enable `python -m pants ...` style execution ala `json.tool` or `venv`. "__main__.py": {"dependencies": ["src/python/pants/bin:pants_loader"]}, - "version.py": {"dependencies": ["./VERSION:resources"]}, + "version.py": {"dependencies": ["./bin/VERSION:resources"]}, }, ) @@ -13,7 +13,7 @@ python_test_utils(name="test_utils") python_distribution( name="pants-packaged", - dependencies=["./__main__.py", ":resources"], + dependencies=["./__main__.py", ":resources", ], # Because we have native code, this will cause the wheel to use whatever the ABI is for the # interpreter used to run setup.py, e.g. `cp36m-macosx_10_15_x86_64`. sdist=False, diff --git a/src/python/pants/__init__.py b/src/python/pants/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/python/pants/backend/python/dependency_inference/BUILD b/src/python/pants/backend/python/dependency_inference/BUILD index 0290569f3ec..74d7180d82c 100644 --- a/src/python/pants/backend/python/dependency_inference/BUILD +++ b/src/python/pants/backend/python/dependency_inference/BUILD @@ -1,7 +1,9 @@ # Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). -python_sources() +python_sources( + dependencies=["./scripts:dependency_parser",], +) python_tests( name="tests", diff --git a/src/python/pants/backend/python/dependency_inference/parse_python_dependencies.py b/src/python/pants/backend/python/dependency_inference/parse_python_dependencies.py index a404e0bc832..96b897397b9 100644 --- a/src/python/pants/backend/python/dependency_inference/parse_python_dependencies.py +++ b/src/python/pants/backend/python/dependency_inference/parse_python_dependencies.py @@ -61,7 +61,7 @@ class ParserScript: @rule async def parser_script() -> ParserScript: - script = read_resource(__name__, "scripts/dependency_parser.py") + script = read_resource(__name__, "scripts/dependency_parser_py") assert script is not None return ParserScript( await Get(Digest, CreateDigest([FileContent("__parse_python_dependencies.py", script)])) diff --git a/src/python/pants/backend/python/dependency_inference/scripts/BUILD b/src/python/pants/backend/python/dependency_inference/scripts/BUILD index e142aded947..60134271a58 100644 --- a/src/python/pants/backend/python/dependency_inference/scripts/BUILD +++ b/src/python/pants/backend/python/dependency_inference/scripts/BUILD @@ -1,11 +1,13 @@ # Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). -resource(name="dependency_parser", source="dependency_parser.py") +resource(name="dependency_parser", source="dependency_parser_py", dependencies=[":init_py",]) +resource(name="init_py", source="__init__.py",) + # Also expose scripts as python sources so they get formatted/linted/checked. python_source( name="dependency_parser_source", - source="dependency_parser.py", + source="dependency_parser_py", # This is run with Python 2.7 and 3.5+, so we shouldn't be running pyupgrade. # skip_pyupgrade=True, ) diff --git a/src/python/pants/backend/python/dependency_inference/scripts/dependency_parser.py b/src/python/pants/backend/python/dependency_inference/scripts/dependency_parser_py similarity index 100% rename from src/python/pants/backend/python/dependency_inference/scripts/dependency_parser.py rename to src/python/pants/backend/python/dependency_inference/scripts/dependency_parser_py diff --git a/src/python/pants/bin/BUILD b/src/python/pants/bin/BUILD index 74ecd622770..8a4ba73a622 100644 --- a/src/python/pants/bin/BUILD +++ b/src/python/pants/bin/BUILD @@ -78,3 +78,5 @@ pex_binary( ) python_tests(name="tests") + +resources(name="resources", sources=["VERSION"]) diff --git a/src/python/pants/bin/VERSION b/src/python/pants/bin/VERSION new file mode 120000 index 00000000000..6ff19de4b80 --- /dev/null +++ b/src/python/pants/bin/VERSION @@ -0,0 +1 @@ +../VERSION \ No newline at end of file diff --git a/src/python/pants/version.py b/src/python/pants/version.py index 6d9192af32b..b4121605887 100644 --- a/src/python/pants/version.py +++ b/src/python/pants/version.py @@ -15,7 +15,7 @@ os.environ.get(_PANTS_VERSION_OVERRIDE) or # NB: We expect VERSION to always have an entry and want a runtime failure if this is false. - read_resource(__name__, "VERSION").decode().strip() + read_resource("pants.bin", "VERSION").decode().strip() ) PANTS_SEMVER = Version(VERSION)