Skip to content

Commit

Permalink
chore: update cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
wpk committed Jun 14, 2023
1 parent 6e1bf56 commit 6b6102e
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/wpk-nist-gov/cookiecutter-pypackage.git",
"commit": "2bd65646cebcc09c4ffbecd4915d3c3ae4a6830a",
"commit": "971a85c7f1441446253a4bd7e955efeb9013754b",
"checkout": "feature/nox",
"context": {
"cookiecutter": {
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pip install noxopt
Ready to contribute? Here's how to set up `module-utilities` for local
development.

- Fork the `module=utilities` repo on GitHub.
- Fork the `module-utilities` repo on GitHub.

- Clone your fork locally:

Expand Down
9 changes: 9 additions & 0 deletions environment/test-extras.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# This file is autogenerated by pyrpoject2conda.
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
#
pytest
pytest-xdist
pytest-cov
pytest-sugar
13 changes: 13 additions & 0 deletions environment/test-extras.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# This file is autogenerated by pyrpoject2conda.
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
#
channels:
- conda-forge
dependencies:
- python>=3.8
- pytest
- pytest-xdist
- pytest-cov
- pytest-sugar
89 changes: 81 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def run_annotated(**kwargs):

LOCK_CLI = Annotated[bool, LOCK_OPT]
RUN_CLI = Annotated[list[list[str]], RUN_OPT]
TEST_OPTS_CLI = opts_annotated(help="extra arguments/flags to pytest")
TEST_OPTS_CLI = opts_annotated(help="extra arguments/flags to pytest") # type: ignore

# CMD_CLI = Annotated[list[str], CMD_OPT]

Expand Down Expand Up @@ -273,7 +273,7 @@ def pyproject2conda(
force_reinstall=force_reinstall,
)

def create_env(output, extras=None, python="get", base=True):
def create_env(output, extras=None, python="get", base=True, cmd="yaml"):
def _to_args(flag, val):
if val is None:
return []
Expand All @@ -282,9 +282,9 @@ def _to_args(flag, val):
return prepend_flag(flag, val)

if pyproject2conda_force or update_target(output, "pyproject.toml"):
args = ["yaml", "-o", output] + _to_args("-e", extras)
args = [cmd, "-o", output] + _to_args("-e", extras)

if python:
if python and cmd == "yaml":
args.extend(["--python-include", python])

if not base:
Expand All @@ -307,6 +307,12 @@ def _to_args(flag, val):
for k in ["dist-pypi", "dist-conda"]:
create_env(f"environment/{k}.yaml", extras=k, base=False)

# need an isolated set of test requirements
create_env("environment/test-extras.yaml", extras="test", base=False)
create_env(
"environment/test-extras.txt", extras="test", base=False, cmd="requirements"
)


@DEFAULT_SESSION
def conda_lock(
Expand Down Expand Up @@ -638,13 +644,21 @@ def dist_conda(
session: nox.Session,
dist_conda_run: RUN_CLI = [], # noqa
dist_conda_cmd: cmd_annotated( # type: ignore
choices=["recipe", "build", "clean", "clean-recipe", "clean-build"],
choices=[
"recipe",
"build",
"clean",
"clean-recipe",
"clean-build",
"recipe-cat-full",
],
flags=("--dist-conda-cmd", "-c"),
) = (),
lock: LOCK_CLI = False,
sdist_path: str = "",
force_reinstall: FORCE_REINSTALL_CLI = False,
log_session: bool = False,
version: VERSION_CLI = "",
):
"""Runs make -C dist-conda posargs"""
install_requirements(
Expand All @@ -670,16 +684,21 @@ def dist_conda(
cmd.extend(["clean-recipe", "clean-build"])
cmd.remove("clean")

cmd = sort_like(cmd, ["clean-recipe", "recipe", "clean-build", "build"])
cmd = sort_like(
cmd, ["recipe-cat-full", "clean-recipe", "recipe", "clean-build", "build"]
)

if not sdist_path:
sdist_path = PACKAGE_NAME
if version:
sdist_path = f"{sdist_path}=={version}"

for command in cmd:
if command == "clean-recipe":
session.run("rm", "-rf", f"dist-conda/{PACKAGE_NAME}", external=True)
elif command == "clean-build":
session.run("rm", "-rf", "dist-conda/build", external=True)
elif command == "recipe":
if sdist_path is None:
sdist_path = PACKAGE_NAME
session.run(
"grayskull",
"pypi",
Expand All @@ -698,6 +717,20 @@ def dist_conda(
session.run(
"cat", f"dist-conda/{PACKAGE_NAME}/meta.yaml", external=True
)
elif command == "recipe-cat-full":
import tempfile

with tempfile.TemporaryDirectory() as d:
session.run(
"grayskull",
"pypi",
sdist_path,
"-o",
d,
)
session.run(
"cat", str(Path(d) / PACKAGE_NAME / "meta.yaml"), external=True
)

elif command == "build":
session.run(
Expand Down Expand Up @@ -837,6 +870,46 @@ def testdist_pypi(
session.run("pytest", *opts)


@group.session(python=PYTHON_ALL_VERSIONS) # type: ignore
def testdist_pypi_venv(
session: Session,
test_no_pytest: bool = False,
test_opts: TEST_OPTS_CLI = (), # type: ignore
testdist_pypi_run: RUN_CLI = [], # noqa
testdist_pypi_extras: cmd_annotated(help="extras to install") = (), # type: ignore
force_reinstall: FORCE_REINSTALL_CLI = False,
version: VERSION_CLI = "",
log_session: bool = False,
):
"""Test pypi distribution"""
extras = testdist_pypi_extras
install_str = PACKAGE_NAME

if extras:
install_str = "{}[{}]".format(install_str, ",".join(extras))

if version:
install_str = f"{install_str}=={version}"

install_requirements(
session=session,
name="testdist-pypi-venv",
set_kernel=False,
install_package=False,
force_reinstall=force_reinstall,
style="pip",
reqs=["-r", "environment/test-extras.txt", install_str],
)

if log_session:
session_log_session(session, False)

session_run_commands(session, testdist_pypi_run)
if not test_no_pytest:
opts = combine_list_str(test_opts)
session.run("pytest", *opts)


# --- Utilities ------------------------------------------------------------------------
def _create_doc_examples_symlinks(session, clean=True):
"""Create symlinks from docs/examples/*.md files to /examples/usage/..."""
Expand Down

0 comments on commit 6b6102e

Please sign in to comment.