forked from github/pelican
Update code base for Python 3.8 and above
Result of: pipx run pyupgrade --py38-plus pelican/**/*.py
This commit is contained in:
parent
903ce3ce33
commit
ecd598f293
15 changed files with 58 additions and 64 deletions
|
|
@ -41,7 +41,7 @@ def decode_wp_content(content, br=True):
|
|||
if start == -1:
|
||||
content = content + pre_part
|
||||
continue
|
||||
name = "<pre wp-pre-tag-{}></pre>".format(pre_index)
|
||||
name = f"<pre wp-pre-tag-{pre_index}></pre>"
|
||||
pre_tags[name] = pre_part[start:] + "</pre>"
|
||||
content = content + pre_part[0:start] + name
|
||||
pre_index += 1
|
||||
|
|
@ -765,7 +765,7 @@ def download_attachments(output_path, urls):
|
|||
|
||||
if not os.path.exists(full_path):
|
||||
os.makedirs(full_path)
|
||||
print("downloading {}".format(filename))
|
||||
print(f"downloading {filename}")
|
||||
try:
|
||||
urlretrieve(url, os.path.join(full_path, filename))
|
||||
locations[url] = os.path.join(localpath, filename)
|
||||
|
|
@ -782,7 +782,7 @@ def is_pandoc_needed(in_markup):
|
|||
def get_pandoc_version():
|
||||
cmd = ["pandoc", "--version"]
|
||||
try:
|
||||
output = subprocess.check_output(cmd, universal_newlines=True)
|
||||
output = subprocess.check_output(cmd, text=True)
|
||||
except (subprocess.CalledProcessError, OSError) as e:
|
||||
logger.warning("Pandoc version unknown: %s", e)
|
||||
return ()
|
||||
|
|
@ -898,7 +898,7 @@ def fields2pelican(
|
|||
new_content = decode_wp_content(content)
|
||||
else:
|
||||
paragraphs = content.splitlines()
|
||||
paragraphs = ["<p>{}</p>".format(p) for p in paragraphs]
|
||||
paragraphs = [f"<p>{p}</p>" for p in paragraphs]
|
||||
new_content = "".join(paragraphs)
|
||||
with open(html_filename, "w", encoding="utf-8") as fp:
|
||||
fp.write(new_content)
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ def ask(question, answer=str, default=None, length=None):
|
|||
r = ""
|
||||
while True:
|
||||
if default:
|
||||
r = input("> {} [{}] ".format(question, default))
|
||||
r = input(f"> {question} [{default}] ")
|
||||
else:
|
||||
r = input("> {} ".format(question))
|
||||
r = input(f"> {question} ")
|
||||
|
||||
r = r.strip()
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ def ask(question, answer=str, default=None, length=None):
|
|||
print("You must enter something")
|
||||
else:
|
||||
if length and len(r) != length:
|
||||
print("Entry must be {} characters long".format(length))
|
||||
print(f"Entry must be {length} characters long")
|
||||
else:
|
||||
break
|
||||
|
||||
|
|
@ -114,11 +114,11 @@ def ask(question, answer=str, default=None, length=None):
|
|||
r = None
|
||||
while True:
|
||||
if default is True:
|
||||
r = input("> {} (Y/n) ".format(question))
|
||||
r = input(f"> {question} (Y/n) ")
|
||||
elif default is False:
|
||||
r = input("> {} (y/N) ".format(question))
|
||||
r = input(f"> {question} (y/N) ")
|
||||
else:
|
||||
r = input("> {} (y/n) ".format(question))
|
||||
r = input(f"> {question} (y/n) ")
|
||||
|
||||
r = r.strip().lower()
|
||||
|
||||
|
|
@ -138,9 +138,9 @@ def ask(question, answer=str, default=None, length=None):
|
|||
r = None
|
||||
while True:
|
||||
if default:
|
||||
r = input("> {} [{}] ".format(question, default))
|
||||
r = input(f"> {question} [{default}] ")
|
||||
else:
|
||||
r = input("> {} ".format(question))
|
||||
r = input(f"> {question} ")
|
||||
|
||||
r = r.strip()
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ def render_jinja_template(tmpl_name: str, tmpl_vars: Mapping, target_path: str):
|
|||
_template = _jinja_env.get_template(tmpl_name)
|
||||
fd.write(_template.render(**tmpl_vars))
|
||||
except OSError as e:
|
||||
print("Error: {}".format(e))
|
||||
print(f"Error: {e}")
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -376,12 +376,12 @@ needed by Pelican.
|
|||
try:
|
||||
os.makedirs(os.path.join(CONF["basedir"], "content"))
|
||||
except OSError as e:
|
||||
print("Error: {}".format(e))
|
||||
print(f"Error: {e}")
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.join(CONF["basedir"], "output"))
|
||||
except OSError as e:
|
||||
print("Error: {}".format(e))
|
||||
print(f"Error: {e}")
|
||||
|
||||
conf_python = dict()
|
||||
for key, value in CONF.items():
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def main():
|
|||
"-V",
|
||||
"--version",
|
||||
action="version",
|
||||
version="pelican-themes v{}".format(__version__),
|
||||
version=f"pelican-themes v{__version__}",
|
||||
help="Print the version of this script",
|
||||
)
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ def install(path, v=False, u=False):
|
|||
install(path, v)
|
||||
else:
|
||||
if v:
|
||||
print("Copying '{p}' to '{t}' ...".format(p=path, t=theme_path))
|
||||
print(f"Copying '{path}' to '{theme_path}' ...")
|
||||
try:
|
||||
shutil.copytree(path, theme_path)
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ def symlink(path, v=False):
|
|||
err(path + " : already exists")
|
||||
else:
|
||||
if v:
|
||||
print("Linking `{p}' to `{t}' ...".format(p=path, t=theme_path))
|
||||
print(f"Linking `{path}' to `{theme_path}' ...")
|
||||
try:
|
||||
os.symlink(path, theme_path)
|
||||
except Exception as e:
|
||||
|
|
@ -288,12 +288,12 @@ def clean(v=False):
|
|||
path = os.path.join(_THEMES_PATH, path)
|
||||
if os.path.islink(path) and is_broken_link(path):
|
||||
if v:
|
||||
print("Removing {}".format(path))
|
||||
print(f"Removing {path}")
|
||||
try:
|
||||
os.remove(path)
|
||||
except OSError:
|
||||
print("Error: cannot remove {}".format(path))
|
||||
print(f"Error: cannot remove {path}")
|
||||
else:
|
||||
c += 1
|
||||
|
||||
print("\nRemoved {} broken links".format(c))
|
||||
print(f"\nRemoved {c} broken links")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue