enough-advantage-61561
08/11/2023, 11:17 AMdependencies
of a python file in a simple dummy project? (posting details to comments)enough-advantage-61561
08/11/2023, 11:19 AMπ pants-tests/
ββπ .gitignore
ββπ lib/
β ββπ my-pkg/
β ββπ pyproject.toml
β ββπ mypkg/
β ββπ __init__.py
β ββπ something.py
β ββπ BUILD
ββπ pants.toml
And the pyproject.toml
defines "numba" as dependency
[project]
name = "my-pkg"
requires-python = ">=3.10"
description = "A package"
version = "0.1.0"
dependencies = ["numba"]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["."]
include = ["mypkg*"]
The lib/my-pkg/mypkg/something.py
imports numba (and matplotlib):
import matplotlib
import numba
def foo():
print(matplotlib)
print(numba)
if __name__ == "__main__":
print("Hello from ", __file__)
and I'm using pants 2.15.0enough-advantage-61561
08/11/2023, 11:20 AMpants tailor ::
it creates lib/my-pkg/mypkg/BUILD
with following contents:
python_sources()
That is the only BUILD
file created.enough-advantage-61561
08/11/2023, 11:20 AMniko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies lib/my-pkg/mypkg/something.py
14:13:43.36 [WARN] Pants cannot infer owners for the following imports in the target lib/my-pkg/mypkg/something.py:
* matplotlib (line: 1)
* numba (line: 2)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.15/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
niko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies --transitive lib/my-pkg/mypkg/something.py
niko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies lib/my-pkg/mypkg/something.py
niko@niko-ubuntu:~/tmp/pants-tests$
enough-advantage-61561
08/11/2023, 11:22 AMBUILD
have some (other) content? I would expect that "numba" is added automatically as 3rd party dependency as it is listed in pyproject.toml
. That seems not be the case. Is there a way to get the dependencies listed automatically? If not, where I should put manually put them?enough-advantage-61561
08/11/2023, 11:27 AMAuto-generate BUILD file targets for new source files.
from which I would assume the 3rd party dependencies are added to the BUILD files automatically by pants tailor ::
. Why I don't see it? It does not specifically say if it reads the dependencies from setup.py or pyproject.toml or requirements.txt, or directly from import statements from the source files.. π€broad-processor-92400
08/11/2023, 11:29 AMpython_requirements
target in it. See the βpep 621β section of https://www.pantsbuild.org/docs/python-third-party-dependencies for more (Iβm on mobile so canβt link to it directly)enough-advantage-61561
08/11/2023, 11:30 AMbroad-processor-92400
08/11/2023, 11:30 AMpython_requirements
target is requiredbroad-processor-92400
08/11/2023, 11:30 AMenough-advantage-61561
08/11/2023, 11:31 AMenough-advantage-61561
08/11/2023, 11:33 AMBUILD
file created by pants tailor ::
has same contents and here is what the dependency check looks like
niko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies lib/my-pkg/mypkg/something.py
14:31:59.42 [WARN] DEPRECATED: the factory default interpreter constraints value is scheduled to be removed in version 2.17.0.dev0.
You're relying on the default interpreter constraints that ship with Pants (('CPython>=3.7,<4',)). This default is deprecated, in favor of explicitly specifying the interpreter versions your code is actually intended to run against.
You specify interpreter constraints using the `interpreter_constraints` option in the `[python]` section of pants.toml. We recommend constraining to a single interpreter minor version if you can, e.g., `interpreter_constraints = ['==3.11.*']`, or at least a small number of interpreter minor versions, e.g., `interpreter_constraints = ['>=3.10,<3.12']`. See <https://www.pantsbuild.org/v2.16/docs/python-interpreter-compatibility> for details.
Set explicit interpreter constraints now to get rid of this warning.
14:32:07.38 [WARN] Pants cannot infer owners for the following imports in the target lib/my-pkg/mypkg/something.py:
* matplotlib (line: 1)
* numba (line: 2)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.16/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
niko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies lib/my-pkg/mypkg/something.py
niko@niko-ubuntu:~/tmp/pants-tests$
enough-advantage-61561
08/11/2023, 11:37 AMBUILD
file next to the pyproject.toml
:
π pants-tests/
ββπ .gitignore
ββπ lib/
β ββπ my-pkg/
β ββπ pyproject.toml
β ββπ BUILD <----- manually added
β ββπ mypkg/
β ββπ __init__.py
β ββπ something.py
β ββπ BUILD <---- from pants tailor (automatic)
ββπ pants.toml
enough-advantage-61561
08/11/2023, 11:38 AMlib/my-pkg/BUILD
has only this as content:
python_requirements(source="pyproject.toml")
enough-advantage-61561
08/11/2023, 11:39 AMniko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies lib/my-pkg/mypkg/something.py
14:35:12.88 [WARN] Pants cannot infer owners for the following imports in the target lib/my-pkg/mypkg/something.py:
* matplotlib (line: 1)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.16/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
lib/my-pkg#numba
The matplotlib
I purposefully did not add, so I could see what pants
does automatically. On second run it looks like this:
niko@niko-ubuntu:~/tmp/pants-tests$ pants dependencies lib/my-pkg/mypkg/something.py
lib/my-pkg#numba
enough-advantage-61561
08/11/2023, 11:39 AMbroad-processor-92400
08/11/2023, 11:41 AM