hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.59k stars 291 forks source link

Version 1.7.0 (last to support python 2.7) depends on a version of pycodestyle that does not support 2.7 #769

Open magnus-puresalmon opened 2 months ago

magnus-puresalmon commented 2 months ago

I am, unfortunately, working on a system that is stuck on 2.7 (specifically it's stuck on using jython, which is itself stuck on 2.7). I wanted to get a code formatter for VSCode that could help, found this GitHub issue: https://github.com/microsoft/vscode-python/discussions/21991 and tried doing method 1 there, but I could not install 1.7.0 due to a dependency on pycodestyle 2.9.1, which doesn't support Python 2.7

While I'd like for this to result in some minimal work to make 1.7.0 use a 2.7 compliant version of pycodestyle, I'd expect it'd be simpler to declare 1.7.0 as not supporting 2.7 (which would make the solution where I'm using autopep8 extension for VSCode break, since the extension requires autopep8>=1.7.0 for the autopep8 version if using an external file)


Command Line

$ ./python -m pip install autopep8==1.7.0
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting autopep8==1.7.0
  Downloading autopep8-1.7.0-py2.py3-none-any.whl (45 kB)
Collecting toml
  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
ERROR: Could not find a version that satisfies the requirement pycodestyle>=2.9.1 (from autopep8==1.7.0) (from versions: 1.8.0.dev0, 2.0.0a1, 2.0.0, 2.1.0, 2.2.0, 2.3.0, 2.3.1, 2.4.0, 2.5.0, 2.6.0a1, 2.6.0, 2.7.0, 2.8.0)
ERROR: No matching distribution found for pycodestyle>=2.9.1 (from autopep8==1.7.0)

Your Environment

magnus-puresalmon commented 2 months ago

I also tried hacking around the version requirement by editing the source of pycodestyle so it declared support for 2.7, but that broke because pycodestyle 2.9.1 uses f-string syntax which is unavailable when built for 2.7. On the other hand, autopep8 1.7.0 using pycodestyle 2.8.0 succesfully parses, but fails at runtime due to a unicode-string error (so it is very likely 1.7.0 shouldn't even declare support for python 2.7)

I also had to change a line of code in the VSCode extension so it could read stderr and not stdout, because apparently autopep8 1.7.0 emits --version info to stderr instead of stdout for some reason.

VSCode settings (username omitted):

{
    "python.analysis.typeCheckingMode": "off",
    "[python]": {
        "editor.defaultFormatter": "ms-python.autopep8"
    },
    "autopep8.importStrategy": "fromEnvironment",
    "autopep8.path": [
        "C:/Users/username/AppData/Local/Python/2.7/Scripts/autopep8.exe"
    ],
    "autopep8.interpreter": [
        "C:/Users/username/AppData/Local/Python/Python311-32/python.exe"
    ]
}