https://pantsbuild.org/ logo
#general
Title
# general
l

lively-dusk-46231

10/24/2022, 8:16 AM
I am trying to create some wheels from my codebase using pants. I read through
package
, the
setuptools
integration and
setuptools_scm
parts too Current setup: We have
setup.py
and
pyproject.toml
. With
setuptools_scm
I tried:
Copy code
$ cat BUILD
python_sources(name='source', sources=['my_api/**/*.py'])

vcs_version(
    name='version',
    generate_to='my_api/_version.py',
    template='version = {version}',
)

resource(name='pyproject', source='pyproject.toml')

python_distribution(
    name='my-api',
    dependencies=[
        ':pyproject',
        ':version',
    ],
    provides=python_artifact(name='my-api'),
    sdist=False,
    generate_setup=False,
)
And then did:
./pants package ::
It threw an error about
setuptools_scm
:
Copy code
LookupError: setuptools-scm was unable to detect version for /tmp/pants-sandbox-hVjRo4/chroot.
So, I removed
setuptools_scm
from my
pyproject.toml
Then again ran:
./pants package ::
This is generating
dist/UNKNOWN-0.0.0-py3-none-any.whl
And I can't figure out why the name/version is incorrect Any thoughts ?
I have added:
"pants.backend.experimental.python"
b

bitter-ability-32190

10/24/2022, 10:29 AM
One of the greatest debugging tools pants has:
--keep-sandboxes
./pants --keep-sandboxes=always package <target>
will leak the sandboxes pants used to run processes. The last one logged is usually the one you're looking for (the process description is logged too). And if it doesn't leak and log, it's likely a cache issue. Just add a comment or whitespace to the file and try again
Once you're in the sandbox, there's a
__run.sh
which is made to run the process exactly like pants did
h

happy-kitchen-89482

10/24/2022, 3:14 PM
Not sure if this will fix this, but I think the dependency on
':version'
needs to be a dep of the
python_sources
that owns your
setup.py
So, assuming it’s
my_api/setup.py
, that would be the
python_sources()
in your BUILD file, not the
python_distribution()
Also, just to double-check: this is in a git repo, right?
This is the rule that invokes setuptools_scm , BTW, so the process whose sandbox you want to poke around in is the one titled “Run setuptools_scm for …”
l

lively-dusk-46231

10/24/2022, 3:30 PM
I actually didn't add setup.py in my
python_sources()
🙂 I don't think it would have mattered because my setup.py is just adding some extra setup.py commands for pybabel translations But I added:
python_sources(name='setup', sources=['setup.py'], dependencies=[':version'])
which didn't help Will try
--keep-sandboxes
and check whats going on
And yes - its a git repo
Hmm, I checked the sandboxes and none of them seem to be creating wheel files nor setuptools-scm. Made me thing that maybe caching was in play, so I modified some lines of code in my pkg. Which didnt help either. Then I checked the generated wheel file - and it was empty:
Copy code
$ unzip -l dist/UNKNOWN-0.0.0-py3-none-any.whl.zip
Archive:  dist/UNKNOWN-0.0.0-py3-none-any.whl.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      132  2022-10-24 15:29   UNKNOWN-0.0.0.dist-info/METADATA
       92  2022-10-24 15:29   UNKNOWN-0.0.0.dist-info/WHEEL
        1  2022-10-24 15:29   UNKNOWN-0.0.0.dist-info/top_level.txt
      296  2022-10-24 15:29   UNKNOWN-0.0.0.dist-info/RECORD
---------                     -------
      521                     4 files
Which is again weird, cause I have:
Copy code
python_sources(name='source', sources=['my_api/**/*.py'])

resource(name='pyproject', source='pyproject.toml')
python_sources(name='setup', sources=['setup.py'], dependencies=[':version'])

python_distribution(
    name='my-api',
    dependencies=[
        ':pyproject',
        ':setup',
        ':source', # <----- Should have added my code ?
    ],
    provides=python_artifact(name='my-api'),
    sdist=False,
    generate_setup=False,
)
I also have this in
setup.cfg
Copy code
[options]
packages = find_namespace:

[options.packages.find]
include = my_api, my_api.*
5 Views