Skip to content

Commit 79204d0

Browse files
committed
Reformat code using python black
Get rid of all the different coding and quoting styles by running `black .` on the whole code base defining a line length of 100.
1 parent 149a357 commit 79204d0

File tree

84 files changed

+3033
-3374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3033
-3374
lines changed

01_reload_submodules.py

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def _load_module_exports(module):
21-
if 'exports' in module.__dict__:
21+
if "exports" in module.__dict__:
2222
for name in module.exports:
2323
try:
2424
# lift the export to this modules top level
@@ -27,61 +27,52 @@ def _load_module_exports(module):
2727
print("Error: {0} not defined in {1}.".format(name, module.__name__))
2828

2929

30-
MOD_PREFIX = 'LaTeXTools.'
30+
MOD_PREFIX = "LaTeXTools."
3131

3232
# these modules must be specified in the order they depend on one another
3333
LOAD_ORDER = [
34-
'external',
35-
'external.bibtex',
36-
'external.frozendict',
37-
'external.latex_chars',
38-
39-
'latextools_plugin_internal',
40-
41-
'latextools_utils',
42-
34+
"external",
35+
"external.bibtex",
36+
"external.frozendict",
37+
"external.latex_chars",
38+
"latextools_plugin_internal",
39+
"latextools_utils",
4340
# no internal dependencies
44-
'latextools_utils.activity_indicator',
45-
'latextools_utils.bibformat',
46-
'latextools_utils.logging',
47-
'latextools_utils.parser_utils',
48-
'latextools_utils.settings',
49-
'latextools_utils.utils',
50-
41+
"latextools_utils.activity_indicator",
42+
"latextools_utils.bibformat",
43+
"latextools_utils.logging",
44+
"latextools_utils.parser_utils",
45+
"latextools_utils.settings",
46+
"latextools_utils.utils",
5147
# depend on previous only
52-
'latextools_utils.cache',
53-
'latextools_utils.distro_utils',
54-
'latextools_utils.external_command',
55-
'latextools_utils.internal_types',
56-
'latextools_utils.quickpanel',
57-
'latextools_utils.selectors',
58-
48+
"latextools_utils.cache",
49+
"latextools_utils.distro_utils",
50+
"latextools_utils.external_command",
51+
"latextools_utils.internal_types",
52+
"latextools_utils.quickpanel",
53+
"latextools_utils.selectors",
5954
# depend on any previous
60-
'latextools_utils.sublime_utils',
61-
'latextools_utils.is_tex_file',
62-
'latextools_utils.tex_directives',
63-
'latextools_utils.tex_log',
64-
55+
"latextools_utils.sublime_utils",
56+
"latextools_utils.is_tex_file",
57+
"latextools_utils.tex_directives",
58+
"latextools_utils.tex_log",
6559
# depend on any previous
66-
'latextools_utils.analysis',
67-
'latextools_utils.ana_utils',
68-
'latextools_utils.output_directory',
69-
'latextools_utils.bibcache',
70-
71-
'latextools_plugin',
72-
60+
"latextools_utils.analysis",
61+
"latextools_utils.ana_utils",
62+
"latextools_utils.output_directory",
63+
"latextools_utils.bibcache",
64+
"latextools_plugin",
7365
# ensure latex_fill_all is loaded before the modules that depend on it
74-
'latex_fill_all',
75-
66+
"latex_fill_all",
7667
# preview related modules
77-
'st_preview.preview_utils',
78-
'st_preview.preview_threading',
68+
"st_preview.preview_utils",
69+
"st_preview.preview_threading",
7970
]
8071

8172
EXPORT_MODULES = [
82-
'latextools_utils.input_quickpanel',
83-
'st_preview.preview_math',
84-
'st_preview.preview_image'
73+
"latextools_utils.input_quickpanel",
74+
"st_preview.preview_math",
75+
"st_preview.preview_image",
8576
]
8677

8778
LOAD_ORDER += EXPORT_MODULES
@@ -107,7 +98,7 @@ def plugin_loaded():
10798
logging.init()
10899

