anaconda icon indicating copy to clipboard operation
anaconda copied to clipboard

Make anaconda's auto format not to format import's

Open jerilkuriakose opened this issue 6 years ago • 3 comments

I am having the following imports in my python file:

# internal
import os
import datetime
# external
import yaml
import gridfs
import pymongo
from pytz import timezone
# local
import constants
from apps.utilities import utils
from apps.utilities.get_mongo_client import mongo_client

But after auto format it changes to :

# internal
import datetime
import os

# local
import constants
import gridfs
import pymongo
# external
import yaml
from apps.utilities import utils
from apps.utilities.get_mongo_client import mongo_client
from pytz import timezone

I tried changing the anaconda settings, and is as follows:

{
    "python_interpreter": "C:\\ProgramData\\Anaconda3\\python.exe",
    "anaconda_linting": false,
    "auto_formatting": true,
    "pep328": false,
    "swallow_startup_errors": true,
    "enable_docstrings_tooltip": false
}

but that didnt work, Is there a way to retain the format for imports alone, and do the auto format for other parts of the code.

Thank you.

jerilkuriakose avatar Nov 30 '19 03:11 jerilkuriakose

Sorry for the very very late answer (its probably that you already solved this by yourself but anyway). Anaconda uses autopep8 in order to automatically format your buffer, you can disable any of the things that autopep8 fixes adding its error code into autoformat_ignore list of error on the Anaconda settings file.

You can find the list of error codes and what they fix in autopep8 official project

DamnWidget avatar May 02 '20 12:05 DamnWidget

Thank you.

jerilkuriakose avatar May 19 '20 03:05 jerilkuriakose

@DamnWidget Hi, The following is my Anaconda User Settings, but it is still sorting the imports:

{
    "python_interpreter": "C:\\ProgramData\\Anaconda3\\python.exe",
    "anaconda_linting": false,
    "auto_formatting": true,
    "autoformat_ignore": ["E402"],
    "swallow_startup_errors": true,
    "enable_docstrings_tooltip": false,
    "auto_formatting_timeout": 5
}

I also referred this link for VSCode, and they use the error code E402 to ignore the formatting of imports.

Can you please help me with this. Thank you.

jerilkuriakose avatar Mar 21 '22 02:03 jerilkuriakose