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

Poetry pip shims fix and dropping py3.7 in the same release breaks isort on py3.7 without recourse #2083

Closed
vedantpuri opened this issue Jan 29, 2023 · 12 comments · Fixed by Ekumen-OS/tortoise-data-migration#43 or psf/requests#6370

Comments

@vedantpuri
Copy link

The following PRs were bundled in 5.12.0

If I understand this correctly, anyone using isort on py3.7 does not get the poetry fix. Should there have been an intermediary release before 5.12.0 to cover this case ?

@sijunhe
Copy link

sijunhe commented Jan 29, 2023

+1 to this. We are also in the same dilemma. Would it be possible to do another release that fixes isort for py3.7?

@noorul
Copy link

noorul commented Jan 30, 2023

Looks like the release 5.12.0 has dropped support for 3.7 and this has put everyone using < 3.8 in dilemma.

@psdon
Copy link

psdon commented Jan 30, 2023

This also affects python 3.11

@exhuma
Copy link

exhuma commented Jan 30, 2023

It also seems to affect Python 3.10

We have over 100 projects, each of which with their own .pre-commit-config.yml with daily dev-builds configured. This caused a ton of error-notifications being generated this morning.

Updating all of the projects would be pretty cumbersome. But without a fix we'll be confronted with the same notification mess tomorrow (and each day after).

We can mitigate this by pinning an isort version in a centrally shared part of the pipeline. But that's pretty hacky and I would appreciate a fix by isort considering that this has been affecting a lot of people.

@RobPasMue
Copy link

This also affects python 3.11

We are having issues throughout many repositories because of this problem as well on Python 3.11...

@timothycrosley
Copy link
Member

timothycrosley commented Jan 30, 2023

@psdon @exhuma and @RobPasMue Can you confirm you are using the latest version of isort (5.12.0)? This issue should be fixed in that release, but is bundled with the project deprecating support for Python3.7. I was planning on making a hot fix for 3.7 with the workaround for the surprising breaking change from poetry, but if this is still happening with the fix in place on those newer versions more investigation will be needed. Is is possible all these Python3.10/3.11 projects have the old version of isort pinned, or need to run a pre-commit autoupdate? If that's the case there's nothing I could do at the isort level to fix that, since any changes I make will be new releases.

@RobPasMue
Copy link

That's true, I was pointing to 5.11.4 while using Python 3.11 - thanks for pointing it out @timothycrosley! That solved our issues =)

@exhuma
Copy link

exhuma commented Jan 30, 2023

@timothycrosley The projects are not running on isort 5.12 and updating all of the projects is not feasible. There just are too many and we cannot drop everything right now to work on this. It's too time intensive. We need to go through all the failures, check out the code, run autoupdate commit and push for over 100 projects.

Running autoupdate can also have unintended side effects as it updates everything. We've had surprising failures in the past with projects like mypy when it suddenly started detecting new type-errors in newer versions. We just cannot risk running this "blindly" on every project.

This will be done, but we cannot do this quickly enough and I prefer to do this in a calm, controlled space.

We have a shared CI pipeline which gives me some flexibility but the nature of pre-commit is that the config is inside the project. So each project needs to be touched individually.

The quickest thing we can do is to disable isort everywhere. But I'm working on a more invasive solution which would not require us to drop isort. I will share it as soon as it's done (which is soon) ;)

@timothycrosley
Copy link
Member

timothycrosley commented Jan 30, 2023

@exhuma best of luck on your approach to fix this! I really wish there was a way for me to safely retroactively fix the old release, but it simply isn't possible. The only project that could fix it for existing references to the old version would be the poetry project, where the incompatibility was introduced

@exhuma
Copy link

exhuma commented Jan 30, 2023

Here is a script that I will shim into our shared pipeline runs. It's far from ideal, but it allows us to go through our projects piece by piece while keeping the pipelines "green". For anyone else who needs this, feel free to use it.

This script replaces all isort references with 5.12.0. So even newer versions of isort would be "downgraded" which is pretty bad. But it's a workaround.

#!/usr/bin/env python
"""
Fix for https://github.com/PyCQA/isort/issues/2083

This script *modifies* ``.pre-commit-config.yaml`` and pins the isort version
to 5.12.0

This is a hacky workaround for the aforementioned GitHub issue. Considering
that this aggressively changes the revision number for ``isort`` this should
only be used as a workaround if no other solution is available.

It should also be removed as soon as it is no longer needed because this will
"undo" any upgrades to ``isort`` in repositories.

This script assumes to be run in a CI-pipeline. As such, it also assumes that
it can modify files with impunity as they will not be committed back to the
source-code and will be lost after CI pipeline cleanup. This is - in this case
- the intended behaviour.



--- LICENSE ------------------------------------------------------------------

Copyright 2023 Michel Albert

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

from copy import deepcopy
from os.path import exists
from shutil import copyfile
from textwrap import dedent

from yaml import dump, safe_load

import yamlfix.services

source_file = ".pre-commit-config.yaml"
backup_file = f"{source_file}.bak"

if exists(backup_file):
    raise FileExistsError(f"File {backup_file} already exists")

copyfile(source_file, backup_file)

with open(source_file, encoding="utf8") as fptr:
    content = safe_load(fptr)

replacement_done = False
for repo in content.get("repos", []):
    if repo["repo"] == "https://github.com/PyCQA/isort" and not repo["rev"].startswith(
        "5.12"
    ):
        original = deepcopy(repo)
        repo["rev"] = "5.12.0"
        template = dedent(
            f"""\
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                Problematic isort version {original["rev"]} detected
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            Replacing with pinned 5.12.0
            This is a *temporary* fix. For more information see

            https://github.com/PyCQA/isort/issues/2083
            ----------------------------------------------------------------
            Original Config
            {{original}}
            ----------------------------------------------------------------
            New Config
            {{new}}
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            """
        )
        print(
            template.format(
                original=yamlfix.fix_code(dump(original)),
                new=yamlfix.fix_code(dump(repo)),
            )
        )
        print(f"Updating {repo} with pinned isort version")
        print(f"Updated to {repo}")
        replacement_done = True

with open(source_file, "w", encoding="utf8") as fptr:
    output = yamlfix.services.fix_code(dump(content))
    fptr.write(output)

@exhuma
Copy link

exhuma commented Jan 30, 2023

The only project that could fix it for existing references to the old version would be the poetry project, where the incompatibility was introduced

Any change to prod the poetry devs for this? As a member of the isort project you would surely have more weight than myself 😉

@timothycrosley
Copy link
Member

Closing this as I've fixed this for 3.7 as well with a hotfix: 5.11.5

@timothycrosley timothycrosley pinned this issue Jan 30, 2023
aiven-anton added a commit to Aiven-Open/karapace that referenced this issue Jan 30, 2023
CI is broken on main due to this isort issue, the root cause lies in an
underlying incompatible change in Poetry.

PyCQA/isort#2083
aiven-anton added a commit to Aiven-Open/karapace that referenced this issue Jan 30, 2023
CI is broken on main due to this isort issue, the root cause lies in an
underlying incompatible change in Poetry.

PyCQA/isort#2083

With the upgrade to flake8 6, we ran into an issue with comments in the
configuration file. Those comments are moved to their own lines above
the config instead, see issue below.

PyCQA/flake8#1756
aiven-anton added a commit to Aiven-Open/karapace that referenced this issue Jan 30, 2023
CI is broken on main due to this isort issue, the root cause lies in an
underlying incompatible change in Poetry. The new version of isort has
dropped support for Python 3.7 so we bump CI to run on 3.11 instead (3.7
is EOL later this year anyway).

PyCQA/isort#2083

With the upgrade to flake8 6, we ran into an issue with comments in the
configuration file. Those comments are moved to their own lines above
the config instead, see issue below.

PyCQA/flake8#1756
aiven-anton added a commit to Aiven-Open/karapace that referenced this issue Jan 30, 2023
CI is broken on main due to this isort issue, the root cause lies in an
underlying incompatible change in Poetry. The new version of isort has
dropped support for Python 3.7 so we bump CI to run on 3.11 instead (3.7
is EOL later this year anyway).

PyCQA/isort#2083

With the upgrade to flake8 6, we ran into an issue with comments in the
configuration file. Those comments are moved to their own lines above
the config instead, see issue below.

PyCQA/flake8#1756

Because of installation issues in the lint step, installation is altered
to only installed pre-commit which handles its own dependencies anyway.
connelldave pushed a commit to connelldave/botocove that referenced this issue Feb 8, 2023
See [CI error][1]:

```text
RuntimeError: The Poetry configuration is invalid:
  - [extras.pipfile_deprecated_finder.2] 'pip-shims<=0.3.4' does not match '^[a-zA-Z-_.0-9]+$'
```

See [isort issues referencing `pip-shims`](PyCQA/isort#2083) for more details.

[1]: https://github.com/connelldave/botocove/actions/runs/4120906018/jobs/7116097629
LucidDan added a commit to LucidDan/asgiref that referenced this issue Feb 18, 2023
Update isort to 5.11.5 due to PyCQA/isort#2083
Note 5.12.0 is out but has already dropped support for python 3.7
andrewgodwin pushed a commit to django/asgiref that referenced this issue Feb 19, 2023
Update isort to 5.11.5 due to PyCQA/isort#2083
Note 5.12.0 is out but has already dropped support for python 3.7
LucidDan added a commit to LucidDan/asgiref that referenced this issue Feb 19, 2023
Update isort to 5.11.5 due to PyCQA/isort#2083
Note 5.12.0 is out but has already dropped support for python 3.7
honggyukim added a commit to honggyukim/uftrace that referenced this issue Feb 20, 2023
The pre-commit shows an error in isort hook as follows.

  RuntimeError: The Poetry configuration is invalid

This can be fixed by upgrading isort rev to 5.11.5 so this patch changes
the version to fix it.

In addition, apply changes from isort 5.11.5 to make pre-commit happy.

Link: PyCQA/isort#2083 (comment)
Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
honggyukim added a commit to namhyung/uftrace that referenced this issue Feb 20, 2023
The pre-commit shows an error in isort hook as follows.

  RuntimeError: The Poetry configuration is invalid

This can be fixed by upgrading isort rev to 5.11.5 so this patch changes
the version to fix it.

In addition, apply changes from isort 5.11.5 to make pre-commit happy.

Link: PyCQA/isort#2083 (comment)
Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
yetinam added a commit to seisbench/seisbench that referenced this issue Feb 20, 2023
HorlogeSkynet added a commit to python-distro/distro that referenced this issue Feb 20, 2023
datalogics-robb pushed a commit to datalogics-robb/conan-center-index that referenced this issue Mar 6, 2023
Bumping to isort 5.11.5 fixes a bug with Poetry.

See this comment: PyCQA/isort#2083 (comment)
goldentroll added a commit to goldentroll/asgiref that referenced this issue Mar 14, 2023
Update isort to 5.11.5 due to PyCQA/isort#2083
Note 5.12.0 is out but has already dropped support for python 3.7
bpedersen2 pushed a commit to mlz-ictrl/nicos that referenced this issue Mar 27, 2023
isort v5.10.1 present compatibility issues in some environments (see
PyCQA/isort#2083 (comment)).
isort v5.12.0 seems to solve the issue.

Change-Id: Ie0d10567a9d281b211ef47f50acdd53ab55e9b6f
Reviewed-on: https://forge.frm2.tum.de/review/c/frm2/nicos/nicos/+/30758
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Jonas Petersson <jonas.petersson@ess.eu>
Reviewed-by: Jens Krueger <jens.krueger@frm2.tum.de>
nyreed added a commit to nyreed/openai-chatgpt-opentranslator that referenced this issue Apr 30, 2023
zoj613 added a commit to zoj613/aehmc that referenced this issue May 3, 2023
Setting up the pre-commit hooks fails due to a bug in isort (see:
PyCQA/isort#2083). This commit updates the
version to 5.12.0 where this bug was fixed.
zoj613 added a commit to zoj613/aehmc that referenced this issue May 3, 2023
Setting up the pre-commit hooks fails due to a bug in isort (see:
PyCQA/isort#2083). This commit updates the
version to 5.12.0 where this bug was fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants