Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Jul 22, 2020
1 parent 40831b3 commit 18fee73
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 46 deletions.
4 changes: 2 additions & 2 deletions repo_helper/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def create_short_desc_block(short_desc: str) -> str:
loader=BaseLoader, # type: ignore
undefined=StrictUndefined,
).from_string(
"""\
"""\
.. start installation
.. tabs::
Expand Down Expand Up @@ -362,7 +362,7 @@ def create_short_desc_block(short_desc: str) -> str:
.. end installation
"""
)
)


def create_docs_install_block(
Expand Down
6 changes: 4 additions & 2 deletions repo_helper/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def make_auto_assign_action(repo_path: pathlib.Path, templates: jinja2.Environme
# numberOfAssignees: 2
# more settings at https://github.com/marketplace/actions/auto-assign-action
""")
"""
)

return [".github/workflows/assign.yml", ".github/workflow/assign.yml", ".github/auto_assign.yml"]

Expand Down Expand Up @@ -133,7 +134,8 @@ def make_dependabot(repo_path: pathlib.Path, templates: jinja2.Environment) -> L
update_schedule: "weekly"
default_reviewers:
- "{templates.globals['username']}"
""")
"""
)

return [".dependabot/config.yml"]

Expand Down
21 changes: 13 additions & 8 deletions repo_helper/ci_cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,20 @@ def no_dev_versions(versions):
ci_platform="windows-2019",
ci_name="Windows Tests",
python_versions=py_versions,
))
)
)
else:
if (dot_github / "workflows" / "python_ci.yml").is_file():
(dot_github / "workflows" / "python_ci.yml").unlink()

if "macOS" in templates.globals["platforms"]:
(dot_github / "workflows" / "python_ci_macos.yml").write_clean(actions.render(
no_dev_versions=no_dev_versions,
ci_platform="macos-latest",
ci_name="macOS Tests",
))
(dot_github / "workflows" / "python_ci_macos.yml").write_clean(
actions.render(
no_dev_versions=no_dev_versions,
ci_platform="macos-latest",
ci_name="macOS Tests",
)
)
else:
if (dot_github / "workflows" / "python_ci_macos.yml").is_file():
(dot_github / "workflows" / "python_ci_macos.yml").unlink()
Expand All @@ -171,7 +174,8 @@ def no_dev_versions(versions):
no_dev_versions=no_dev_versions,
ci_platform="ubuntu-18.04",
ci_name="Linux Tests",
))
)
)
else:
if (dot_github / "workflows" / "python_ci_linux.yml").is_file():
(dot_github / "workflows" / "python_ci_linux.yml").unlink()
Expand Down Expand Up @@ -209,7 +213,8 @@ def make_github_manylinux(repo_path: pathlib.Path, templates: jinja2.Environment
PYVERSIONS.append(f'"3{pyver}"')

(dot_github / "workflows" / "manylinux_build.yml").write_clean(
actions.render(wheel_py_versions=wheel_py_versions, PYVERSIONS=" ".join(PYVERSIONS)))
actions.render(wheel_py_versions=wheel_py_versions, PYVERSIONS=" ".join(PYVERSIONS))
)
else:
if (dot_github / "workflows" / "manylinux_build.yml").is_file():
(dot_github / "workflows" / "manylinux_build.yml").unlink()
Expand Down
30 changes: 19 additions & 11 deletions repo_helper/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ class modname(ConfigVar): # noqa
@staticmethod
def validator(name: str) -> str:
if not name.replace("-", "_").isidentifier():
raise ValueError("""\
'modname' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces.""")
raise ValueError(
"""\
'modname' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces."""
)
return name


Expand Down Expand Up @@ -236,9 +238,11 @@ class repo_name(ConfigVar): # noqa
@staticmethod
def validator(name: str) -> str:
if not name.replace("-", "_").isidentifier():
raise ValueError("""\
raise ValueError(
"""\
'repo_name' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces.""")
It cannot cannot start with a number, or contain any spaces."""
)
return name


Expand All @@ -260,9 +264,11 @@ class pypi_name(ConfigVar): # noqa
@staticmethod
def validator(name: str) -> str:
if not name.replace("-", "_").isidentifier():
raise ValueError("""\
'pypi_name' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces.""")
raise ValueError(
"""\
'pypi_name' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces."""
)
return name


Expand All @@ -285,9 +291,11 @@ class import_name(ConfigVar): # noqa
def validator(name: str) -> str:
name = name.replace("-", "_") # replace hyphens with underscores
if not name.isidentifier():
raise ValueError("""\
'import_name' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces.""")
raise ValueError(
"""\
'import_name' must only contain contains letters, numbers and underscores (_).
It cannot cannot start with a number, or contain any spaces."""
)
return name


Expand Down
7 changes: 3 additions & 4 deletions repo_helper/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ def make_contributing(repo_path: pathlib.Path, templates: jinja2.Environment) ->

contributing = templates.get_template("CONTRIBUTING.rst")

PathPlus(repo_path / "CONTRIBUTING.rst").write_clean(
contributing.render(bash_block=github_bash_block))
PathPlus(repo_path / "CONTRIBUTING.rst").write_clean(contributing.render(bash_block=github_bash_block))

if (repo_path / "CONTRIBUTING.md").is_file():
(repo_path / "CONTRIBUTING.md").unlink()
Expand All @@ -338,7 +337,7 @@ def make_docs_contributing(repo_path: pathlib.Path, templates: jinja2.Environmen

contributing = templates.get_template("CONTRIBUTING.rst")

PathPlus(repo_path / templates.globals["docs_dir"] / "contributing.rst").write_clean(
contributing.render(bash_block=sphinx_bash_block))
PathPlus(repo_path / templates.globals["docs_dir"] / "contributing.rst"
).write_clean(contributing.render(bash_block=sphinx_bash_block))

return [os.path.join(templates.globals["docs_dir"], "contributing.rst")]
12 changes: 8 additions & 4 deletions repo_helper/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def ensure_doc_requirements(repo_path: pathlib.Path, templates: jinja2.Environme
# Requirement("gitpython"),
Requirement("sphinx_autodoc_typehints>=1.11.0"),
Requirement("sphinx-copybutton>=0.2.12"), # https://sphinx-copybutton.readthedocs.io/en/latest/
Requirement("sphinx-prompt>=1.2.0"), # ("git+https://github.com/ScriptAutomate/sphinx-tabs-expanded.git", None)
Requirement("sphinx-prompt>=1.2.0"
), # ("git+https://github.com/ScriptAutomate/sphinx-tabs-expanded.git", None)
}

if templates.globals["sphinx_html_theme"] == "sphinx_rtd_theme":
Expand Down Expand Up @@ -292,7 +293,8 @@ def copy_docs_styling(repo_path: pathlib.Path, templates: jinja2.Environment) ->
html {{
scroll-behavior: smooth;
}}
""")
"""
)

elif templates.globals["sphinx_html_theme"] == "alabaster":
PathPlus(dest__static_dir / "style.css").write_clean(
Expand Down Expand Up @@ -427,15 +429,17 @@ def copy_docs_styling(repo_path: pathlib.Path, templates: jinja2.Environment) ->
font-weight: bold;
}}
""")
"""
)

PathPlus(dest__templates_dir / "layout.html").write_clean(
"""<!--- This file is managed by 'repo_helper'. Don't edit it directly. --->
{% extends "!layout.html" %}
{% block extrahead %}
<link href="{{ pathto("_static/style.css", True) }}" rel="stylesheet" type="text/css">
{% endblock %}
""")
"""
)

