Hi, I am trying to integrates pants into an existi...
# general
h
Hi, I am trying to integrates pants into an existing project. As hierarchy I currently have the
~/libraries/projectA/
which contains
pyproject.toml
,
tests
,
docs
,
examples
, and
source code
in a folder with the same name as the
projectA
. I am a bit confused of where the requirements/dependencies go. I moved the dependencies from
.toml
to a
requirements.txt
and put them at root. But I also tried to keep them in the
.toml
. In the docs I see that requirements go inside a
BUILD
file, but I am not sure which one. Inside the
BUILD
file at the projectA, I created the
python_distribution
to build the project given the dependencies inside toml but it wont take them. After running
pants package
it also seems that it just stores the wheel and not rebuild it? Just wondering as I am trying to test constantly if its building correctly.
b
For the point about
pants package
, pants will cache tasks like building a wheel, and only rerun them if the inputs have changed. If they haven’t changed, pants will just copy the wheel from its cache storage, rather than rerun the whole process. There’s a few ways to force it to rerun, but I suspect they won’t necessarily help with the task you’re trying to solve. For the requirements, I think any BUILD file is fine. To start with, I might recommend keeping the project structure as similar to your existing one as possible (to get something going with minimal changes). This might mean next to the toml. Pants has support for reading requirements from toml files too; what format are they in? Also, taking a step back to confirm the bigger picture, is your goal to build a wheel for publishing somewhere?
h
overall goal is to have a wheel to distribute, will be published only on a github release page. And also fully integrate CI/CD through pants. I was trying to add the requirements.txt into the BUILD at the root of the projectA next to toml but because the build already had a
python_distribution()
it wont allow me to have a
python_requirements()
. My
.toml
has a
dependencies
key under `[project]`and I have additional optional dependencies for testings and docs under
[project.optional-dependencies]
. But when there, It didnt seem pants would detect them as testing would say different modules are not found.
Another issue i have with
pants package
is this error which i cant really see to find why its thrown inside pants.
Copy code
11:20:28.61 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

ProcessExecutionFailure: Process 'Run setuptools.build_meta for libraries/projectA:dist' failed with exit code 1.
stdout:

stderr:
/root/.cache/pants/named_caches/pex_root/venvs/s/14a914f5/venv/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py:66: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
  config = read_configuration(filepath, True, ignore_option_errors, dist)
usage: backend_shim.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: backend_shim.py --help [cmd1 cmd2 ...]
   or: backend_shim.py --help-commands
   or: backend_shim.py cmd --help

error: invalid command 'bdist_wheel'
For future reference for others, the issue above is for not including
wheel
in the requires for
pyproject.toml
. Using the following now works:
Copy code
[build-system]
requires = ['setuptools','wheel']
build-backend = 'setuptools.build_meta'
c
I was trying to add the requirements.txt into the BUILD at the root of the projectA next to toml but because the build already had a
python_distribution()
it wont allow me to have a
python_requirements()
.
this is likely due to not being explicitly named. Only one target in any directory may use the default name otherwise there would be name conflicts, which ought to have been the error message you observed. relevant section of the docs: https://www.pantsbuild.org/docs/targets#target-addresses