109100
# reload any plugins cached in memory
110-
mods = [m for m in sys.modules if m.startswith('_latextools_')]
101+
mods = [m for m in sys.modules if m.startswith("_latextools_")]
111102
for mod in mods:
112103
del sys.modules[mod]
113104

02_temp_file_cleanup.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@
1111
# here we cleanup any directories listed in the temporary_output_dirs
1212
# file as having been previously created by the plugin
1313

14+
1415
def plugin_loaded():
1516
temporary_output_dirs = os.path.join(
16-
sublime.cache_path(),
17-
'LaTeXTools',
18-
'temporary_output_dirs'
17+
sublime.cache_path(), "LaTeXTools", "temporary_output_dirs"
1918
)
2019

2120
if os.path.exists(temporary_output_dirs):
22-
with open(temporary_output_dirs, 'r') as f:
21+
with open(temporary_output_dirs, "r") as f:
2322
data = json.load(f)
2423

2524
tempdir = tempfile.gettempdir()
2625

2726
try:
28-
for directory in data['directories']:
27+
for directory in data["directories"]:
2928
# shutil.rmtree is a rather blunt tool, so here we try to
3029
# ensure we are only deleting legitimate temporary files
3130
if (
32-
directory is None or
33-
not isinstance(directory, str) or
34-
not directory.startswith(tempdir)
31+
directory is None
32+
or not isinstance(directory, str)
33+
or not directory.startswith(tempdir)
3534
):
3635
continue
3736

@@ -40,7 +39,7 @@ def plugin_loaded():
4039
except OSError:
4140
pass
4241
else:
43-
logger.info('Deleted old temp directory %s', directory)
42+
logger.info("Deleted old temp directory %s", directory)
4443
except KeyError:
4544
pass
4645

auto_label.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"LatextoolsAutoInserLabelListener",
1111
]
1212

13+
1314
def _RE_FIND_SECTION(command_mapping):
1415
return re.compile(
1516
r"\\(?P<command>" + "|".join(command_mapping.keys()) + r"|caption)"
@@ -72,7 +73,7 @@ def _find_label_content(view, pos, find_region):
7273
else:
7374
label_content = "label"
7475
# change the label if we are inside a equation and it is not set already
75-
if (label_type == "???" and view.match_selector(pos, "meta.environment.math")):
76+
if label_type == "???" and view.match_selector(pos, "meta.environment.math"):
7677
env_mapping = get_setting("auto_label_env_mapping", {})
7778
label_type = env_mapping.get("<math>", "eq")
7879
elif label_type == "???":
@@ -101,8 +102,7 @@ def run(self, edit):
101102
line_above = view.line(view.line(pos).a - 1)
102103
find_region = sublime.Region(line_above.a, pos)
103104

104-
label_type, label_content = _find_label_content(
105-
view, pos, find_region)
105+
label_type, label_content = _find_label_content(view, pos, find_region)
106106

107107
before_text, after_text = _create_surrounding_text(view, pos)
108108

@@ -113,16 +113,14 @@ def run(self, edit):
113113
"{before_text}" # leading \label{
114114
"${{1:{label_type}}}:${{2:{label_content}}}"
115115
"{after_text}" # trailing }
116-
"$0"
117-
.format(**locals())
116+
"$0".format(**locals())
118117
)
119118
view.run_command("insert_snippet", {"contents": snippet})
120119
else:
121120
content = (
122121
"{before_text}" # leading \label{
123122
"{label_type}:{label_content}"
124-
"{after_text}" # trailing }
125-
.format(**locals())
123+
"{after_text}".format(**locals()) # trailing }
126124
)
127125
view.insert(edit, pos, content)
128126

@@ -139,5 +137,6 @@ def on_query_context(self, view, key, operator, operand, match_all):
139137
else:
140138
raise Exception(
141139
"latextools.setting.auto_label_auto_trigger; "
142-
"Invalid operator must be EQUAL or NOT_EQUAL.")
140+
"Invalid operator must be EQUAL or NOT_EQUAL."
141+
)
143142
return result

