Skip to content

Commit

Permalink
Make VERSION resource loadable without upsetting the rest of the pa…
Browse files Browse the repository at this point in the history
…nts 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]
  • Loading branch information
Christopher Neugebauer committed Aug 3, 2022
1 parent 913e894 commit ac24a35
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/python/pants/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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"]},
},
)

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,
Expand Down
Empty file removed src/python/pants/__init__.py
Empty file.
4 changes: 3 additions & 1 deletion src/python/pants/backend/python/dependency_inference/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]))
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
2 changes: 2 additions & 0 deletions src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ pex_binary(
)

python_tests(name="tests")

resources(name="resources", sources=["VERSION"])
1 change: 1 addition & 0 deletions src/python/pants/bin/VERSION
2 changes: 1 addition & 1 deletion src/python/pants/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ac24a35

Please sign in to comment.