I've got a weird issue where `python_distribution`...
# general
t
I've got a weird issue where
python_distribution
isn't including my
pyproject.toml
in
chroot
event though the target is in the
dependencies
.
I manually copied it into the
tmp
sandbox and reran
__run.sh
and it built correctly.
Ok, I got it to build correctly, but I needed to include a
files
target with the
pyproject.toml
,
README.md
, and
LICENSE
files as
sources
. I did get the following error:
Copy code
09:54:32.36 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

ProcessExecutionFailure: Process 'Run setuptools.build_meta for //:dss-sdk' failed with exit code 1.
stdout:

stderr:
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'
So, I added
wheel=False
to the
python_distribution
target and it build the
tar.gz
correctly.
I'm gonna call it a win for now and move on lol
😅 1
g
Hmm, I'm not sure I understand. Is there something missing in the docs here? https://www.pantsbuild.org/2.19/docs/python/overview/building-distributions#pep-517 You say that that you had the target in the dependencies, but then also that you needed to include a files target. What did you have to start with? 🙂
t
@gorgeous-winter-99296, I think there might be some inaccuracies in the latest documentation. I was finally able to get everything to work correctly, but it required some trial & error. I initially started with a bare-bones BUILD file like described here. However, it was not including the actual
pyproject.toml
file in the sandbox. So, it would build with the directory name and version
0.0.0
. The
pyproject.toml
was configured with:
Copy code
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
...
I eventually created a
files
target like:
Copy code
files(
    name="build_files",
    sources=["pyproject.toml"],
)
and added that as a dependency to
python_distribution
. It finally included it in the sandbox, but failed to build the wheel and raised an Exception. I figured out I had to add "wheel" to the
requires
like this:
Copy code
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
...
And then it built (kinda). It still failed because it didn't have the README and LICENSE files in the sandbox as well, so I modified the
files
target like so:
Copy code
files(
    name="build_files",
    sources=["pyproject.toml", "README.md", "LICENSE"],
)
And THEN it built both artifacts correctly as I expected.
While you can twine upload just the tar.gz, it failed to
pip install ...
correctly because of some strange issue with setuptools. By ensuring I had both the tar and the wheel, I was able to
pants publish ::
and
pip install ...
correctly (from TestPyPi).
I don't think pants is determining readme or license files when building, nor is it really including the toml as a physical file dependency, but a transitive dependency for inference purposes.
Side note: I'm not even configuring a name for the
python_artifact()
and it still builds correctly. Not sure if that's some weird emergent behavior or a regression. It will complain about no
name
kwarg when I set
generate_setup
to
True
.
Frankly, it kinda seems like a (duh) moment for me when I created a those file dependencies. I don't think there's any issue with pants, it's more like the documentation is a little lacking in terms of a true copy/paste operation.
g
Yeah; I think the documentation assumes a bit of familiarity with PEP517/518. With
generate_setup
Pants will need info for itself, while in a pyproject.toml world we expect that file to be mostly configured correctly. This includes pulling down the setuptools/wheel dependencies -- I use pdm for building wheels, so those are of no use for example.
t
Yeah, aside from maybe some as-is working examples, it all works as I intended. It just took a round-about way to get there. Love pants!
♥️ 1
c
I had this issue recently too, took the same solution you did in the end and was just looking to see if anyone else had run into this!
👍 1
g
It might be cool to add an example here too; as we only have an example for setup.py distributions: https://github.com/pantsbuild/example-python/blob/main/helloworld/translator/BUILD
t
I can probably contribute something to the documentation. At least, maybe provide a bare-bones working BUILD file that I've tested with PyPi
c
> We always welcome contributions if you want to improve it: https://github.com/pantsbuild/pants/blob/main/docs/docs/python/overview/building-distributions.mdx I can add a readme file target to the example PEP 517 BUILD file on this page? That would have been what I would have needed to see to clear up what I had to do.