Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"TypeError: cannot use a string pattern on a bytes-like object" while installing django-geojson #2118

Open
khink opened this issue Jul 26, 2024 · 5 comments · May be fixed by #2119
Open

"TypeError: cannot use a string pattern on a bytes-like object" while installing django-geojson #2118

khink opened this issue Jul 26, 2024 · 5 comments · May be fixed by #2119
Labels
resolver Related to dependency resolver

Comments

@khink
Copy link

khink commented Jul 26, 2024

Not sure if this is an issue with pip-tools or (django-)geojson, but ill start asking here:

In our base.in we have django-geojson.

Today while running pip-compile i ran into this error:

CUSTOM_COMPILE_COMMAND="make requirements" env/bin/pip-compile --upgrade --resolver=backtracking --generate-hashes --allow-unsafe --output-file requirements/production.txt requirements/production.in
    error: subprocess-exited-with-error

    × python setup.py egg_info did not run successfully.
    │ exit code: 1
    ╰─> [16 lines of output]
        Traceback (most recent call last):
          File "<string>", line 2, in <module>
          File "<pip-setuptools-caller>", line 34, in <module>
          File "/tmp/pip-resolve-8epq73d1/geojson_f8da4ae3298f497286137c89d8d975c6/setup.py", line 6, in <module>
            setup(name          = "geojson",
          File "/home/kees/Projects/eov-2.0-api/env/lib/python3.9/site-packages/setuptools/__init__.py", line 108, in setup
            return distutils.core.setup(**attrs)
          File "/home/kees/Projects/eov-2.0-api/env/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 146, in setup
            _setup_distribution = dist = klass(attrs)
          File "/home/kees/Projects/eov-2.0-api/env/lib/python3.9/site-packages/setuptools/dist.py", line 300, in __init__
            self.metadata.version = self._normalize_version(self.metadata.version)
          File "/home/kees/Projects/eov-2.0-api/env/lib/python3.9/site-packages/setuptools/dist.py", line 336, in _normalize_version
            normalized = str(Version(version))
          File "/home/kees/Projects/eov-2.0-api/env/lib/python3.9/site-packages/packaging/version.py", line 198, in __init__
            match = self._regex.search(version)
        TypeError: cannot use a string pattern on a bytes-like object
        [end of output]

    note: This error originates from a subprocess, and is likely not a problem with pip.

Pinning django-geojson==4.0.0 (the currently used version) fixes it.

This might be due to a new django-geojson release (https://pypi.org/project/django-geojson/4.1.0/), but I can't see anything wrong with its setup.py (https://github.com/makinacorpus/django-geojson/blob/4.1.0/setup.py)

The stacktrace above lists setup(name = "geojson", which i think is a string parsing error, as geojson is not a dependency of django-geojson, nor has it been.

Environment Versions

  • OS Type: Ubuntu 22.04.4 LTS
  • Python version: Python 3.9.19
  • pip version: pip 24.1.2
  • pip-tools version: pip-compile, version 7.4.1

Steps to replicate

Edit: Easy reproduction steps at https://github.com/khink/pip-tools-issue-2118

In short: Run pip-compile on this requirements file

@RonnyPfannschmidt
Copy link
Member

This is a bug in the project, nothing pip can do about a broken package

@khink
Copy link
Author

khink commented Jul 29, 2024

Hi, first off: thanks for taking the time to look into this!

pip install django-geojson==4.1.0 just works. How can i show the django-geojson maintainers what is wrong?

Edit: The error above seems to indicate it fails in the python setup.py egg_info step, but the following just works:

git clone [email protected]:makinacorpus/django-geojson.git
cd django-geojson/
git checkout 4.1.0
python3.11 -m venv env
. env/bin/activate
python setup.py egg_info

Not sure how to reproduce the error.

@AndydeCleyre AndydeCleyre added the needs reproduce Need to reproduce an issue label Jul 29, 2024
@AndydeCleyre
Copy link
Contributor

I can't reproduce with this info yet, but can you ensure you're using the latest setuptools in the venv with the problem?

@khink
Copy link
Author

khink commented Jul 30, 2024

Thanks for thinking of that.

Turns out it was a recent setuptools: 71.1.0. I just upgraded it and tried again:

$ pip install --upgrade setuptools
Requirement already satisfied: setuptools in ./env/lib/python3.9/site-packages (71.1.0)
Collecting setuptools
  Downloading setuptools-72.1.0-py3-none-any.whl.metadata (6.6 kB)
Downloading setuptools-72.1.0-py3-none-any.whl (2.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 2.6 MB/s eta 0:00:00
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 71.1.0
    Uninstalling setuptools-71.1.0:
      Successfully uninstalled setuptools-71.1.0
Successfully installed setuptools-72.1.0

However, same result.

I created this repo to reproduce it: https://github.com/khink/pip-tools-issue-2118

Apparently the bug only surfaces in combination with these other requirements.

@AndydeCleyre
Copy link
Contributor

Great! OK, so I can confirm that this reproduces here, and it's failing on processing django-geojson 1.2.0, and can be worked around by making the requirement django-geojson>1.2.0. And also that a plain:

$ pip install django-geojson==1.2.0

fails the same way. It looks like that version depends on an uninstallable version of geojson.

pip-tools should probably just reject a failed version like this and keep trying others.

@AndydeCleyre AndydeCleyre added resolver Related to dependency resolver and removed needs reproduce Need to reproduce an issue labels Jul 30, 2024
khink added a commit to khink/pip-tools that referenced this issue Jul 31, 2024
Fixes jazzband#2118.

Now, with this in requirements.txt:

    django-debug-toolbar
    django-geojson
    wagtail>=4.2,<4.3

I get:

    $ env/bin/pip-compile --resolver=backtracking --generate-hashes --allow-unsafe --output-file requirements.txt requirements.in
        error: subprocess-exited-with-error

        × python setup.py egg_info did not run successfully.
        │ exit code: 1
        ╰─> [18 lines of output]
            /home/kees/Projects/pip-tools/env/lib/python3.10/site-packages/setuptools/_distutils/dist.py:268: UserWarning: Unknown distribution option: 'test_suite'
              warnings.warn(msg)
            Traceback (most recent call last):
              File "<string>", line 2, in <module>
              File "<pip-setuptools-caller>", line 34, in <module>
              File "/tmp/pip-resolve-o2r8fhgd/geojson_90f4efbe8a2247f9a1883c03e4988381/setup.py", line 6, in <module>
                setup(name          = "geojson",
              File "/home/kees/Projects/pip-tools/env/lib/python3.10/site-packages/setuptools/__init__.py", line 108, in setup
                return distutils.core.setup(**attrs)
              File "/home/kees/Projects/pip-tools/env/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 146, in setup
                _setup_distribution = dist = klass(attrs)
              File "/home/kees/Projects/pip-tools/env/lib/python3.10/site-packages/setuptools/dist.py", line 289, in __init__
                self.metadata.version = self._normalize_version(self.metadata.version)
              File "/home/kees/Projects/pip-tools/env/lib/python3.10/site-packages/setuptools/dist.py", line 325, in _normalize_version
                normalized = str(Version(version))
              File "/home/kees/Projects/pip-tools/env/lib/python3.10/site-packages/packaging/version.py", line 200, in __init__
                match = self._regex.search(version)
            TypeError: cannot use a string pattern on a bytes-like object
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
    Discarding django-geojson (from -r requirements.in (line 11)) to proceed the resolution.
    It looks like it has a release with broken metadata, causing this resolver to fail.
    You may try to pin that package's version (probably to a recent one), so the resolver doesn't consider the broken release.

The exception is still shown. Also we log a warning to tell the user the package was discarded.

The way to find the offending pacakge is crude (regex in error message string).

When the regex search for package name fails, we re-raise the error so no requirements file is generated.

In that case we log an error, which is hopefully helpful.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolver Related to dependency resolver
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants