FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/isort/settings.py at master · bugnemo/pythonVSCode · GitHub
bugnemo
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
isort
/
settings.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
222 lines (186 loc) · 10.2 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
isort
/
settings.py
Copy path
File metadata and controls
222 lines (186 loc) · 10.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
"""isort/settings.py.
Defines how the default settings for isort should be loaded
(First from the default setting dictionary at the top of the file, then overridden by any settings
in ~/.isort.cfg if there are any)
Copyright (C) 2013 Timothy Edmund Crosley
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
__future__
import
absolute_import
,
division
,
print_function
,
unicode_literals
import
fnmatch
import
os
from
collections
import
namedtuple
from
.
pie_slice
import
*
try
:
import
configparser
except
ImportError
:
import
ConfigParser
as
configparser
MAX_CONFIG_SEARCH_DEPTH
=
25
# The number of parent directories isort will look for a config file within
DEFAULT_SECTIONS
=
(
"FUTURE"
,
"STDLIB"
,
"THIRDPARTY"
,
"FIRSTPARTY"
,
"LOCALFOLDER"
)
WrapModes
=
(
'GRID'
,
'VERTICAL'
,
'HANGING_INDENT'
,
'VERTICAL_HANGING_INDENT'
,
'VERTICAL_GRID'
,
'VERTICAL_GRID_GROUPED'
,
'NOQA'
)
WrapModes
=
namedtuple
(
'WrapModes'
,
WrapModes
)(
*
range
(
len
(
WrapModes
)))
# Note that none of these lists must be complete as they are simply fallbacks for when included auto-detection fails.
default
=
{
'force_to_top'
: [],
'skip'
: [
'__init__.py'
, ],
'skip_glob'
: [],
'line_length'
:
79
,
'wrap_length'
:
0
,
'sections'
:
DEFAULT_SECTIONS
,
'no_sections'
:
False
,
'known_future_library'
: [
'__future__'
],
'known_standard_library'
: [
"abc"
,
"anydbm"
,
"argparse"
,
"array"
,
"asynchat"
,
"asyncore"
,
"atexit"
,
"base64"
,
"BaseHTTPServer"
,
"bisect"
,
"bz2"
,
"calendar"
,
"cgitb"
,
"cmd"
,
"codecs"
,
"collections"
,
"commands"
,
"compileall"
,
"ConfigParser"
,
"contextlib"
,
"Cookie"
,
"copy"
,
"cPickle"
,
"cProfile"
,
"cStringIO"
,
"csv"
,
"datetime"
,
"dbhash"
,
"dbm"
,
"decimal"
,
"difflib"
,
"dircache"
,
"dis"
,
"doctest"
,
"dumbdbm"
,
"EasyDialogs"
,
"errno"
,
"exceptions"
,
"filecmp"
,
"fileinput"
,
"fnmatch"
,
"fractions"
,
"functools"
,
"gc"
,
"gdbm"
,
"getopt"
,
"getpass"
,
"gettext"
,
"glob"
,
"grp"
,
"gzip"
,
"hashlib"
,
"heapq"
,
"hmac"
,
"imaplib"
,
"imp"
,
"inspect"
,
"io"
,
"itertools"
,
"json"
,
"linecache"
,
"locale"
,
"logging"
,
"mailbox"
,
"math"
,
"mhlib"
,
"mmap"
,
"multiprocessing"
,
"operator"
,
"optparse"
,
"os"
,
"pdb"
,
"pickle"
,
"pipes"
,
"pkgutil"
,
"platform"
,
"plistlib"
,
"pprint"
,
"profile"
,
"pstats"
,
"pwd"
,
"pyclbr"
,
"pydoc"
,
"Queue"
,
"random"
,
"re"
,
"readline"
,
"resource"
,
"rlcompleter"
,
"robotparser"
,
"sched"
,
"select"
,
"shelve"
,
"shlex"
,
"shutil"
,
"signal"
,
"SimpleXMLRPCServer"
,
"site"
,
"sitecustomize"
,
"smtpd"
,
"smtplib"
,
"socket"
,
"SocketServer"
,
"sqlite3"
,
"string"
,
"StringIO"
,
"struct"
,
"subprocess"
,
"sys"
,
"sysconfig"
,
"tabnanny"
,
"tarfile"
,
"tempfile"
,
"textwrap"
,
"threading"
,
"time"
,
"timeit"
,
"trace"
,
"traceback"
,
"unittest"
,
"urllib"
,
"urllib2"
,
"urlparse"
,
"usercustomize"
,
"uuid"
,
"warnings"
,
"weakref"
,
"webbrowser"
,
"whichdb"
,
"xml"
,
"xmlrpclib"
,
"zipfile"
,
"zipimport"
,
"zlib"
,
'builtins'
,
'__builtin__'
,
'thread'
,
"binascii"
,
"statistics"
,
"unicodedata"
,
"fcntl"
,
'pathlib'
],
'known_third_party'
: [
'google.appengine.api'
],
'known_first_party'
: [],
'multi_line_output'
:
WrapModes
.
GRID
,
'forced_separate'
: [],
'indent'
:
' '
*
4
,
'length_sort'
:
False
,
'add_imports'
: [],
'remove_imports'
: [],
'force_single_line'
:
False
,
'default_section'
:
'FIRSTPARTY'
,
'import_heading_future'
:
''
,
'import_heading_stdlib'
:
''
,
'import_heading_thirdparty'
:
''
,
'import_heading_firstparty'
:
''
,
'import_heading_localfolder'
:
''
,
'balanced_wrapping'
:
False
,
'use_parentheses'
:
False
,
'order_by_type'
:
True
,
'atomic'
:
False
,
'lines_after_imports'
:
-
1
,
'lines_between_sections'
:
1
,
'lines_between_types'
:
0
,
'combine_as_imports'
:
False
,
'combine_star'
:
False
,
'include_trailing_comma'
:
False
,
'from_first'
:
False
,
'verbose'
:
False
,
'quiet'
:
False
,
'force_adds'
:
False
,
'force_alphabetical_sort_within_sections'
:
False
,
'force_alphabetical_sort'
:
False
,
'force_grid_wrap'
:
False
,
'force_sort_within_sections'
:
False
,
'show_diff'
:
False
,
'enforce_white_space'
:
False
}
@
lru_cache
()
def
from_path
(
path
):
computed_settings
=
default
.
copy
()
_update_settings_with_config
(
path
,
'.editorconfig'
,
'~/.editorconfig'
, (
'*'
,
'*.py'
,
'**.py'
),
computed_settings
)
_update_settings_with_config
(
path
,
'.isort.cfg'
,
'~/.isort.cfg'
, (
'settings'
,
'isort'
),
computed_settings
)
_update_settings_with_config
(
path
,
'setup.cfg'
,
None
, (
'isort'
, ),
computed_settings
)
return
computed_settings
def
_update_settings_with_config
(
path
,
name
,
default
,
sections
,
computed_settings
):
editor_config_file
=
default
and
os
.
path
.
expanduser
(
default
)
tries
=
0
current_directory
=
path
while
current_directory
and
tries
<
MAX_CONFIG_SEARCH_DEPTH
:
potential_path
=
os
.
path
.
join
(
current_directory
,
native_str
(
name
))
if
os
.
path
.
exists
(
potential_path
):
editor_config_file
=
potential_path
break
new_directory
=
os
.
path
.
split
(
current_directory
)[
0
]
if
current_directory
==
new_directory
:
break
current_directory
=
new_directory
tries
+=
1
if
editor_config_file
and
os
.
path
.
exists
(
editor_config_file
):
_update_with_config_file
(
editor_config_file
,
sections
,
computed_settings
)
def
_update_with_config_file
(
file_path
,
sections
,
computed_settings
):
settings
=
_get_config_data
(
file_path
,
sections
).
copy
()
if
not
settings
:
return
if
file_path
.
endswith
(
".editorconfig"
):
indent_style
=
settings
.
pop
(
'indent_style'
,
""
).
strip
()
indent_size
=
settings
.
pop
(
'indent_size'
,
""
).
strip
()
if
indent_style
==
"space"
:
computed_settings
[
'indent'
]
=
" "
*
(
indent_size
and
int
(
indent_size
)
or
4
)
elif
indent_style
==
"tab"
:
computed_settings
[
'indent'
]
=
"
\t
"
*
(
indent_size
and
int
(
indent_size
)
or
1
)
max_line_length
=
settings
.
pop
(
'max_line_length'
,
""
).
strip
()
if
max_line_length
:
computed_settings
[
'line_length'
]
=
int
(
max_line_length
)
for
key
,
value
in
itemsview
(
settings
):
access_key
=
key
.
replace
(
'not_'
,
''
).
lower
()
existing_value_type
=
type
(
default
.
get
(
access_key
,
''
))
if
existing_value_type
in
(
list
,
tuple
):
# sections has fixed order values; no adding or substraction from any set
if
access_key
==
'sections'
:
computed_settings
[
access_key
]
=
tuple
(
_as_list
(
value
))
else
:
existing_data
=
set
(
computed_settings
.
get
(
access_key
,
default
.
get
(
access_key
)))
if
key
.
startswith
(
'not_'
):
computed_settings
[
access_key
]
=
list
(
existing_data
.
difference
(
_as_list
(
value
)))
else
:
computed_settings
[
access_key
]
=
list
(
existing_data
.
union
(
_as_list
(
value
)))
elif
existing_value_type
==
bool
and
value
.
lower
().
strip
()
==
"false"
:
computed_settings
[
access_key
]
=
False
elif
key
.
startswith
(
'known_'
):
computed_settings
[
access_key
]
=
list
(
_as_list
(
value
))
else
:
computed_settings
[
access_key
]
=
existing_value_type
(
value
)
def
_as_list
(
value
):
return
filter
(
bool
, [
item
.
strip
()
for
item
in
value
.
replace
(
'
\n
'
,
','
).
split
(
","
)])
@
lru_cache
()
def
_get_config_data
(
file_path
,
sections
):
with
open
(
file_path
,
'rU'
)
as
config_file
:
if
file_path
.
endswith
(
".editorconfig"
):
line
=
"
\n
"
last_position
=
config_file
.
tell
()
while
line
:
line
=
config_file
.
readline
()
if
"["
in
line
:
config_file
.
seek
(
last_position
)
break
last_position
=
config_file
.
tell
()
config
=
configparser
.
SafeConfigParser
()
config
.
readfp
(
config_file
)
settings
=
dict
()
for
section
in
sections
:
if
config
.
has_section
(
section
):
settings
.
update
(
dict
(
config
.
items
(
section
)))
return
settings
return
{}
def
should_skip
(
filename
,
config
,
path
=
'/'
):
"""Returns True if the file should be skipped based on the passed in settings."""
for
skip_path
in
config
[
'skip'
]:
if
os
.
path
.
join
(
path
,
filename
).
endswith
(
'/'
+
skip_path
.
lstrip
(
'/'
)):
return
True
position
=
os
.
path
.
split
(
filename
)
while
position
[
1
]:
if
position
[
1
]
in
config
[
'skip'
]:
return
True
position
=
os
.
path
.
split
(
position
[
0
])
for
glob
in
config
[
'skip_glob'
]:
if
fnmatch
.
fnmatch
(
filename
,
glob
):
return
True
return
False
Back
|
FazBrowse Home
|
New Git URL