Hi all, I’m back to working on packaging (related ...
# general
f
Hi all, I’m back to working on packaging (related to my earlier PEP 621 threads from a few weeks ago). I’m having trouble with the
python_distribution
target and handling PEP 517 compliant backends. I have two specific problems, which are both demonstrated in this repo: https://github.com/bryanwweber/pep621-pants-test First, running
./pants package src/test-flit::
, I get an error:
Copy code
14:48:33.97 [ERROR] 1 Exception encountered:

Engine traceback:
  in select
  in pants.core.goals.package.package_asset
  in pants.backend.python.goals.setup_py.package_python_dist (src/test-flit:test-flit)
  in pants.backend.python.util_rules.dists.run_pep517_build
  in pants.engine.process.fallible_to_exec_result_or_raise
Traceback (most recent call last):
  File "/Users/bweber/.cache/pants/setup/bootstrap-Darwin-arm64/pants.MAN743/install/lib/python3.9/site-packages/pants/engine/process.py", line 272, in fallible_to_exec_result_or_raise
    raise ProcessExecutionFailure(
pants.engine.process.ProcessExecutionFailure: Process 'Run flit_core.buildapi for src/test-flit:test-flit' failed with exit code 1.
stdout:

stderr:
Traceback (most recent call last):
  File "/private/var/folders/zj/p64fbz8d6nd6st_w625_cf7r0000gq/T/pants-sandbox-MxaxV1/chroot/src/test-flit/../../../.cache/pex_root/venvs/31101af6a39067ea0ded21c13e22768ab8004113/c6158e3f0f08aecef5110af6fc1a7d94053f2bee/pex", line 229, in <module>
    exec(ast, globals_map, locals_map)
  File "backend_shim.py", line 16, in <module>
    wheel_path = backend.build_wheel(dist_dir, wheel_config_settings) if build_wheel else None
  File "/Users/bweber/.cache/pants/named_caches/pex_root/venvs/31101af6a39067ea0ded21c13e22768ab8004113/c6158e3f0f08aecef5110af6fc1a7d94053f2bee/lib/python3.10/site-packages/flit_core/buildapi.py", line 72, in build_wheel
    info = make_wheel_in(pyproj_toml, Path(wheel_directory))
  File "/Users/bweber/.cache/pants/named_caches/pex_root/venvs/31101af6a39067ea0ded21c13e22768ab8004113/c6158e3f0f08aecef5110af6fc1a7d94053f2bee/lib/python3.10/site-packages/flit_core/wheel.py", line 219, in make_wheel_in
    (fd, temp_path) = tempfile.mkstemp(suffix='.whl', dir=str(wheel_directory))
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tempfile.py", line 341, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tempfile.py", line 256, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/zj/p64fbz8d6nd6st_w625_cf7r0000gq/T/pants-sandbox-MxaxV1/chroot/src/test-flit/dist/tmplaw_7nkj.whl'
This happens for
pants
2.12.0 and 2.13.0rc1
Second, I would like to be able to single-source a version for my package from an attribute.
setuptools
allows this by a configuration option in
setup.cfg
but
pants
is not able to read this value
Running
./pants package src/test-setuptools::
results in a wheel called
setuptools_module-0.0.0-py3-none-any.whl
Ah! That problem is resolved by setting a
resource
for
setup.cfg
So it’s just the first problem above with Flit
h
Hmm, I think this is because flit doesn’t create the output dir if it doesn’t exist
f
So, should
pants
create it?
h
Yes, it should
With this diff:
Copy code
diff --git a/src/python/pants/backend/python/util_rules/dists.py b/src/python/pants/backend/python/util_rules/dists.py
index 9aa926a8b..3cfe90602 100644
--- a/src/python/pants/backend/python/util_rules/dists.py
+++ b/src/python/pants/backend/python/util_rules/dists.py
@@ -144,6 +144,7 @@ class DistBuildResult:
 _BACKEND_SHIM_BOILERPLATE = """
 # DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS
 
+import os
 import {build_backend_module}
 
 backend = {build_backend_object}
@@ -154,6 +155,7 @@ build_sdist = {build_sdist}
 wheel_config_settings = {wheel_config_settings_str}
 sdist_config_settings = {sdist_config_settings_str}
 
+os.makedirs(dist_dir, exist_ok=True)
 wheel_path = backend.build_wheel(dist_dir, wheel_config_settings) if build_wheel else None
 sdist_path = backend.build_sdist(dist_dir, sdist_config_settings) if build_sdist else None
I get a different error, that I think is legit:
ValueError: No file/folder found for module a_module
f
Yeah, I don’t think I specified the right code dependency for the
flit
test folder
a_module
is what I had called the module at some point in the past
h
I’ll pop out a quick fix
thanks for the bug report!
f
Thank you!
h
f
Whoa! Super fast
h
We try our best to fix blocking bugs quickly 🙂 I think we'll cherry-pick this likely to 2.13, which is close to its stable release. Or possibly to 2.12.1
f
It’s very much appreciated 🙂
❤️ 1
h
I’d rather not cherrypick to 2.12.1, I really want to get that out and close out the 2.12.x branch
🙏 2
But definitely 2.13
🙏 1
OK, this is merged in main and cherrypicked to 2.13.x and 2.14.x, so it’ll be in the next releases in those series
Thanks for the bug report, and sorry for the trouble @future-oxygen-10553
f
Thank you so much for the quick fix!
As it’s on
main
I’ll be able to use it for testing right away, so I really appreciate it
Just to confirm, once I fix the
pyproject.toml
to point to the right module,
flit
packaging works as expected now!
🎉 2
h
woohoo!