Skip to content

Commit 7f8631d

Browse files
committed
style: Apply isort & black style
1 parent bbb0b86 commit 7f8631d

Some content is hidden

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

54 files changed

+2179
-1704
lines changed

docs/conf.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20-
project = 'python-fluent'
20+
project = "python-fluent"
2121

2222

2323
# -- General configuration ---------------------------------------------------
@@ -26,49 +26,48 @@
2626
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2727
# ones.
2828
extensions = [
29-
'sphinx.ext.intersphinx',
30-
'sphinx.ext.viewcode',
31-
'sphinx.ext.autodoc',
29+
"sphinx.ext.intersphinx",
30+
"sphinx.ext.viewcode",
31+
"sphinx.ext.autodoc",
3232
]
3333

3434
# Add any paths that contain templates here, relative to this directory.
35-
templates_path = ['_templates']
35+
templates_path = ["_templates"]
3636

3737

3838
# Add src_dir/docs/_templates in a hook as we only have the src_dir then.
3939
def setup(app):
40-
app.connect('config-inited', add_templates)
40+
app.connect("config-inited", add_templates)
4141

4242

4343
def add_templates(app, config):
44-
config.templates_path.insert(0, f'{app.srcdir}/_templates')
44+
config.templates_path.insert(0, f"{app.srcdir}/_templates")
4545

4646

4747
# List of patterns, relative to source directory, that match files and
4848
# directories to ignore when looking for source files.
4949
# This pattern also affects html_static_path and html_extra_path.
50-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
50+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
5151

5252

5353
# -- Options for HTML output -------------------------------------------------
5454

5555
# The theme to use for HTML and HTML Help pages. See the documentation for
5656
# a list of builtin themes.
5757
#
58-
html_theme = 'nature'
58+
html_theme = "nature"
5959

6060
# Add any paths that contain custom static files (such as style sheets) here,
6161
# relative to this directory. They are copied after the builtin static files,
6262
# so a file named "default.css" will overwrite the builtin "default.css".
63-
html_static_path = ['_static']
64-
html_css_files = ['project-fluent.css']
65-
html_js_files = ['versions.js']
63+
html_static_path = ["_static"]
64+
html_css_files = ["project-fluent.css"]
65+
html_js_files = ["versions.js"]
6666

6767
html_sidebars = {
68-
'**': ['globaltoc.html', 'versions.html', 'searchbox.html'],
69-
}
70-
html_theme_options = {
68+
"**": ["globaltoc.html", "versions.html", "searchbox.html"],
7169
}
70+
html_theme_options = {}
7271

7372
# -- Extension configuration -------------------------------------------------
7473

@@ -79,6 +78,6 @@ def add_templates(app, config):
7978

8079
# -- Options for autodoc extension --------------------------------------------
8180
autodoc_mock_imports = [
82-
'attr',
81+
"attr",
8382
]
84-
autodoc_member_order = 'bysource'
83+
autodoc_member_order = "bysource"

fluent.docs/fluent/docs/__init__.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from pathlib import Path
2+
23
from .build import DocBuilder
34

45

56
def finalize_builddir(repo_name):
6-
'Bookkeeping on the docs build directory'
7-
root = Path('_build') / repo_name
8-
with open(root / '.nojekyll', 'w') as fh:
9-
fh.write('')
7+
"Bookkeeping on the docs build directory"
8+
root = Path("_build") / repo_name
9+
with open(root / ".nojekyll", "w") as fh:
10+
fh.write("")
1011

1112

