Skip to content

Commit

Permalink
Fixed noxfile: shlex split does not handle windows backslash characte…
Browse files Browse the repository at this point in the history
…rs well. Wrapping in double quotes everywhere. Also using f-strings everywhere now.
  • Loading branch information
Sylvain MARIE committed Mar 12, 2024
1 parent a0b285e commit 2b65f3d
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def tests(session: PowerSession, coverage, pkg_specs):
# session.run2("conda list", env={"CONDA_PREFIX": str(conda_prefix), "CONDA_DEFAULT_ENV": session.get_session_id()})

# Fail if the assumed python version is not the actual one
session.run2("python ci_tools/check_python_version.py %s" % session.python)
session.run2(f"python ci_tools/check_python_version.py {session.python}")

# check that it can be imported even from a different folder
# Important: do not surround the command into double quotes as in the shell !
Expand All @@ -127,20 +127,21 @@ def tests(session: PowerSession, coverage, pkg_specs):
versions_dct=pkg_specs)

# --coverage + junit html reports
session.run2("coverage run --source src/{pkg_name} "
"-m pytest --cache-clear --junitxml={test_xml} --html={test_html} -v tests/"
"".format(pkg_name=pkg_name, test_xml=Folders.test_xml, test_html=Folders.test_html))
session.run2(f"coverage run --source src/{pkg_name} "
f"-m pytest --cache-clear "
f'--junitxml="{Folders.test_xml}" --html="{Folders.test_html}" '
f"-v tests/")
session.run2("coverage report")
session.run2("coverage xml -o {covxml}".format(covxml=Folders.coverage_xml))
session.run2("coverage html -d {dst}".format(dst=Folders.coverage_reports))
session.run2(f'coverage xml -o "{Folders.coverage_xml}"')
session.run2(f'coverage html -d "{Folders.coverage_reports}"')
# delete this intermediate file, it is not needed anymore
rm_file(Folders.coverage_intermediate_file)

# --generates the badge for the test results and fail build if less than x% tests pass
nox_logger.info("Generating badge for tests coverage")
# Use our own package to generate the badge
session.run2("genbadge tests -i %s -o %s -t 100" % (Folders.test_xml, Folders.test_badge))
session.run2("genbadge coverage -i %s -o %s" % (Folders.coverage_xml, Folders.coverage_badge))
session.run2(f'genbadge tests -i "{Folders.test_xml}" -o "{Folders.test_badge}" -t 100')
session.run2(f'genbadge coverage -i "{Folders.coverage_xml}" -o "{Folders.coverage_badge}"')


@power_session(python=PY39, logsdir=Folders.runlogs)
Expand All @@ -160,21 +161,21 @@ def flake8(session: PowerSession):
session.run("flake8", pkg_name, "--exit-zero", "--format=html", "--htmldir", str(Folders.flake8_reports),
"--statistics", "--tee", "--output-file", str(Folders.flake8_intermediate_file))
# generate our badge
session.run2("genbadge flake8 -i %s -o %s" % (Folders.flake8_intermediate_file, Folders.flake8_badge))
session.run2(f'genbadge flake8 -i "{Folders.flake8_intermediate_file}" -o "{Folders.flake8_badge}"')
rm_file(Folders.flake8_intermediate_file)


@power_session(python=[PY39])
def docs(session: PowerSession):
"""Generates the doc and serves it on a local http server. Pass '-- build' to build statically instead."""
"""Generates the doc. Pass '-- serve' to serve it on a local http server instead."""

session.install_reqs(phase="docs", phase_reqs=["mkdocs-material", "mkdocs", "pymdown-extensions", "pygments"])

if session.posargs:
# use posargs instead of "serve"
# use posargs instead of "build"
session.run2("mkdocs %s" % " ".join(session.posargs))
else:
session.run2("mkdocs serve")
session.run2("mkdocs build")


@power_session(python=[PY39])
Expand Down Expand Up @@ -251,10 +252,9 @@ def my_scheme(version_):

# create the github release
session.install_reqs(phase="release", phase_reqs=["click", "PyGithub"])
session.run2("python ci_tools/github_release.py -s {gh_token} "
"--repo-slug {gh_org}/{gh_repo} -cf ./docs/changelog.md "
"-d https://{gh_org}.github.io/{gh_repo}/changelog {tag}"
"".format(gh_token=gh_token, gh_org=gh_org, gh_repo=gh_repo, tag=current_tag))
session.run2(f"python ci_tools/github_release.py -s {gh_token} "
f"--repo-slug {gh_org}/{gh_repo} -cf ./docs/changelog.md "
f"-d https://{gh_org}.github.io/{gh_repo}/changelog {current_tag}")


@nox.session(python=False)
Expand Down Expand Up @@ -283,15 +283,15 @@ def gha_list(session):
session_func.parametrize
except AttributeError:
if additional_args.with_version:
sessions_list = [{"python": py, "session": "%s-%s" % (session_func.__name__, py)} for py in session_func.python]
sessions_list = [{"python": py, "session": f"{session_func.__name__}-{py}"} for py in session_func.python]
else:
sessions_list = ["%s-%s" % (session_func.__name__, py) for py in session_func.python]
sessions_list = [f"{session_func.__name__}-{py}" for py in session_func.python]
else:
if additional_args.with_version:
sessions_list = [{"python": py, "session": "%s-%s(%s)" % (session_func.__name__, py, param)}
sessions_list = [{"python": py, "session": f"{session_func.__name__}-{py}({param})"}
for py, param in product(session_func.python, session_func.parametrize)]
else:
sessions_list = ["%s-%s(%s)" % (session_func.__name__, py, param)
sessions_list = [f"{session_func.__name__}-{py}({param})"
for py, param in product(session_func.python, session_func.parametrize)]

# print the list so that it can be caught by GHA.
Expand Down

0 comments on commit 2b65f3d

Please sign in to comment.