if (dest__templates_dir / "footer.html").is_file():
(dest__templates_dir / "footer.html").unlink()
Expand Down
8 changes: 5 additions & 3 deletions repo_helper/init_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def init_repo(repo_path: pathlib.Path, templates: jinja2.Environment) -> List[st
template = init_repo_templates.get_template(filename)
PathPlus(repo_path / templates.globals["docs_dir"] / filename).write_clean(template.render())

with (repo_path / templates.globals["docs_dir"] / "api" / templates.globals["modname"]
).with_suffix(".rst").open('w', encoding="UTF-8") as fp:
with (repo_path / templates.globals["docs_dir"] / "api"
/ templates.globals["modname"]).with_suffix(".rst"
).open('w', encoding="UTF-8") as fp:
buf = '='
buf += '=' * len(templates.globals["import_name"])
buf += f"\n{templates.globals['import_name']}\n="
Expand Down Expand Up @@ -143,7 +144,8 @@ def init_repo(repo_path: pathlib.Path, templates: jinja2.Environment) -> List[st
year=datetime.datetime.today().year,
organization=templates.globals["author"],
project=templates.globals["modname"],
))
)
)

# Touch requirements file
(repo_path / "requirements.txt").touch()
Expand Down
4 changes: 1 addition & 3 deletions repo_helper/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ def make_pylintrc(repo_path: pathlib.Path, templates: jinja2.Environment) -> Lis
:type templates: jinja2.Environment
"""

PathPlus(repo_path / ".pylintrc").write_clean(
PathPlus(template_dir / "pylintrc").read_text(),
)
PathPlus(repo_path / ".pylintrc").write_clean(PathPlus(template_dir / "pylintrc").read_text(), )

return [".pylintrc"]

Expand Down
20 changes: 13 additions & 7 deletions repo_helper/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ def make_manifest(repo_path: pathlib.Path, templates: jinja2.Environment) -> Lis

if templates.globals["stubs_package"]:
manifest_entries.append(
f"recursive-include {templates.globals['source_dir']}{templates.globals['import_name']}-stubs *.pyi")
f"recursive-include {templates.globals['source_dir']}{templates.globals['import_name']}-stubs *.pyi"
)
manifest_entries.append(
f"include {templates.globals['source_dir']}{templates.globals['import_name']}-stubs/py.typed")
f"include {templates.globals['source_dir']}{templates.globals['import_name']}-stubs/py.typed"
)
else:
manifest_entries.append(
f"recursive-include {templates.globals['source_dir']}{templates.globals['import_name'].replace('.', '/')} *.pyi")
f"recursive-include {templates.globals['source_dir']}{templates.globals['import_name'].replace('.', '/')} *.pyi"
)
manifest_entries.append(
f"include {templates.globals['source_dir']}{templates.globals['import_name'].replace('.', '/')}/py.typed")
f"include {templates.globals['source_dir']}{templates.globals['import_name'].replace('.', '/')}/py.typed"
)

PathPlus(repo_path / "MANIFEST.in").write_clean("\n".join(manifest_entries))

Expand Down Expand Up @@ -160,9 +164,11 @@ def make_setup(repo_path: pathlib.Path, templates: jinja2.Environment) -> List[s
with (repo_path / "setup.py").open('w', encoding="UTF-8") as fp:
clean_writer(
setup.render(
additional_setup_args="\n".join(
["\t\t{}={},".format(*x) for x in sorted(data.items())]
) + "\n" + templates.globals["additional_setup_args"]), fp)
additional_setup_args="\n".join(["\t\t{}={},".format(*x) for x in sorted(data.items())])
+ "\n" + templates.globals["additional_setup_args"]
),
fp
)

return ["setup.py"]

Expand Down
2 changes: 1 addition & 1 deletion repo_helper/repo_helper_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@
"short_desc"
],
"additionalProperties": false
}
}
2 changes: 1 addition & 1 deletion repo_helper/templates/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ jobs:
repo: {{ username }}/{{ repo_name }}
provider: script
script: python .ci/copy_pypi_2_github.py || return 1;{% endif %}
{% endif %}
{% endif %}

0 comments on commit 18fee73

Please sign in to comment.