bland-father-19717
03/05/2022, 2:35 PMbland-father-19717
03/05/2022, 2:38 PMabsl
when run or repl.
BUILD
poetry_requirements()
python_sources(
sources=["**/*.py"],
)
pyproject.toml
[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.22.1"
pytz = "^2021.3"
absl-py = "^1.0.0"
bland-father-19717
03/05/2022, 2:40 PMpoetry_requirements()
python_sources(
sources=["**/*.py"],
dependencies=[
":absl-py",
":numpy",
":pytz"
]
)
pyproject.toml
[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.22.1"
pytz = "^2021.3"
absl-py = "^1.0.0"
hundreds-father-404
03/05/2022, 3:01 PMuse_deprecated_python_macros = false
! (Don't set that immediately, read the deprecation instructions first).
That change switches poetry_requirements
to use the new "target generation" feature. One of the improvements thanks to that is that poetry_requirements
becomes a normal target like anything else, meaning that you can address it. When you depend on it, it's an ~alias for depending on everything it generates
See https://www.pantsbuild.org/docs/upgrade-tipshundreds-father-404
03/05/2022, 3:04 PMupdate-build-files
will work properly to automate making this change though. We cherry-picked a fix this week but the release hasn't gone out yet and I'm blocked due to some temporary internal infrastructure stuff (I pinged other maintainers)
If you're trying to do this today, you can use the PANTS_SHA
feature mentioned in the ./pants
script with this commit: 84c0d295557fb97168ccc696cda60c9bf5e57497. That is what 2.10.0rc3 will be based onbland-father-19717
03/05/2022, 3:24 PMhappy-kitchen-89482
03/06/2022, 1:01 AMbland-father-19717
03/06/2022, 10:18 AMhappy-kitchen-89482
03/06/2022, 5:10 PMhappy-kitchen-89482
03/06/2022, 5:10 PMhappy-kitchen-89482
03/06/2022, 5:11 PMpython_sources
imports from numpy
then that :numpy
dep should be added automaticallyhappy-kitchen-89482
03/06/2022, 5:12 PMWARN
logs in the output about multiple targets providing the same symbol or something like that?happy-kitchen-89482
03/06/2022, 5:12 PMhappy-kitchen-89482
03/06/2022, 5:12 PMrequirements.txt
for example?bland-father-19717
03/07/2022, 1:39 AM./pants repl src/python/lib/lib_a
[INFO] Completed: Building requirements.pex with 1 requirement: numpy==1.20.1
Python 3.8.12 (default, Feb 5 2022, 23:27:32)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import absl
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'absl'
./pants run src/python/main/main_a:main
File "xxx/pants-sample/.pants.d/tmp9ukio0z4/src/python/main/main_a/main.py", line 2, in <module>
from lib.lib_a.utils.log import set_logging_basic_config
File "xxx/pants-sample/.pants.d/tmp9ukio0z4/src/python/lib/lib_a/utils/log.py", line 3, in <module>
import absl.logging
ModuleNotFoundError: No module named 'absl'
enough-analyst-54434
03/07/2022, 1:59 AM$ git diff src/
diff --git a/src/python/main/main_a/BUILD b/src/python/main/main_a/BUILD
index bec269e..e96c61a 100644
--- a/src/python/main/main_a/BUILD
+++ b/src/python/main/main_a/BUILD
@@ -2,10 +2,9 @@ pex_binary(
name="main",
entry_point="main.py",
dependencies=[
- ":lib",
],
platforms=["linux-x86_64-cp-38-cp38"]
)
-python_sources(name="lib", dependencies=["src/python/lib/lib_a"])
+python_sources(name="lib")
docker_image(name="docker", dependencies=["src/python/main/main_a:main"])
Then:
$ ./pants run src/python/main/main_a:main
[0. 0. 0. 0. 0.]
happy-kitchen-89482
03/07/2022, 2:08 AMhappy-kitchen-89482
03/07/2022, 2:11 AMenough-analyst-54434
03/07/2022, 2:14 AMhappy-kitchen-89482
03/07/2022, 2:17 AMenough-analyst-54434
03/07/2022, 2:17 AMenough-analyst-54434
03/07/2022, 2:18 AMbland-father-19717
03/07/2022, 2:20 AMbland-father-19717
03/07/2022, 2:20 AMfeature/add_lib_a_utils
happy-kitchen-89482
03/07/2022, 2:21 AMpoetry_requirements
target:
poetry_requirements(
module_mapping={'absl-py': ['absl']},
)
bland-father-19717
03/07/2022, 2:22 AMhappy-kitchen-89482
03/07/2022, 2:31 AMhappy-kitchen-89482
03/07/2022, 2:31 AMhappy-kitchen-89482
03/07/2022, 2:32 AMhappy-kitchen-89482
03/07/2022, 2:32 AMbland-father-19717
03/07/2022, 2:33 AMenough-analyst-54434
03/07/2022, 2:40 AMbland-father-19717
03/07/2022, 2:47 AMhundreds-father-404
03/07/2022, 3:21 AMhappy-kitchen-89482
03/07/2022, 3:40 AMbland-father-19717
03/07/2022, 3:48 AM