biblatex_crossref_completions.py

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,21 @@
1414
# constructing them here
1515
#
1616
# VALUE_REGEX is a common suffix to hand the `= {<value>,<value>}` part
17-
VALUE_REGEX = (
18-
r'(?!.*\})\s*(?P<ENTRIES>(?:,[^,]*)+\b)?\s*(?P<OPEN>\{)?'
19-
r'(?P<EQUALS>\s*=\s*)?'
20-
)
17+
VALUE_REGEX = r"(?!.*\})\s*(?P<ENTRIES>(?:,[^,]*)+\b)?\s*(?P<OPEN>\{)?" r"(?P<EQUALS>\s*=\s*)?"
2118

22-
CROSSREF_REGEX = re.compile(
23-
VALUE_REGEX + r'crossref'[::-1] + r'\b',
24-
re.IGNORECASE
25-
)
19+
CROSSREF_REGEX = re.compile(VALUE_REGEX + r"crossref"[::-1] + r"\b", re.IGNORECASE)
2620

2721
BIBLATEX_REGEX = re.compile(
28-
VALUE_REGEX +
29-
r'(?:' + r'|'.join((s[::-1] for s in ('xref', 'related'))) + r')' + r'\b',
30-
re.IGNORECASE
22+
VALUE_REGEX + r"(?:" + r"|".join((s[::-1] for s in ("xref", "related"))) + r")" + r"\b",
23+
re.IGNORECASE,
3124
)
3225

33-
ENTRY_SET_REGEX = re.compile(
34-
VALUE_REGEX + r'entryset'[::-1] + r'\b',
35-
re.IGNORECASE
36-
)
26+
ENTRY_SET_REGEX = re.compile(VALUE_REGEX + r"entryset"[::-1] + r"\b", re.IGNORECASE)
3727

38-
XDATA_REGEX = re.compile(
39-
VALUE_REGEX + r'xdata'[::-1] + r'\b',
40-
re.IGNORECASE
41-
)
28+
XDATA_REGEX = re.compile(VALUE_REGEX + r"xdata"[::-1] + r"\b", re.IGNORECASE)
4229

4330
# set indicating entries that have their own special handling...
44-
SPECIAL_ENTRIES = set(['@xdata', '@set'])
31+
SPECIAL_ENTRIES = set(["@xdata", "@set"])
4532

4633

4734
def _get_keys_by_type(view, valid_types):
@@ -51,19 +38,22 @@ def _get_keys_by_type(view, valid_types):
5138
if callable(valid_types):
5239
validator = valid_types
5340
elif isinstance(valid_types, str):
41+
5442
def validator(s):
5543
return s == valid_types
44+
5645
else:
46+
5747
def validator(s):
5848
return s in valid_types
5949

6050
keys = []
6151

6252
contents = view.substr(sublime.Region(0, view.size()))
6353
for entry_type, key in re.findall(
64-
r'(@(?!preamble|comment|string)[a-zA-Z]+)\s*\{\s*([^,]+)\b',
54+
r"(@(?!preamble|comment|string)[a-zA-Z]+)\s*\{\s*([^,]+)\b",
6555
contents,
66-
re.IGNORECASE
56+
re.IGNORECASE,
6757
):
6858
if validator(entry_type):
6959
keys.append(key)
@@ -78,15 +68,9 @@ def _get_keys_from_id_field(view):
7868
contents = view.substr(sublime.Region(0, view.size()))
7969
# TODO: Should probably figure out how to work out the entry-type
8070
for ids in re.findall(
81-
r'\bids\s*=\s*\{([^}]+)\}',
82-
contents,
83-
re.IGNORECASE | re.UNICODE | re.DOTALL
71+
r"\bids\s*=\s*\{([^}]+)\}", contents, re.IGNORECASE | re.UNICODE | re.DOTALL
8472
):
85-
for key in re.findall(
86-
r'\b([^,]+)\b',
87-
ids,
88-
re.IGNORECASE | re.UNICODE
89-
):
73+
for key in re.findall(r"\b([^,]+)\b", ids, re.IGNORECASE | re.UNICODE):
9074
keys.append(key)
9175

9276
return keys
@@ -97,16 +81,15 @@ def _get_cite_keys_validator(s):
9781

