Skip to content

Commit

Permalink
build(workflow): add default database prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Burling committed Jul 15, 2022
1 parent bf5ef89 commit 28668d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:

# run black code formatter on python files
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.6.0
hooks:
- id: black
args:
Expand Down
52 changes: 24 additions & 28 deletions datajoint-workflow/{{cookiecutter.github_repo}}/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
"""Nox sessions.
- https://nox.thea.codes/en/stable/tutorial.html
Expand All @@ -17,13 +18,13 @@
nox.options.pythons = [default_python_version]


def install_dependencies(session: nox.Session, *extras: str) -> None:
def install_dependencies(session, *extras):
session.install("setuptools>=62.0", "wheel>=0.37")
extras = extras or ("test",)
session.run("pip", "install", f".[{','.join(extras)}]")


def parse_session_posargs(args: list[str]) -> argparse.Namespace:
def parse_session_posargs(args):
class SplitCSA(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if values:
Expand Down Expand Up @@ -65,16 +66,11 @@ def __call__(self, parser, namespace, values, option_string=None):
help="Flag to force exception on failed session run.",
action="store_true",
)
parsed_args: argparse.Namespace = parser.parse_args(args)
parsed_args = parser.parse_args(args)
return parsed_args


def git_action_bot(
session: nox.Session,
add: list[str] = None,
commit: list[str] = None,
push: list[str] = None,
) -> None:
def git_action_bot(session, add=None, commit=None, push=None):
session.log("Configuring git user and email.")
session.run(
"git", "config", "--local", "user.name", "github-actions[bot]", external=True
Expand Down Expand Up @@ -102,7 +98,7 @@ def git_action_bot(


@nox.session(python=default_python_version, reuse_venv=True)
def main_cli(session: nox.Session) -> None:
def main_cli(session):
"""Install all dependencies then run package main cli with arg '--version'.
nox -s main_cli
Expand All @@ -113,15 +109,15 @@ def main_cli(session: nox.Session) -> None:


@nox.session(python=default_python_version, reuse_venv=True)
def write_version(session: nox.Session) -> None:
def write_version(session):
"""Bump version.py to the latest version.
nox -s write_version -- --version 0.0.1
"""

args: argparse.Namespace = parse_session_posargs(session.posargs)
version: str = args.version.pop()
prev_ver: str = args.prev_ver.pop()
args = parse_session_posargs(session.posargs)
version = args.version.pop()
prev_ver = args.prev_ver.pop()

if version == prev_ver:
session.log(f"Skipping overwriting 'version.py' to '{version}'")
Expand All @@ -136,15 +132,15 @@ def write_version(session: nox.Session) -> None:


@nox.session(python=default_python_version, reuse_venv=True)
def pre_commit(session: nox.Session) -> None:
def pre_commit(session):
"""Run pre-commit.
nox -s pre_commit -- --pre-commit-hooks=black,isort --fail
"""

args: argparse.Namespace = parse_session_posargs(session.posargs)
hooks: list[str] = args.pre_commit_hooks
raise_exception: bool = args.fail
args = parse_session_posargs(session.posargs)
hooks = args.pre_commit_hooks
raise_exception = args.fail

install_dependencies(session, "dev")
session.run("pre-commit", "install")
Expand All @@ -165,18 +161,18 @@ def pre_commit(session: nox.Session) -> None:
os.remove(log_file)

if failed_hooks:
failed_str = "Failed pre-commit hooks:"
failed_str += "".join(
failed_str = "Failed pre-commit hooks:" + "".join(
[f"\n::{hk}\n\n{txt}\n" for hk, txt in failed_hooks.items()]
)

if raise_exception:
session.error(failed_str)
else:
session.log(failed_str)


@nox.session(python=nox.options.pythons)
def pytest(session: nox.Session) -> None:
def pytest(session):
"""Run tests using pytest.
nox -s pytest
Expand All @@ -188,18 +184,18 @@ def pytest(session: nox.Session) -> None:


@nox.session(python=default_python_version, reuse_venv=True)
def docs(session: nox.Session) -> None:
def docs(session):
"""Build the latest documentation w/ mkdocs and mike.
nox -s docs -- --version v0.0
"""

args: argparse.Namespace = parse_session_posargs(session.posargs)
docs_version: str = args.version.pop()
docs_alias: str = "latest"
index_html: bool = args.index_html
args = parse_session_posargs(session.posargs)
docs_version = args.version.pop()
docs_alias = "latest"
index_html = args.index_html

ver_regex: re.Pattern = re.compile(
ver_regex = re.compile(
r"^(?P<tag>v?)"
r"(?P<major>[0-9]+)\."
r"(?P<minor>[0-9]+)\."
Expand Down Expand Up @@ -235,7 +231,7 @@ def docs(session: nox.Session) -> None:


@nox.session(python=default_python_version, reuse_venv=True)
def docs_no_ver(session: nox.Session) -> None:
def docs_no_ver(session):
"""Build the documentation w/ mkdocs.
nox -s docs_no_ver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"enable_python_native_blobs": true,
"fetch_format": "array",
"loglevel": "WARNING",
"safemode": true
"safemode": true,
"custom": {
"database.prefix": "{{cookiecutter.github_repo}}"
}
}

0 comments on commit 28668d5

Please sign in to comment.