Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4799a02

Browse files
committed
Clean up flake8 stylistic things.
1 parent4fd177e commit4799a02

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

‎_websiteutils/make_redirects_links.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
importargparse
2-
importglob
32
importlogging
43
importmultiprocessing
54
importos
65
importpathlib
76
importre
8-
importsubprocess
9-
importsys
107
importtempfile
118
importshutil
129

@@ -89,14 +86,16 @@ def findlast(fname, tocheck, *, _cache={}):
8986

9087
# note these are all one line so they are easy to search and replace in the
9188
# html files (otherwise we need to close tags)
92-
warn_banner_exists= ('<div id="olddocs-message"> You are reading an old '
93-
'version of the documentation (v%s). For the latest version see '
94-
'<a href="%s">%s</a></div>\n')
89+
warn_banner_exists= (
90+
'<div id="olddocs-message"> You are reading an old version of the'
91+
'documentation (v%s). For the latest version see '
92+
'<a href="%s">%s</a></div>\n')
9593

9694

97-
warn_banner_old= ('<div id="olddocs-message"> You are reading an old '
98-
'version of the documentation (v%s). For the latest version see '
99-
'<a href="/stable/">https://matplotlib.org/stable/</a> </div>\n')
95+
warn_banner_old= (
96+
'<div id="olddocs-message"> You are reading an old version of the'
97+
'documentation (v%s). For the latest version see '
98+
'<a href="/stable/">https://matplotlib.org/stable/</a> </div>\n')
10099

101100

102101
defdo_links(root0):
@@ -152,7 +151,7 @@ def do_canonicals(dname):
152151
basename=pathlib.Path(*p.parts[1:])
153152
last=findlast(basename,tocheck)
154153
iflastisnotNone:
155-
update_canonical(fullname,last,dname==tocheck[1])
154+
update_canonical(fullname,last,dname==tocheck[1])
156155

157156

158157
defupdate_canonical(fullname,last,newest):
@@ -162,26 +161,23 @@ def update_canonical(fullname, last, newest):
162161
removing any other content on a line that has the canonical link.
163162
164163
Also add a banner (div) in the body if an old version of the docs.
165-
164+
166165
Note that if for some reason there are more than one canonical link
167166
this will change all of them.
168167
"""
169168
p=pathlib.Path(fullname)
170169
pre="https://matplotlib.org/"
171170
pnew=pathlib.Path(last,*p.parts[1:])
172-
newcanon=f"{pre+str(pnew)}"
173-
_log.info(f"{p} to{pre+str(pnew)}")
171+
newcanon=f"{pre}{str(pnew)}"
172+
_log.info(f"{p} to{pre}{str(pnew)}")
174173
rec=re.compile(b'<link rel="canonical" href=".*"')
175174
withtempfile.NamedTemporaryFile(delete=False)asfout:
176175
found=False
177176
withopen(fullname,"rb")asfin:
178177
forlineinfin:
179178
ifnotfoundandb'<link rel="canonical"'inline:
180-
new=bytes(
181-
f'<link rel="canonical" href="{newcanon}"',
182-
encoding="utf-8"
183-
)
184-
ll=rec.sub(new,line)
179+
new=f'<link rel="canonical" href="{newcanon}"'
180+
ll=rec.sub(new.encode("utf-8"),line)
185181
_log.debug(f"new{line}->{ll}")
186182
fout.write(ll)
187183
found=True
@@ -194,12 +190,11 @@ def update_canonical(fullname, last, newest):
194190
newcanon)
195191
else:
196192
new=warn_banner_old% (p.parts[0])
197-
fout.write(bytes(new,encoding="utf-8"))
198-
ifnotb'<div>'inline:
199-
# write the line out if itwasnt' an olddocs-message:
193+
fout.write(new.encode("utf-8"))
194+
ifb'<div>'notinline:
195+
# write the line out if itwasn't an olddocs-message:
200196
fout.write(line)
201197

202-
203198
else:
204199
fout.write(line)
205200

@@ -211,12 +206,10 @@ def update_canonical(fullname, last, newest):
211206
parser=argparse.ArgumentParser(description="Optional app description")
212207

213208
parser.add_argument("--np",type=int,help="Number of processors to use")
214-
parser.add_argument(
215-
"--no_canonicals",help="do not do canonical links",action="store_true"
216-
)
217-
parser.add_argument(
218-
"--no_redirects",help="do not do redirects links",action="store_true"
219-
)
209+
parser.add_argument("--no_canonicals",help="do not do canonical links",
210+
action="store_true")
211+
parser.add_argument("--no_redirects",help="do not do redirects links",
212+
action="store_true")
220213

221214
args=parser.parse_args()
222215
ifargs.np:
@@ -244,7 +237,8 @@ def update_canonical(fullname, last, newest):
244237
_log.info(f"Rewriting HTML:{fullname} in{last}")
245238
withopen(fullname,"w")asfout:
246239
oldname=os.path.join(last,fullname)
247-
st=html_redirect% (oldname,"/"+oldname,oldname)
240+
st=html_redirect% (oldname,"/"+oldname,
241+
oldname)
248242
fout.write(st)
249243
_log.info("Done links and redirects")
250244

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp