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.56k stars 290 forks source link

Not formatting #621

Closed DeadPool3333 closed 2 years ago

DeadPool3333 commented 2 years ago

Python Code

Just used the example given in README.md


import math, sys;

def example1():
    ####This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple=(   1,2, 3,'a'  );
    some_variable={'long':'Long code lines should be wrapped within 79 characters.',
    'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
    'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
    20,300,40000,500000000,60000000000000000]}}
    return (some_tuple, some_variable)
def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
class Example3(   object ):
    def __init__    ( self, bar ):
     #Comments should have a space after the hash.
     if bar : bar+=1;  bar=bar* bar   ; return bar
     else:
                    some_string = """
                       Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
                    return (sys.path, some_string)

Command Line and Configuration

.pep8, setup.cfg, ...

[pep8]

Command Line

$ autopep8 --in-place main.py

Your Environment

DeadPool3333 commented 2 years ago

I am trying this but it is not formatting at all, and also if I use command line without --in-place also it is showing non-formatted code only. Idk what I am doing wrong :/

hhatto commented 2 years ago

@DeadPool3333 It's working fine in my environment. (with Linux, Python3.7.9, autopep8 1.6.0)

$ cat main.py
import math, sys;

def example1():
    ####This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple=(   1,2, 3,'a'  );
    some_variable={'long':'Long code lines should be wrapped within 79 characters.',
    'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
    'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
    20,300,40000,500000000,60000000000000000]}}
    return (some_tuple, some_variable)
def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
class Example3(   object ):
    def __init__    ( self, bar ):
     #Comments should have a space after the hash.
     if bar : bar+=1;  bar=bar* bar   ; return bar
     else:
                    some_string = """
                       Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
                    return (sys.path, some_string)
$ /home/ec2-user/.virtualenvs/py379crypto/bin/autopep8 --in-place main.py
$ cat main.py
import math
import sys

def example1():
    # This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple = (1, 2, 3, 'a')
    some_variable = {'long': 'Long code lines should be wrapped within 79 characters.',
                     'other': [math.pi, 100, 200, 300, 9876543210, 'This is a long string that goes on'],
                     'more': {'inner': 'This whole logical line should be wrapped.', some_tuple: [1,
                                                                                                  20, 300, 40000, 500000000, 60000000000000000]}}
    return (some_tuple, some_variable)

def example2(): return {'has_key() is deprecated': True}.has_key(
    {'f': 2}.has_key(''))

class Example3(object):
    def __init__(self, bar):
        # Comments should have a space after the hash.
        if bar:
            bar += 1
            bar = bar * bar
            return bar
        else:
            some_string = """
                       Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
            return (sys.path, some_string)

Could you share the following results with us?

DeadPool3333 commented 2 years ago

Oh, and i tried that both commands but they are also not working yet, i mean they are also not formatting. It is just showing this autopep8 -vvv -d main.py:

enable config: section=pycodestyle, key=ignore, value=E, W
[file:main.py]
--->  0 issue(s) to fix {}

autopep8 -vvv --in-place main.py

enable config: section=pycodestyle, key=ignore, value=E, W
[file:main.py]
--->  0 issue(s) to fix {}
hhatto commented 2 years ago

this config is ignore all errors and warnings. key=ignore, value=E, W

Could you please review the configuration file on your environment?

ref: https://github.com/hhatto/autopep8#configuration

DeadPool3333 commented 2 years ago

So actually at first i tried without config so when it dint work then i used this in my pyproject.toml file https://github.com/hhatto/autopep8#pyproject-toml. But after that also it is not working.

hhatto commented 2 years ago

Do you have any of the following files in your project? autopep8 will read and use the settings in the pep8 or pycodestyle or flake8 sections of the following files if they exist.

DeadPool3333 commented 2 years ago

No i dint have any of the file. So should i create that files? if yes than what should i enter in that files?

DeadPool3333 commented 2 years ago

Yeah it is not formatting but not like this https://github.com/hhatto/autopep8#usage. My result:

import math
import sys

def example1():
    # This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple = (1, 2, 3, 'a')
    some_variable = {'long': 'Long code lines should be wrapped within 79 characters.',
                     'other': [math.pi, 100, 200, 300, 9876543210, 'This is a long string that goes on'],
                     'more': {'inner': 'This whole logical line should be wrapped.', some_tuple: [1,
                                                                                                  20, 300, 40000, 500000000, 60000000000000000]}}
    return (some_tuple, some_variable)

def example2(): return {'has_key() is deprecated': True}.has_key({'f': 2}.has_key(''))

class Example3(object):
    def __init__(self, bar):
        # Comments should have a space after the hash.
        if bar:
            bar += 1
            bar = bar * bar
            return bar
        else:
            some_string = """
                       Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
            return (sys.path, some_string)