Skip to content

Commit

Permalink
Merge pull request #5 from wpk-nist-gov/release/v0.8.0
Browse files Browse the repository at this point in the history
release/v0.8.0
  • Loading branch information
wpk-nist-gov authored Oct 2, 2023
2 parents f976377 + 354558f commit 595a032
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 49 deletions.
16 changes: 5 additions & 11 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"template": "https://github.com/wpk-nist-gov/cookiecutter-pypackage.git",
"commit": "71625a367d3dc20e38fd58c761e10ee671e9a7d2",
"checkout": "feature/nox",
"template": "https://github.com/usnistgov/cookiecutter-nist-python.git",
"commit": "7ba78569cba4c2b39c2706d1f95b74c919b310cf",
"checkout": "develop",
"context": {
"cookiecutter": {
"full_name": "William P. Krekelberg",
Expand All @@ -22,16 +22,10 @@
"changelog.d/templates/auto-changelog/*.jinja2"
],
"project_short_description": "A script to convert a Python project declared on a pyproject.toml to a conda environment.",
"version": "0.0.1",
"use_pytest": "y",
"use_pypi_deployment_with_travis": "n",
"command_line_interface": "Click",
"create_author_file": "y",
"open_source_license": "NIST license",
"sphinx_auto": "automodule",
"command_line_interface": "Typer",
"sphinx_use_autodocsumm": "y",
"sphinx_theme": "sphinx_book_theme",
"_template": "https://github.com/wpk-nist-gov/cookiecutter-pypackage.git"
"_template": "https://github.com/usnistgov/cookiecutter-nist-python.git"
}
},
"directory": null
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ See the fragment files in

<!-- scriv-insert-here -->

## v0.8.0 — 2023-10-02

### Added

- Added option to either raise error, or print message for environments with no
dependencies.

### Changed

- pyproject2conda now works with `pyproject.toml` files with no dependencies.

## v0.7.0 — 2023-09-26

### Added
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,4 @@ cog-readme: ## apply cog to README.md
# Can't seem to convert
.PHONY: README.pdf
README.pdf: ## create README.pdf
pandoc -V colorlinks README.md -o README.pdf
pandoc -V colorlinks -V geometry:margin=0.8in README.md -o README.pdf
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ suggestions!

Use one of the following to install `pyproject2conda`:

<!-- markdownlint-disable MD014 -->

```bash
pip install pyproject2conda
$ pip install pyproject2conda
```

or

```bash
conda install -c conda-forge pyproject2conda
$ conda install -c conda-forge pyproject2conda
```

[rich]: https://github.com/Textualize/rich
Expand All @@ -77,9 +79,11 @@ If using pip, to install with [rich] and [shellingham] support, either install
them your self, or use:

```bash
pip install pyproject2conda[all]
$ pip install pyproject2conda[all]
```

<!-- markdownlint-enable MD014 -->

The conda-forge distribution of [typer] (which `pyproject2conda` uses) installs
[rich] and [shellingham] by default.

Expand Down Expand Up @@ -854,11 +858,10 @@ The author can be reached at <wpk@nist.gov>.

## Credits