9882

9983
def get_cite_keys(view):
100-
return _get_keys_by_type(view, _get_cite_keys_validator) + \
101-
_get_keys_from_id_field(view)
84+
return _get_keys_by_type(view, _get_cite_keys_validator) + _get_keys_from_id_field(view)
10285

10386

10487
def get_xdata_keys(view):
105-
return _get_keys_by_type(view, '@xdata')
88+
return _get_keys_by_type(view, "@xdata")
10689

10790

10891
def get_entryset_keys(view):
109-
return _get_keys_by_type(view, '@set')
92+
return _get_keys_by_type(view, "@set")
11093

11194

11295
def get_text_to_cursor(view):
@@ -117,59 +100,49 @@ def get_text_to_cursor(view):
117100

118101
# builds the replacement string depending on the current context of the line
119102
def _get_replacement(matcher, key):
120-
if not matcher.group('ENTRIES'):
121-
return '{0}{1}{2}{3}'.format(
122-
'' if matcher.group('EQUALS') else '= ',
123-
'' if matcher.group('OPEN') else '{',
103+
if not matcher.group("ENTRIES"):
104+
return "{0}{1}{2}{3}".format(
105+
"" if matcher.group("EQUALS") else "= ",
106+
"" if matcher.group("OPEN") else "{",
124107
key,
125-
'' if matcher.group('OPEN') else '}'
108+
"" if matcher.group("OPEN") else "}",
126109
)
127110

128-
return '{0}{1}'.format(
129-
',' if matcher.group('ENTRIES')[0] != ',' else '',
130-
key
131-
)
111+
return "{0}{1}".format("," if matcher.group("ENTRIES")[0] != "," else "", key)
132112

133113

134114
def get_completions_if_matches(regex, line, get_key_list_func, view):
135115
matcher = regex.match(line)
136116
if matcher:
137117
return (
138-
[
139-
(key, _get_replacement(matcher, key))
140-
for key in sorted(set(get_key_list_func(view)))
141-
],
142-
sublime.INHIBIT_WORD_COMPLETIONS
118+
[(key, _get_replacement(matcher, key)) for key in sorted(set(get_key_list_func(view)))],
119+
sublime.INHIBIT_WORD_COMPLETIONS,
143120
)
144121
else:
145122
return []
146123

147124

148125
class BiblatexCrossrefCompletions(sublime_plugin.EventListener):
149126
def on_query_completions(self, view, prefix, locations):
150-
if not view.match_selector(locations[0], 'text.bibtex, text.biblatex'):
127+
if not view.match_selector(locations[0], "text.bibtex, text.biblatex"):
151128
return []
152129

153130
current_line = get_text_to_cursor(view)[::-1]
154131

155132
if current_line.startswith(prefix[::-1]):
156-
current_line = current_line[len(prefix):]
133+
current_line = current_line[len(prefix) :]
157134

158-
result = get_completions_if_matches(
159-
CROSSREF_REGEX, current_line, get_cite_keys, view)
135+
result = get_completions_if_matches(CROSSREF_REGEX, current_line, get_cite_keys, view)
160136

161137
if result:
162138
return result
163139

164-
if not view.match_selector(locations[0], 'text.biblatex'):
140+
if not view.match_selector(locations[0], "text.biblatex"):
165141
return []
166142

167143
return (
168-
get_completions_if_matches(
169-
BIBLATEX_REGEX, current_line, get_cite_keys, view) or
170-
get_completions_if_matches(
171-
XDATA_REGEX, current_line, get_xdata_keys, view) or
172-
get_completions_if_matches(
173-
ENTRY_SET_REGEX, current_line, get_entryset_keys, view) or
174-
[]
144+
get_completions_if_matches(BIBLATEX_REGEX, current_line, get_cite_keys, view)
145+
or get_completions_if_matches(XDATA_REGEX, current_line, get_xdata_keys, view)
146+
or get_completions_if_matches(ENTRY_SET_REGEX, current_line, get_entryset_keys, view)
147+
or []
175148
)

0 commit comments

Comments
 (0)