1213
def build_root(repo_name):
13-
'''Build the top-level documentation.
14+
"""Build the top-level documentation.
1415
1516
See :py:mod:`.build` on building sub-projects.
16-
'''
17-
with DocBuilder(repo_name, '.') as builder:
17+
"""
18+
with DocBuilder(repo_name, ".") as builder:
1819
builder.build()

fluent.docs/fluent/docs/build.py

+57-56
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
from collections import defaultdict
21
import os
3-
from pathlib import Path
42
import shutil
53
import subprocess
64
import tempfile
5+
from collections import defaultdict
6+
from pathlib import Path
7+
78
from .tags import get_tag_infos
89

910

1011
def build(repo_name, projects, releases_after=None):
11-
'''Build documentation for projects.
12+
"""Build documentation for projects.
1213
1314
Build the given projects in _build/repo_name.
1415
Create versioned documentations for tags after ``releases_after``,
1516
if given.
16-
'''
17+
"""
1718
tagged_versions = []
1819
if releases_after:
1920
tagged_versions = [
20-
tag for tag in get_tag_infos(releases_after)
21-
if tag.project in projects
21+
tag for tag in get_tag_infos(releases_after) if tag.project in projects
2222
]
2323
# List of versions we have for each project
2424
versions_4_project = defaultdict(list)
@@ -28,54 +28,45 @@ def build(repo_name, projects, releases_after=None):
2828
for project in projects:
2929
if project in versions_4_project:
3030
last_vers[project] = versions_4_project[project][0]
31-
versions_4_project[project][:0] = ['dev', 'stable']
31+
versions_4_project[project][:0] = ["dev", "stable"]
3232
else:
3333
# No releases yet, just dev
34-
last_vers[project] = 'dev'
35-
versions_4_project[project].append('dev')
34+
last_vers[project] = "dev"
35+
versions_4_project[project].append("dev")
3636
# Build current dev version for each project
3737
for project in projects:
3838
src_dir = project
3939
builder = ProjectBuilder(
40-
repo_name, src_dir, project, versions_4_project[project], 'dev'
40+
repo_name, src_dir, project, versions_4_project[project], "dev"
4141
)
4242
with builder:
4343
builder.build()
4444
# Create redirect page from project to stable release or dev
45-
index = Path(f'_build/{repo_name}/{project}/index.html')
46-
target = 'stable' if last_vers[project] != 'dev' else 'dev'
47-
index.write_text(
48-
f'<meta http-equiv="refresh" content="0; URL={target}/">\n'
49-
)
45+
index = Path(f"_build/{repo_name}/{project}/index.html")
46+
target = "stable" if last_vers[project] != "dev" else "dev"
47+
index.write_text(f'<meta http-equiv="refresh" content="0; URL={target}/">\n')
5048
worktree = None
5149
for tag in tagged_versions:
5250
if worktree is None:
5351
worktree = tempfile.mkdtemp()
54-
subprocess.run([
55-
'git',
56-
'worktree', 'add',
57-
'--detach',
58-
worktree
59-
])
60-
subprocess.run([
61-
'git',
62-
'checkout',
63-
f'{tag.project}@{tag.version}'
64-
], cwd=worktree)
52+
subprocess.run(["git", "worktree", "add", "--detach", worktree])
53+
subprocess.run(
54+
["git", "checkout", f"{tag.project}@{tag.version}"], cwd=worktree
55+
)
6556
with ProjectBuilder(
6657
repo_name,
6758
os.path.join(worktree, tag.project),
6859
tag.project,
6960
versions_4_project[tag.project],
70-
tag.version
61+
tag.version,
7162
) as builder:
7263
builder.build()
7364
if worktree is not None:
7465
shutil.rmtree(worktree)
7566
for project in projects:
76-
if last_vers[project] == 'dev':
67+
if last_vers[project] == "dev":
7768
continue
78-
stable = Path(f'_build/{repo_name}/{project}/stable')
69+
stable = Path(f"_build/{repo_name}/{project}/stable")
7970
if stable.is_symlink():
8071
stable.unlink()
8172
if stable.exists():
@@ -84,8 +75,7 @@ def build(repo_name, projects, releases_after=None):
8475

8576

8677
class DocBuilder:
87-
'''Builder for the top-level documentation.
88-
'''
78+
"""Builder for the top-level documentation."""
8979

9080
def __init__(self, repo_name, src_dir):
9181
self.repo_name = repo_name
@@ -103,22 +93,31 @@ def build(self):
10393
subprocess.check_call(cmd, env=env)
10494

10595
def command(self):
106-
return self.cmd_prefix + self.cmd_opts + [
107-
f'{self.src_dir}/docs',
108-
self.dest_dir,
109-
]
96+
return (
97+
self.cmd_prefix
98+
+ self.cmd_opts
99+
+ [
100+
f"{self.src_dir}/docs",
101+
self.dest_dir,
102+
]
103+
)
110104

111105
def environ(self):
112106
return os.environ.copy()
113107

114108
@property
115109
def cmd_prefix(self):
116110
return [
117-
'sphinx-build',
118-
'-c', 'docs',
119-
'-a', '-E', '-W',
120-
'-A', 'root_url=/' + self.repo_name,
121-
'-d', self.doc_tree,
111+
"sphinx-build",
112+
"-c",
113+
"docs",
114+
"-a",
115+
"-E",
116+
"-W",
117+
"-A",
118+
"root_url=/" + self.repo_name,
119+
"-d",
120+
self.doc_tree,
122121
]
123122

124123
@property
@@ -127,16 +126,16 @@ def cmd_opts(self):
127126

128127
@property
129128
def dest_dir(self):
130-
return f'_build/{self.repo_name}'
129+
return f"_build/{self.repo_name}"
131130

132131
@property
133132
def doc_tree(self):
134-
return '_build/doctrees'
133+
return "_build/doctrees"
135134

136135

137136
class ProjectBuilder(DocBuilder):
138-
'''Builder for individual projects, with project name and version.
139-
'''
137+
"""Builder for individual projects, with project name and version."""
138+
140139
def __init__(self, repo_name, src_dir, project_name, versions, version):
141140
super().__init__(repo_name, src_dir)
142141
self.project_name = project_name
@@ -146,9 +145,9 @@ def __init__(self, repo_name, src_dir, project_name, versions, version):
146145
def __exit__(self, exc_type, exc_val, exc_tb):
147146
# Remove static theme files from project static, they're
148147
# used from the top-level _static.
149-
for staticfile in Path(self.dest_dir).glob('_static/*'):
148+
for staticfile in Path(self.dest_dir).glob("_static/*"):
150149
# The options are project-specific.
151-
if staticfile.name != 'documentation_options.js':
150+
if staticfile.name != "documentation_options.js":
152151
staticfile.unlink()
153152
return False
154153

@@ -158,36 +157,38 @@ def build(self):
158157

159158
def environ(self):
160159
env = super().environ()
161-
env['PYTHONPATH'] = self.src_dir
160+
env["PYTHONPATH"] = self.src_dir
162161
return env
163162

164163
@property
165164
def cmd_opts(self):
166165
opts = [
167-
'-D', 'project=' + self.project_name,
166+
"-D",
167+
"project=" + self.project_name,
168168
]
169-
if self.version != 'dev':
169+
if self.version != "dev":
170170
opts += [
171-
'-D', f'release={self.version}',
171+
"-D",
172+
f"release={self.version}",
172173
]
173174
return opts
174175

175176
@property
176177
def dest_dir(self):
177-
return f'_build/{self.repo_name}/{self.project_name}/{self.version}'
178+
return f"_build/{self.repo_name}/{self.project_name}/{self.version}"
178179

179180
def create_versions_doc(self):
180-
target_path = Path(self.src_dir) / 'docs' / '_templates'
181+
target_path = Path(self.src_dir) / "docs" / "_templates"
181182
target_path.mkdir(exist_ok=True)
182-
target_path = target_path / 'versions.html'
183-
links = ' '.join(
183+
target_path = target_path / "versions.html"
184+
links = " ".join(
184185
f'<a href="/{self.repo_name}/{self.project_name}/{v}">{v}</a>'
185186
for v in self.versions
186187
)
187-
content = f'''<h3>Versions</h3>
188+
content = f"""<h3>Versions</h3>
188189
<p id="versions">
189190
<span class="version">{self.version}</span>
190191
<span class="links">{links}</span>
191192
</p>
192-
'''
193+
"""
193194
target_path.write_text(content)