This package was created with
[Cookiecutter](https://github.com/audreyr/cookiecutter) and the
[wpk-nist-gov/cookiecutter-pypackage](https://github.com/wpk-nist-gov/cookiecutter-pypackage)
Project template forked from
[audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage).
This package was created using
[Cookiecutter](https://github.com/audreyr/cookiecutter) with the
[usnistgov/cookiecutter-nist-python](https://github.com/usnistgov/cookiecutter-nist-python)
template.

<!-- LocalWords: conda subcommands
-->
4 changes: 3 additions & 1 deletion docs/reference/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# API Reference

## pyproject2conda

```{eval-rst}
.. toctree::
Expand All @@ -9,7 +11,7 @@
Modules
-------
=======
.. currentmodule:: pyproject2conda
Expand Down
14 changes: 11 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ def dist_conda(
if not run and not cmd:
cmd = ["recipe"]

# make directory?
if not (d := Path("./dist-conda")).exists():
d.mkdir()

if cmd:
if "recipe" in cmd:
cmd.append("clean-recipe")
Expand Down Expand Up @@ -952,9 +956,13 @@ def testdist_conda(
log_session=log_session,
)

if not test_no_pytest:
opts = combine_list_str(test_opts)
session.run("pytest", *opts)
_test(
session=session,
run=testdist_conda_run,
test_no_pytest=test_no_pytest,
test_opts=test_opts,
no_cov=True,
)


# ** testdist (pypi)
Expand Down
40 changes: 34 additions & 6 deletions src/pyproject2conda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@
logger = logging.getLogger("pyproject2conda")


# * Settings ------------------------------------------------------------------
# * Settings ---------------------------------------------------------------------------
if "P2C_COLUMNS" in os.environ:
os.environ["COLUMNS"] = os.environ["P2C_COLUMNS"] # pragma: no cover


# * Typer App --------------------------------------------------------------------------


class AliasedGroup(TyperGroup):
"""Provide aliasing for commands"""

def get_command(self, ctx, cmd_name): # type: ignore
def get_command(
self, ctx: click.Context, cmd_name: str
) -> Optional[click.core.Command]:
rv = super().get_command(ctx, cmd_name)
if rv is not None:
return rv
Expand Down Expand Up @@ -296,9 +300,10 @@ class Overwrite(str, Enum):
typer.Option(
"--user-config",
help="""
Additional toml file to supply configuration. This can be used to override/add
environment files for your own use (apart from project env files).
The (default) value `infer` means to infer the configuration from `--filename`.
Additional toml file to supply configuration. This can be used to
override/add environment files for your own use (apart from project env
files). The (default) value `infer` means to infer the configuration
from `--filename`.
""",
),
]
Expand All @@ -318,6 +323,17 @@ class Overwrite(str, Enum):
]


ALLOW_EMPTY_OPTION = typer.Option(
"--allow-empty/--no-allow-empty",
help="""
What to do if there are no package requirements for an environment. The
default (`--no-allow-empty`) is to raise an error if the specification
leads to no requirements. Passing `--allow-empty` will lead to a message
being printed, but no environment file being created.
""",
)


# * Utils ------------------------------------------------------------------------------
def _get_header_cmd(
header: Optional[bool], output: Union[str, Path, None]
Expand Down Expand Up @@ -395,7 +411,13 @@ def wrapped(*args: Any, **kwargs: Any) -> R:

logger.setLevel(level)

return func(*args, **kwargs)
# add error logger to function call
try:
return func(*args, **kwargs)
except Exception as error:
# logger.exception(str(error))
logger.error(str(error))
raise

return wrapped

Expand Down Expand Up @@ -444,6 +466,7 @@ def yaml(
verbose: VERBOSE_CLI = None, # pyright: ignore
deps: DEPS_CLI = None,
reqs: REQS_CLI = None,
allow_empty: Annotated[bool, ALLOW_EMPTY_OPTION] = False,
) -> None:
"""Create yaml file from dependencies and optional-dependencies."""

Expand Down Expand Up @@ -476,6 +499,7 @@ def yaml(
sort=sort,
deps=deps,
reqs=reqs,
allow_empty=allow_empty,
)
if not output:
print(s, end="")
Expand All @@ -495,6 +519,7 @@ def requirements(
overwrite: OVERWRITE_CLI = Overwrite.check,
verbose: VERBOSE_CLI = None, # pyright: ignore
reqs: REQS_CLI = None,
allow_empty: Annotated[bool, ALLOW_EMPTY_OPTION] = False,
) -> None:
"""Create requirements.txt for pip dependencies."""

Expand All @@ -513,6 +538,7 @@ def requirements(
header_cmd=_get_header_cmd(header, output),
sort=sort,
reqs=reqs,
allow_empty=allow_empty,
)
if not output:
print(s, end="")
Expand All @@ -535,6 +561,7 @@ def project(
verbose: VERBOSE_CLI = None,
dry: DRY_CLI = False,
user_config: USER_CONFIG_CLI = "infer",
allow_empty: Annotated[Optional[bool], ALLOW_EMPTY_OPTION] = None,
) -> None:
"""Create multiple environment files from `pyproject.toml` specification."""
from pyproject2conda.config import Config
Expand All @@ -552,6 +579,7 @@ def project(
header=header,
overwrite=overwrite.value,
verbose=verbose,
allow_empty=allow_empty,
):
if dry:
# small header
Expand Down
17 changes: 16 additions & 1 deletion src/pyproject2conda/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ def user_config(self, env_name: str | None = None) -> str | None: # pyright: ig
"""Flag user_config"""
return self._get_value(key="user_config", default=None) # type: ignore

def allow_empty(self, env_name: str | None = None, default: bool = False) -> bool:
return self._get_value( # type: ignore
key="allow_empty", env_name=env_name, default=default
)

def assign_user_config(self, user: Self) -> Self:
"""Assign user_config to self."""
from copy import deepcopy
Expand Down Expand Up @@ -269,6 +274,7 @@ def _iter_yaml(
"deps",
"name",
"channels",
"allow_empty",
]

data = {k: defaults.get(k, getattr(self, k)(env_name)) for k in keys}
Expand Down Expand Up @@ -302,7 +308,16 @@ def _iter_yaml(
def _iter_reqs(
self, env_name: str, **defaults: Any
) -> Iterator[tuple[str, dict[str, Any]]]:
keys = ["extras", "sort", "base", "header", "overwrite", "verbose", "reqs"]
keys = [
"extras",
"sort",
"base",
"header",
"overwrite",
"verbose",
"reqs",
"allow_empty",
]

output, template, _ = self._get_output_and_templates(env_name, **defaults)

Expand Down
Loading

0 comments on commit 595a032

Please sign in to comment.