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

magnificent-toothbrush-17254

02/17/2023, 1:19 AM
Hello, I am very new to pants and am trying to create a python 2.7 package so I set
interpreter_constraints=[">=2.7"],
in my
python_distribution
target. running pants package results in this error:
Copy code
ProcessExecutionFailure: Process 'Run setuptools.build_meta:__legacy__ for 'scm:scm' failed with exit code 1.
stdout:

stderr:
Traceback (most recent call last):
  File "/private/var/folders/tx/j170snrj51x7vsqlr6gjgknm0000gn/T/pants-sandbox-n0BU4K/chroot/../.cache/pex_root/venvs/1286fe9e47a1c2e7c2f0b8f40834df0d199c016c/bbf665a577dacddf63ce4c741b47906e31dbdb6c/pex", line 230, in <module>
    exec ast in globals_map, locals_map
  File "backend_shim.py", line 21, in <module>
    os.makedirs(dist_dir, exist_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exist_ok'
Probably because 2.7 doesn't have the
exist_ok
arg. Couldn't find anything online about how to get this to work, anyone have any ideas what i'm doing wrong? This is a 2 and 3 compatible package, builds fine if i change it to
>=3.7
e

enough-analyst-54434

02/17/2023, 1:23 AM
Can you provide the details surrounding the package? The full BUILD target and the full setup.py / setup.cfg / pyproject.toml with redactions as needed?
$ find . -name backend_shim.py
turns up nothing in the Pex source code.
Ditto Pants source code.
Oh!:
$ git grep "backend_shim.py" src/python/pants/backend/python/util_rules/dists.py: backend_shim_name = "backend_shim.py"
m

magnificent-toothbrush-17254

02/17/2023, 1:25 AM
Yep, will work on that when i successfully build it with python 3, this is what's in the package :
Copy code
# DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS

import os
import setuptools.build_meta

backend = setuptools.build_meta.__legacy__

dist_dir = "dist"
build_wheel = True
build_sdist = True
wheel_config_settings = {
    '--global-option': [
        '--python-tag',
        'py37',
    ],
}
sdist_config_settings = {
}

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

if wheel_path:
    print("wheel: {wheel_path}".format(wheel_path=wheel_path))
if sdist_path:
    print("sdist: {sdist_path}".format(sdist_path=sdist_path))
e

enough-analyst-54434

02/17/2023, 1:25 AM
So, bad Pants
m

magnificent-toothbrush-17254

02/17/2023, 1:25 AM
so i think it's made by pants somehwere lol
e

enough-analyst-54434

02/17/2023, 1:25 AM
Yeah, we get in your way here.
This is a bug!
The short of it is that Pants rules run on ">=3.7,<3.10", and so the tendency is to get lazy and think we can write shim code with the same constraints - we can't. Shims have to be able to run in user code context - here Python 2.7
Do you want to take a crack at filing the issue @magnificent-toothbrush-17254?
The fix will be pretty easy / small I think. Just fixing syntax in the shim we emit to be Python 2.7 compatible.
m

magnificent-toothbrush-17254

02/17/2023, 1:28 AM
Sure, can do
e

enough-analyst-54434

02/17/2023, 1:28 AM
Thank you.
Yeah, even the extra mile to use .format instead of f-strings. Looks like a simple miss on the kwarg.
m

magnificent-toothbrush-17254

02/17/2023, 1:29 AM
happens to us all haha
e

enough-analyst-54434

02/17/2023, 1:31 AM
Pants gets away with generally not having to worry about this because Pex handles 2.7 and Pants delegates most user Python handling to Pex. I maintain Pex and am looking to drop 2.7 support when Red Hat drops commercial support. Can I ask you what your 2.7 use-horizon looks like?
m

magnificent-toothbrush-17254

02/17/2023, 1:35 AM
working on it right now, many services are in python3 but it's taking.. time to move a few. Hence the creating 2 & 3 compatible libraries as things are moved over 😅
e

enough-analyst-54434

02/17/2023, 1:36 AM
Gotcha.
m

magnificent-toothbrush-17254

02/17/2023, 1:46 AM
e

enough-analyst-54434

02/17/2023, 1:50 AM
Thanks
h

happy-kitchen-89482

02/17/2023, 2:39 AM
Thanks for the bug report!
@magnificent-toothbrush-17254 which version of Pants are you currently on?
That fix will be in the next 2.16 dev release, and I will cut a new 2.15.0 release candidate (we plan to release 2.15.0 in a few days, so that fix will be in there)
Thanks again for the bug report!
m

magnificent-toothbrush-17254

02/21/2023, 4:36 PM
I'm on 2.14.1 right now, will upgrade when it's released, thank you for the quick turnaround!
6 Views