From 6b6102e05f3b21ba2c302460cb4552e73fe50ab5 Mon Sep 17 00:00:00 2001 From: wpk Date: Wed, 14 Jun 2023 16:11:04 -0400 Subject: [PATCH] chore: update cruft --- .cruft.json | 2 +- CONTRIBUTING.md | 2 +- environment/test-extras.txt | 9 ++++ environment/test-extras.yaml | 13 ++++++ noxfile.py | 89 ++++++++++++++++++++++++++++++++---- 5 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 environment/test-extras.txt create mode 100644 environment/test-extras.yaml diff --git a/.cruft.json b/.cruft.json index cb5f2e8..a83db2d 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/wpk-nist-gov/cookiecutter-pypackage.git", - "commit": "2bd65646cebcc09c4ffbecd4915d3c3ae4a6830a", + "commit": "971a85c7f1441446253a4bd7e955efeb9013754b", "checkout": "feature/nox", "context": { "cookiecutter": { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 968b5bb..f4a90e1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: diff --git a/environment/test-extras.txt b/environment/test-extras.txt new file mode 100644 index 0000000..41f5872 --- /dev/null +++ b/environment/test-extras.txt @@ -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 diff --git a/environment/test-extras.yaml b/environment/test-extras.yaml new file mode 100644 index 0000000..aead314 --- /dev/null +++ b/environment/test-extras.yaml @@ -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 diff --git a/noxfile.py b/noxfile.py index 9c3e528..e7fd450 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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] @@ -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 [] @@ -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: @@ -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( @@ -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( @@ -670,7 +684,14 @@ 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": @@ -678,8 +699,6 @@ def dist_conda( 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", @@ -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( @@ -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/..."""