Run black reformatter on code
This commit is contained in:
parent
4582eb4085
commit
bd3e31bf3c
178 changed files with 4511 additions and 3385 deletions
|
|
@ -11,15 +11,15 @@ from os import rename
|
|||
|
||||
def _rst2md(filename_rst):
|
||||
|
||||
with open(filename_rst, 'r') as fil:
|
||||
with open(filename_rst, "r") as fil:
|
||||
# read rst file, reformat and save
|
||||
txt = fil.read()
|
||||
with open(filename_rst, 'w') as fil:
|
||||
with open(filename_rst, "w") as fil:
|
||||
txt = "```{eval-rst}\n" + txt + "\n```"
|
||||
fil.write(txt)
|
||||
|
||||
# rename .rst file to .md file
|
||||
filename, _ = filename_rst.rsplit('.', 1)
|
||||
filename, _ = filename_rst.rsplit(".", 1)
|
||||
filename_md = filename + ".md"
|
||||
rename(filename_rst, filename_md)
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ def auto_link_remapper(no_autodoc=False):
|
|||
|
||||
for strip_prefix in _STRIP_PREFIX:
|
||||
if url.startswith(strip_prefix):
|
||||
url = url[len(strip_prefix):]
|
||||
url = url[len(strip_prefix) :]
|
||||
|
||||
if any(url.startswith(noremap) for noremap in _NO_REMAP_STARTSWITH):
|
||||
# skip regular http/s urls etc
|
||||
|
|
@ -157,10 +157,10 @@ def auto_link_remapper(no_autodoc=False):
|
|||
|
||||
if url.startswith("evennia."):
|
||||
# api link - we want to remove legacy #reference and remove .md
|
||||
if '#' in url:
|
||||
_, url = url.rsplit('#', 1)
|
||||
if "#" in url:
|
||||
_, url = url.rsplit("#", 1)
|
||||
if url.endswith(".md"):
|
||||
url, _ = url.rsplit('.', 1)
|
||||
url, _ = url.rsplit(".", 1)
|
||||
return f"[{txt}]({url})"
|
||||
|
||||
fname, *part = url.rsplit("/", 1)
|
||||
|
|
@ -174,7 +174,9 @@ def auto_link_remapper(no_autodoc=False):
|
|||
|
||||
if _CURRFILE in docref_map and fname in docref_map[_CURRFILE]:
|
||||
cfilename = _CURRFILE.rsplit("/", 1)[-1]
|
||||
urlout = docref_map[_CURRFILE][fname] + ".md" + ("#" + anchor[0].lower() if anchor else "")
|
||||
urlout = (
|
||||
docref_map[_CURRFILE][fname] + ".md" + ("#" + anchor[0].lower() if anchor else "")
|
||||
)
|
||||
if urlout != url:
|
||||
print(f" {cfilename}: [{txt}]({url}) -> [{txt}]({urlout})")
|
||||
else:
|
||||
|
|
@ -193,7 +195,7 @@ def auto_link_remapper(no_autodoc=False):
|
|||
|
||||
for strip_prefix in _STRIP_PREFIX:
|
||||
if url.startswith(strip_prefix):
|
||||
url = url[len(strip_prefix):]
|
||||
url = url[len(strip_prefix) :]
|
||||
|
||||
if any(url.startswith(noremap) for noremap in _NO_REMAP_STARTSWITH):
|
||||
return f"[{txt}]: {url}"
|
||||
|
|
@ -202,8 +204,8 @@ def auto_link_remapper(no_autodoc=False):
|
|||
urlout = url
|
||||
elif url.startswith("evennia."):
|
||||
# api link - we want to remove legacy #reference
|
||||
if '#' in url:
|
||||
_, urlout = url.rsplit('#', 1)
|
||||
if "#" in url:
|
||||
_, urlout = url.rsplit("#", 1)
|
||||
else:
|
||||
fname, *part = url.rsplit("/", 1)
|
||||
fname = part[0] if part else fname
|
||||
|
|
|
|||
|
|
@ -50,15 +50,11 @@ tutorials are found here. Also the home of the Tutorial World demo adventure.
|
|||
"utils": """
|
||||
Miscellaneous, optional tools for manipulating text, auditing connections
|
||||
and more.
|
||||
"""
|
||||
""",
|
||||
}
|
||||
|
||||
|
||||
_FILENAME_MAP = {
|
||||
"rpsystem": "RPSystem",
|
||||
"xyzgrid": "XYZGrid",
|
||||
"awsstorage": "AWSStorage"
|
||||
}
|
||||
_FILENAME_MAP = {"rpsystem": "RPSystem", "xyzgrid": "XYZGrid", "awsstorage": "AWSStorage"}
|
||||
|
||||
HEADER = """# Contribs
|
||||
|
||||
|
|
@ -145,10 +141,14 @@ def readmes2docs(directory=_SOURCE_DIR):
|
|||
|
||||
pypath = f"evennia.contrib.{category}.{name}"
|
||||
|
||||
filename = "Contrib-" + "-".join(
|
||||
_FILENAME_MAP.get(
|
||||
part, part.capitalize() if part[0].islower() else part)
|
||||
for part in name.split("_")) + ".md"
|
||||
filename = (
|
||||
"Contrib-"
|
||||
+ "-".join(
|
||||
_FILENAME_MAP.get(part, part.capitalize() if part[0].islower() else part)
|
||||
for part in name.split("_")
|
||||
)
|
||||
+ ".md"
|
||||
)
|
||||
outfile = pathjoin(_OUT_DIR, filename)
|
||||
|
||||
with open(file_path) as fil:
|
||||
|
|
@ -163,7 +163,7 @@ def readmes2docs(directory=_SOURCE_DIR):
|
|||
except IndexError:
|
||||
blurb = name
|
||||
|
||||
with open(outfile, 'w') as fil:
|
||||
with open(outfile, "w") as fil:
|
||||
fil.write(data)
|
||||
|
||||
categories[category].append((name, credits, blurb, filename, pypath))
|
||||
|
|
@ -179,11 +179,7 @@ def readmes2docs(directory=_SOURCE_DIR):
|
|||
for tup in sorted(contrib_tups, key=lambda tup: tup[0].lower()):
|
||||
catlines.append(
|
||||
BLURB.format(
|
||||
name=tup[0],
|
||||
credits=tup[1],
|
||||
blurb=tup[2],
|
||||
filename=tup[3],
|
||||
code_location=tup[4]
|
||||
name=tup[0], credits=tup[1], blurb=tup[2], filename=tup[3], code_location=tup[4]
|
||||
)
|
||||
)
|
||||
filenames.append(f"{tup[3]}")
|
||||
|
|
@ -193,17 +189,15 @@ def readmes2docs(directory=_SOURCE_DIR):
|
|||
category=category,
|
||||
category_desc=_CATEGORY_DESCS[category].strip(),
|
||||
blurbs="\n".join(catlines),
|
||||
toctree=toctree
|
||||
toctree=toctree,
|
||||
)
|
||||
)
|
||||
|
||||
text = _FILE_STRUCTURE.format(
|
||||
header=HEADER,
|
||||
categories="\n".join(category_sections),
|
||||
footer=INDEX_FOOTER
|
||||
header=HEADER, categories="\n".join(category_sections), footer=INDEX_FOOTER
|
||||
)
|
||||
|
||||
with open(_OUT_INDEX_FILE, 'w') as fil:
|
||||
with open(_OUT_INDEX_FILE, "w") as fil:
|
||||
fil.write(text)
|
||||
|
||||
print(f" -- Converted Contrib READMEs to {ncount} doc pages + index.")
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ if __name__ == "__main__":
|
|||
filepaths = glob.glob(args.files, recursive=True)
|
||||
width = args.width
|
||||
|
||||
wrapper = textwrap.TextWrapper(width=width, break_long_words=False, expand_tabs=True,)
|
||||
wrapper = textwrap.TextWrapper(
|
||||
width=width,
|
||||
break_long_words=False,
|
||||
expand_tabs=True,
|
||||
)
|
||||
|
||||
count = 0
|
||||
for filepath in filepaths:
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@
|
|||
#
|
||||
|
||||
from os.path import dirname, abspath, join as pathjoin
|
||||
from evennia.utils.utils import (
|
||||
mod_import, variable_from_module, callables_from_module
|
||||
)
|
||||
from evennia.utils.utils import mod_import, variable_from_module, callables_from_module
|
||||
|
||||
__all__ = ("run_update")
|
||||
__all__ = "run_update"
|
||||
|
||||
|
||||
PAGE = """
|
||||
|
|
@ -33,6 +31,7 @@ with [EvEditor](EvEditor), flipping pages in [EvMore](EvMore) or using the
|
|||
|
||||
"""
|
||||
|
||||
|
||||
def run_update(no_autodoc=False):
|
||||
|
||||
if no_autodoc:
|
||||
|
|
@ -71,7 +70,8 @@ def run_update(no_autodoc=False):
|
|||
for modname in cmd_modules:
|
||||
module = mod_import(modname)
|
||||
cmds_per_module[module] = [
|
||||
cmd for cmd in callables_from_module(module).values() if cmd.__name__.startswith("Cmd")]
|
||||
cmd for cmd in callables_from_module(module).values() if cmd.__name__.startswith("Cmd")
|
||||
]
|
||||
for cmd in cmds_per_module[module]:
|
||||
cmd_to_module_map[cmd] = module
|
||||
cmds_alphabetically.append(cmd)
|
||||
|
|
@ -79,8 +79,9 @@ def run_update(no_autodoc=False):
|
|||
|
||||
cmd_infos = []
|
||||
for cmd in cmds_alphabetically:
|
||||
aliases = [alias[1:] if alias and alias[0] == "@" else alias
|
||||
for alias in sorted(cmd.aliases)]
|
||||
aliases = [
|
||||
alias[1:] if alias and alias[0] == "@" else alias for alias in sorted(cmd.aliases)
|
||||
]
|
||||
aliases = f" [{', '.join(sorted(cmd.aliases))}]" if aliases else ""
|
||||
cmdlink = f"[**{cmd.key}**{aliases}]({cmd.__module__}.{cmd.__name__})"
|
||||
category = f"help-category: _{cmd.help_category.capitalize()}_"
|
||||
|
|
@ -98,12 +99,13 @@ def run_update(no_autodoc=False):
|
|||
txt = PAGE.format(
|
||||
ncommands=len(cmd_to_cmdset_map),
|
||||
nfiles=len(cmds_per_module),
|
||||
alphabetical="\n".join(f"- {info}" for info in cmd_infos))
|
||||
alphabetical="\n".join(f"- {info}" for info in cmd_infos),
|
||||
)
|
||||
|
||||
outdir = pathjoin(dirname(dirname(abspath(__file__))), "source", "Components")
|
||||
fname = pathjoin(outdir, "Default-Commands.md")
|
||||
|
||||
with open(fname, 'w') as fil:
|
||||
with open(fname, "w") as fil:
|
||||
fil.write(txt)
|
||||
|
||||
print(" -- Updated Default Command index.")
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ DOCDIR = pathjoin(ROOTDIR, "docs")
|
|||
DOCSRCDIR = pathjoin(DOCDIR, "source")
|
||||
EVENNIADIR = pathjoin(ROOTDIR, "evennia")
|
||||
|
||||
|
||||
def update_changelog():
|
||||
"""
|
||||
Plain CHANGELOG copy
|
||||
|
|
@ -22,7 +23,7 @@ def update_changelog():
|
|||
with open(sourcefile) as fil:
|
||||
txt = fil.read()
|
||||
|
||||
with open(targetfile, 'w') as fil:
|
||||
with open(targetfile, "w") as fil:
|
||||
fil.write(txt)
|
||||
|
||||
print(" -- Updated Changelog.md")
|
||||
|
|
@ -62,7 +63,7 @@ if settings.SERVERNAME == "Evennia":
|
|||
{txt}
|
||||
```
|
||||
"""
|
||||
with open(targetfile, 'w') as fil:
|
||||
with open(targetfile, "w") as fil:
|
||||
fil.write(txt)
|
||||
|
||||
print(" -- Updated Settings-Default.md")
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
# from recommonmark.transform import AutoStructify
|
||||
from sphinx.util.osutil import cd
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ extensions = [
|
|||
"sphinx.ext.viewcode",
|
||||
"sphinx.ext.todo",
|
||||
"sphinx.ext.githubpages",
|
||||
"myst_parser"
|
||||
"myst_parser",
|
||||
]
|
||||
|
||||
source_suffix = [".md", ".rst"]
|
||||
|
|
@ -145,9 +146,11 @@ _github_code_root = "https://github.com/evennia/evennia/blob/"
|
|||
_github_doc_root = "https://github.com/evennia/tree/master/docs/sources/"
|
||||
_github_issue_choose = "https://github.com/evennia/evennia/issues/new/choose"
|
||||
_ref_regex = re.compile( # normal reference-links [txt](url)
|
||||
r"\[(?P<txt>[\w -\[\]\`\n]+?)\]\((?P<url>.+?)\)", re.I + re.S + re.U + re.M)
|
||||
r"\[(?P<txt>[\w -\[\]\`\n]+?)\]\((?P<url>.+?)\)", re.I + re.S + re.U + re.M
|
||||
)
|
||||
_ref_doc_regex = re.compile( # in-document bottom references [txt]: url
|
||||
r"\[(?P<txt>[\w -\`]+?)\\n]:\s+?(?P<url>.+?)(?=$|\n)", re.I + re.S + re.U + re.M)
|
||||
r"\[(?P<txt>[\w -\`]+?)\\n]:\s+?(?P<url>.+?)(?=$|\n)", re.I + re.S + re.U + re.M
|
||||
)
|
||||
|
||||
|
||||
def url_resolver(app, docname, source):
|
||||
|
|
@ -165,10 +168,11 @@ def url_resolver(app, docname, source):
|
|||
|
||||
|
||||
"""
|
||||
|
||||
def _url_remap(url):
|
||||
|
||||
# determine depth in tree of current document
|
||||
docdepth = docname.count('/') + 1
|
||||
docdepth = docname.count("/") + 1
|
||||
relative_path = "../".join("" for _ in range(docdepth))
|
||||
|
||||
if url.endswith(_choose_issue):
|
||||
|
|
@ -176,14 +180,14 @@ def url_resolver(app, docname, source):
|
|||
return _github_issue_choose
|
||||
elif _githubstart in url:
|
||||
# github:develop/... shortcut
|
||||
urlpath = url[url.index(_githubstart) + len(_githubstart):]
|
||||
urlpath = url[url.index(_githubstart) + len(_githubstart) :]
|
||||
if not (urlpath.startswith("develop/") or urlpath.startswith("master")):
|
||||
urlpath = "master/" + urlpath
|
||||
return _github_code_root + urlpath
|
||||
elif _sourcestart in url:
|
||||
ind = url.index(_sourcestart)
|
||||
|
||||
modpath, *inmodule = url[ind + len(_sourcestart):].rsplit("#", 1)
|
||||
modpath, *inmodule = url[ind + len(_sourcestart) :].rsplit("#", 1)
|
||||
modpath = "/".join(modpath.split("."))
|
||||
inmodule = "#" + inmodule[0] if inmodule else ""
|
||||
modpath = modpath + ".html" + inmodule
|
||||
|
|
@ -194,13 +198,13 @@ def url_resolver(app, docname, source):
|
|||
return url
|
||||
|
||||
def _re_ref_sub(match):
|
||||
txt = match.group('txt')
|
||||
url = _url_remap(match.group('url'))
|
||||
txt = match.group("txt")
|
||||
url = _url_remap(match.group("url"))
|
||||
return f"[{txt}]({url})"
|
||||
|
||||
def _re_docref_sub(match):
|
||||
txt = match.group('txt')
|
||||
url = _url_remap(match.group('url'))
|
||||
txt = match.group("txt")
|
||||
url = _url_remap(match.group("url"))
|
||||
return f"[{txt}]: {url}"
|
||||
|
||||
src = source[0]
|
||||
|
|
@ -248,7 +252,7 @@ autodoc_default_options = {
|
|||
"show-inheritance": True,
|
||||
"special-members": "__init__",
|
||||
"enable_eval_rst": True,
|
||||
"inherited_members": True
|
||||
"inherited_members": True,
|
||||
}
|
||||
|
||||
autodoc_member_order = "bysource"
|
||||
|
|
@ -345,8 +349,12 @@ def setup(app):
|
|||
|
||||
# build toctree file
|
||||
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||
from docs.pylib import (auto_link_remapper, update_default_cmd_index,
|
||||
contrib_readmes2docs, update_dynamic_pages)
|
||||
from docs.pylib import (
|
||||
auto_link_remapper,
|
||||
update_default_cmd_index,
|
||||
contrib_readmes2docs,
|
||||
update_dynamic_pages,
|
||||
)
|
||||
|
||||
_no_autodoc = os.environ.get("NOAUTODOC")
|
||||
update_default_cmd_index.run_update(no_autodoc=_no_autodoc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue