Hey there! We're having an issue with certain depe...
# general
f
Hey there! We're having an issue with certain dependencies using Pants because of what the PEX building bundles for bootstrapping. In particular, the pex comes with its own version of
attrs
which looks like hasn't been touched for 2 years https://github.com/pex-tool/pex/blob/main/pex/vendor/_vendored/attrs/attr/__init__.py Meanwhile,
attrs
itself has changed, and in particular added an
AttrsInstance
in here https://github.com/python-attrs/attrs/blob/main/src/attrs/__init__.py We have a dependency that transitively depends on this
attrs
feature, which causes our app to fail upon startup, since the dependency (great expectations) ends up loading the version internally bundled by the PEX, instead of the external one (that is anyway specified in the lockfile).
c
I don't believe Pex put it's vendored modules anywhere it would show up if you did
import attrs
. Is great expectations doing imports in an unusual way?
Copy code
$ less pex-2.2.2-py2.py3-none-any.whl  | grep attrs | head -5
     459  Defl:N      290  37% 02-02-2020 00:00 b53c5e26  pex/attrs.py
     163  Defl:N      140  14% 02-02-2020 00:00 fe7644f2  pex/vendor/_vendored/attrs/.layout.json
       0  Defl:N        2   0% 02-02-2020 00:00 00000000  pex/vendor/_vendored/attrs/__init__.py
    1672  Defl:N      725  57% 02-02-2020 00:00 704e0178  pex/vendor/_vendored/attrs/attr/__init__.py
   15100  Defl:N     3036  80% 02-02-2020 00:00 6ed87c02  pex/vendor/_vendored/attrs/attr/__init__.pyi
f
There's actually another level of dependency (jsonschema), but no, nothing weird https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/exceptions.py#L14
c
What is the error message that you get?
f
Copy code
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO - Traceback (most recent call last):
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen runpy>", line 198, in _run_module_as_main
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen runpy>", line 88, in _run_code
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/__main__.py", line 106, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     bootstrap_pex(__entry_point__, execute=__execute__, venv_dir=__venv_dir__)
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex_bootstrapper.py", line 618, in bootstrap_pex
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     pex.PEX(entry_point).execute()
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex.py", line 560, in execute
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     sys.exit(self._wrap_coverage(self._wrap_profiling, self._execute))
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex.py", line 467, in _wrap_coverage
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     return runner(*args)
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -            ^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex.py", line 498, in _wrap_profiling
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     return runner(*args)
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -            ^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex.py", line 603, in _execute
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     return self.execute_entry(
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -            ^^^^^^^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex.py", line 798, in execute_entry
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     return self.execute_entry_point(entry_point)
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/pex.py", line 815, in execute_entry_point
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     runner = entry_point.resolve()
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -              ^^^^^^^^^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/dist_metadata.py", line 732, in resolve
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     module = importlib.import_module(self.module)
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     return _bootstrap._gcd_import(name[level:], package, level)
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/dq_runner/cli.py", line 10, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from dq_runner.suite import run
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/dq_runner/suite.py", line 6, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     import great_expectations as gx
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/__init__.py", line 6, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.data_context.migrator.cloud_migrator import CloudMigrator
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/data_context/__init__.py", line 1, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.data_context.data_context import (
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/data_context/data_context/__init__.py", line 1, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.data_context.data_context.abstract_data_context import (
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/data_context/data_context/abstract_data_context.py", line 61, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.core.datasource_dict import CacheableDatasourceDict
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/core/datasource_dict.py", line 13, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.datasource.fluent import Datasource as FluentDatasource
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/datasource/__init__.py", line 6, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from .sparkdf_datasource import SparkDFDatasource
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/datasource/sparkdf_datasource.py", line 8, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.dataset import SparkDFDataset
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/dataset/__init__.py", line 3, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from .dataset import Dataset
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/dataset/dataset.py", line 15, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from great_expectations.data_asset.data_asset import DataAsset
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/data_asset/__init__.py", line 2, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from .file_data_asset import FileDataAsset
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/31550eae3b205bb446525ba78ea6134012b012eaa0bf2bddec1eb619c6af0e41/great_expectations-0.17.15-py3-none-any.whl/great_expectations/data_asset/file_data_asset.py", line 9, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     import jsonschema
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/f3de2823552ee2af15ba0d49a5bff3f31b4c8140481498db339714500a8f16bf/jsonschema-4.21.1-py3-none-any.whl/jsonschema/__init__.py", line 13, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from jsonschema._format import FormatChecker
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/f3de2823552ee2af15ba0d49a5bff3f31b4c8140481498db339714500a8f16bf/jsonschema-4.21.1-py3-none-any.whl/jsonschema/_format.py", line 11, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from jsonschema.exceptions import FormatError
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/f3de2823552ee2af15ba0d49a5bff3f31b4c8140481498db339714500a8f16bf/jsonschema-4.21.1-py3-none-any.whl/jsonschema/exceptions.py", line 14, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from attrs import define
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -   File "/data/cache/.pex/installed_wheels/2550e6830d4914f46602e41e895ca232a64e5becab7964924c650710e1ed1668/attrs-23.2.0-py3-none-any.whl/attrs/__init__.py", line 3, in <module>
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO -     from attr import (
[2024-03-27, 15:04:07 UTC] {subprocess.py:93} INFO - ImportError: cannot import name 'AttrsInstance' from 'pex.vendor._vendored.attrs.attr' (/data/cache/.pex/unzipped_pexes/c3349f9a365512d9ab2e9149a2f882cb22884192/.bootstrap/pex/vendor/_vendored/attrs/attr/__init__.py)
[2024-03-27, 15:04:08 UTC] {subprocess.py:97} INFO - Command exited with return code 1
that's the whole stack trace
in the end
attrs
tries to import something from
attr
but instead of using the
attr
inside
attrs-23.2.0
it uses the one from
_vendored
uh wait, maybe I need to put it explicitly in the
module_mapping
nope, doesn't fix it
tried adding
Copy code
module_mapping={
        "attrs": ["attrs", "attr"],
    },
to the
python_requirements
, fwiw, to make sure it "finds" the
attr
module from the
attrs
package
c
That looks very confusing and frustrating. The part where the error comes from inside the
attrs
wheel is particularity puzzling to me. Do you have a small repository that can rerprouce the issue? (My corp one has both GX and attrs and we have not stumbled on this.)
f
I'll try tomorrow, I'm just trying to hack my way around this
The problem is that we updated some other lib, updated lockfiles, tests all passed, and then once deployed we saw this
And now for some reason
generate-lockfiles
gets stuck in an infinite loop when I revert to the previous
requirements.txt
c
if
generate-lockfiles
seems to be running forever, you can try
ps aux  | grep pip
and see if you can find the pip log. That sometimes has clues, and sometimes just pip restatign that it is taking a long time.
h
Ooof, that is frustrating.
As you've seen, PEX vendors its requirements under a
_vendored
prefix, and rewrites the imports to match, so I'm quite surprised at this.
To clarify, this is happening at runtime, when you execute the
.pex
file? If so, what happens if you change the execution mode to
venv
(if it isn't already) and/or the layout to
packed
or
loose
? (if it isn't already)
f
will give it a try when I can, still trying to revert the prod situation to something that works
So, setting
execution_mode
to
venv
fixes it. The layout doesn't change anything. Aside from the fact that it fixes this problem, is there any reason to use venv over zipapp, or the other way around?
h
venv is generally preferable these days, it gives you a situation identical to manually installing wheels into a virtualenv.
zipapp was supported first, so is the default, but in practice it's better to use venv unless you care about very specific performance differences