fluent.docs/fluent/docs/tags.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
from datetime import date
21
import subprocess
2+
from datetime import date
33

44

55
def get_tag_infos(cut_off_date):
6-
'''Get fluent.* tags newer than cut_off_date.
6+
"""Get fluent.* tags newer than cut_off_date.
77
TagInfo objects are ordered by committer date, newest first.
8-
'''
8+
"""
99
taglines = subprocess.run(
1010
[
11-
'git', 'tag', '--list', 'fluent.*',
12-
'--sort=-committerdate',
13-
'--format=%(refname:lstrip=2) %(committerdate:short)',
11+
"git",
12+
"tag",
13+
"--list",
14+
"fluent.*",
15+
"--sort=-committerdate",
16+
"--format=%(refname:lstrip=2) %(committerdate:short)",
1417
],
15-
encoding='utf-8',
18+
encoding="utf-8",
1619
stdout=subprocess.PIPE,
17-
check=True
20+
check=True,
1821
).stdout.splitlines()
19-
return [
20-
ti for ti in (TagInfo(line) for line in taglines)
21-
if ti.date > cut_off_date
22-
]
22+
return [ti for ti in (TagInfo(line) for line in taglines) if ti.date > cut_off_date]
2323

2424

2525
class TagInfo:
2626
def __init__(self, tagline):
27-
tag, date_string = tagline.split(' ')
28-
self.project, self.version = tag.split('@')
27+
tag, date_string = tagline.split(" ")
28+
self.project, self.version = tag.split("@")
2929
self.date = date.fromisoformat(date_string)
3030

3131
@property
3232
def tag(self):
33-
return f'{self.project}@{self.version}'
33+
return f"{self.project}@{self.version}"
3434

3535
def __repr__(self):
36-
return f'{self.tag} ({self.date})'
36+
return f"{self.tag} ({self.date})"

0 commit comments

Comments
 (0)