Skip to content

Commit

Permalink
Merge branch 'release/v0.19.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wpk-nist-gov committed Jan 29, 2025
2 parents 4417af8 + 1a5172b commit 77470c2
Show file tree
Hide file tree
Showing 29 changed files with 308 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/usnistgov/cookiecutter-nist-python.git",
"commit": "97f9ecc1229823fe6a0e8a4750432d7ec4e2efc2",
"commit": "8abac57f08c85e44e62cd1bd861c83964e347be4",
"checkout": "develop",
"context": {
"cookiecutter": {
Expand All @@ -19,7 +19,7 @@
"__answers": "",
"_copy_without_render": [],
"_template": "https://github.com/usnistgov/cookiecutter-nist-python.git",
"_commit": "97f9ecc1229823fe6a0e8a4750432d7ec4e2efc2"
"_commit": "8abac57f08c85e44e62cd1bd861c83964e347be4"
}
},
"directory": null
Expand Down
23 changes: 21 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,29 @@ repos:
# * uv
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.23
rev: 0.5.24
hooks:
- id: uv-lock
args: [--locked]
alias: lock

# * pyproject2conda
- repo: .
rev: 81c58172112987cdf6025ab13b9951e12cb8931e
hooks:
- id: pyproject2conda-project
alias: requirements

# * all lock files
- repo: local
hooks:
- id: requirements-lock
name: requirements-lock
alias: lock
entry: nox -s lock -- ++lock-force
language: python
files: ^requirements/.*\.txt$
pass_filenames: false
additional_dependencies: ["nox==2024.10.9"]

# * Manual Linting ------------------------------------------------------------
- repo: https://github.com/asottile/pyupgrade
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- id: pyproject2conda-project
name: pyproject2conda-project
description:
"Automatically run 'pyproject2conda project' on project dependencies"
entry: pyproject2conda project
language: python
files: ^pyproject\.toml$
args: ["--overwrite=force", "--verbose"]
pass_filenames: false
additional_dependencies: []
minimum_pre_commit_version: "2.9.2"
- id: pyproject2conda-yaml
name: pyproject2conda-yaml
description:
"Automatically run 'pyproject2conda yaml' on project dependencies"
entry: pyproject2conda yaml
language: python
files: ^pyproject\.toml$
args: ["--group=dev", "--output=environment.yaml"]
pass_filenames: false
additional_dependencies: []
minimum_pre_commit_version: "2.9.2"
- id: pyproject2conda-requirements
name: pyproject2conda-requirements
description:
"Automatically run 'pyproject2conda yaml' on project dependencies"
entry: pyproject2conda requirements
language: python
files: ^pyproject\.toml$
args: ["--group=dev", "--output=requirements-dev.in"]
pass_filenames: false
additional_dependencies: []
minimum_pre_commit_version: "2.9.2"
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ See the fragment files in [changelog.d]

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

## v0.19.0 — 2025-01-29

### Added

- Added pre-commit hooks `pyproject2conda-project`, `pyproject2conda-yaml`, and
`pyproject2conda-requirements`.

### Changed

- Changed default of `--overwrite` to `force`. This simplifies using with
`pre-commit`.
- `--commit-command` defaults to `pre-commit` when run under pre-commit

## v0.18.0 — 2025-01-24

### Added
Expand Down
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
[conda-link]: https://anaconda.org/conda-forge/pyproject2conda
[license-badge]: https://img.shields.io/pypi/l/cmomy?color=informational
[license-link]: https://github.com/usnistgov/pyproject2conda/blob/main/LICENSE
[pre-commit]: https://pre-commit.com/

<!-- other links -->

Expand All @@ -44,15 +45,49 @@ use poetry, I'd highly recommend [poetry2conda].

## Features

- Simple comment based syntax to add information to dependencies when creating
`environment.yaml`
- Automatic creation of `environment.yaml`and `requirements.txt` files from
`pyproject.toml`.
- Simple remapping of `pypi` package name to `conda` package name when creating
`environment.yaml` files.
- [pre-commit] hooks to automatically keep dependency files up to data.

## Status

This package is actively used by the author, but is still very much a work in
progress. Please feel free to create a pull request for wanted features and
suggestions!

## Pre-commit hooks

`pyproject2conda` works with [pre-commit]. Hooks are available for the
`project`, `yaml`, and `requirements` subcommands described below:

```yaml
- repo: https://github.com/usnistgov/pyproject2conda
rev: { version } # replace with current version
hooks:
- id: pyproject2conda-project
- id: pyproject2conda-yaml
- id: pyproject2conda-requirements
```
For `yaml` and `requirements`, you can override the default behavior (of
creating environment/requirement files from the `dependency-group` `dev`) by
passing in `args`. For example, you could use the following to create an
environment file with the extra `dev-complete`

```yaml
- repo: https://github.com/usnistgov/pyproject2conda
rev: { version } # replace with current version
hooks:
- id: pyproject2conda-yaml
args: ["-e", "dev-complete", "-o", "environment-dev.yaml", "-w", "force"]
```

Note that if called from pre-commit (detected by the presence of `PRE_COMMIT`
environment variable), the default is to set `--custom-command="pre-commit"`.
You can explicitly pass in `--custom-command` to override this.

## Quick start

<!-- start-installation -->
Expand Down Expand Up @@ -287,9 +322,11 @@ dependencies:
<!-- [[[end]]] -->

Passing `--python="default"` will extract the python version from
`.python-version` file. Passign `--python` value `"lowest"` or `"highest"` will
`.python-version` file. Passing `--python` value `"lowest"` or `"highest"` will
extract the lowest or highest python version, respectively, from the
`project.classifiers` table of the `pyproject.toml` file.
`project.classifiers` table of the `pyproject.toml` file. Using the option
`python="all"` in `pyproject.toml` will include all python versions in the
`project.classifiers` table.

### Adding extra conda dependencies and pip requirements

Expand Down Expand Up @@ -507,6 +544,8 @@ dependencies:

<!-- [[[end]]] -->

You can customize the command in the header with the `--custom-command` option.

### Usage within python

`pyproject2conda` can also be used within python:
Expand Down
6 changes: 1 addition & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,8 @@ def _get_ipython_savefig_dir() -> str:
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
"numpy": ("https://numpy.org/doc/stable", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"numba": ("https://numba.pydata.org/numba-doc/latest", None),
# "matplotlib": ("https://matplotlib.org", None),
"numba": ("https://numba.readthedocs.io/en/stable/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"dask": ("https://docs.dask.org/en/latest", None),
"cftime": ("https://unidata.github.io/cftime", None),
"sparse": ("https://sparse.pydata.org/en/latest/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
}

Expand Down
12 changes: 5 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class SessionParams(DataclassParser):
)

# requirements
requirements_force: bool = False
requirements_no_notify: bool = add_option(
default=False,
help="Skip notification of lock-compile",
Expand Down Expand Up @@ -447,13 +446,12 @@ def requirements(
These will be placed in the directory "./requirements".
"""
uvxrun.run(
"pyproject2conda",
"project",
"--verbose",
*(["--overwrite=force"] if opts.requirements_force else []),
session=session,
external=True,
"pre-commit",
"run",
"pyproject2conda-project",
"--all-files", # "--show-diff-on-failure",
specs=get_uvxrun_specs(),
session=session,
)

if not opts.requirements_no_notify:
Expand Down
9 changes: 2 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ reqs = [
"grayskull>=2.5.3",
"nbqa>=1.8.4",
"pre-commit",
"pyproject2conda>=0.16.0",
"pyright>=1.1.391",
"pyproject2conda>=0.18.0",
"pyright>=1.1.392",
"scriv",
"twine>=5.0.0",
]
Expand All @@ -432,11 +432,6 @@ required-version = ">=0.5.21"
[tool.uv.pip]
annotation-style = "line"

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/"
publish-url = "https://test.pypi.org/legacy/"

# * Other tools ----------------------------------------------------------------

[tool.scriv]
Expand Down
24 changes: 12 additions & 12 deletions requirements/lock/py312-uvxrun-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ asttokens==3.0.0 \
--hash=sha256:0dcd8baa8d62b0c1d118b399b2ddba3c4aff271d0d7a9e0d4c1681c79035bbc7 \
--hash=sha256:e3078351a059199dd5138cb1c706e6430c05eff2ff136af5eb4790f9d28932e2
# via stack-data
attrs==24.3.0 \
--hash=sha256:8f5c07333d543103541ba7be0e2ce16eeee8130cb0b3f9238ab904ce1e85baff \
--hash=sha256:ac96cd038792094f438ad1f6ff80837353805ac950cd2aa0e0625ef19850c308
attrs==25.1.0 \
--hash=sha256:1c97078a80c814273a76b2a298a932eb681c87415c11dee0a6921de7f1b02c3e \
--hash=sha256:c75a69e28a550a7e93789579c22aa26b0f5b83b75dc4e08fe092980051e1090a
# via scriv
autopep8==2.3.2 \
--hash=sha256:89440a4f969197b69a995e4ce0661b031f455a9f776d2c5ba3dbd83466931758 \
Expand Down Expand Up @@ -587,9 +587,9 @@ pexpect==4.9.0 ; sys_platform != 'emscripten' and sys_platform != 'win32' \
--hash=sha256:7236d1e080e4936be2dc3e326cec0af72acf9212a7e1d060210e70a47e253523 \
--hash=sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f
# via ipython
pip==24.3.1 \
--hash=sha256:3790624780082365f47549d032f3770eeb2b1e8bd1f7b2e02dace1afa361b4ed \
--hash=sha256:ebcb60557f2aefabc2e0f918751cd24ea0d56d8ec5445fe1807f1d2109660b99
pip==25.0 \
--hash=sha256:8e0a97f7b4c47ae4a494560da84775e9e2f671d415d8d828e052efefb206b30b \
--hash=sha256:b6eb97a803356a52b2dd4bb73ba9e65b2ba16caa6bcb25a7497350a4e5859b65
# via grayskull
pkginfo==1.12.0 \
--hash=sha256:8ad91a0445a036782b9366ef8b8c2c50291f83a553478ba8580c73d3215700cf \
Expand Down Expand Up @@ -741,13 +741,13 @@ pylev==1.4.0 \
--hash=sha256:7b2e2aa7b00e05bb3f7650eb506fc89f474f70493271a35c242d9a92188ad3dd \
--hash=sha256:9e77e941042ad3a4cc305dcdf2b2dec1aec2fbe3dd9015d2698ad02b173006d1
# via clikit
pyproject2conda==0.17.0 \
--hash=sha256:56706d5072c1966226103595d5604ab750b2779abf1d2c45e3a5dfa52f3c9593 \
--hash=sha256:e1abc3a3ac1e8df47d5226b74dea883f877cc023ee48b7cd2111f9574c91f110
pyproject2conda==0.18.0 \
--hash=sha256:32bc0d806ad4046a9c7b331ba3840a249641a7165e61b0291a6000e129eb9823 \
--hash=sha256:f969e5b4d07b96bd419f329aa24fe601061a625f62f3622b2dcbca1138b9c4af
# via -r requirements/uvxrun-tools.txt
pyright==1.1.392.post0 \
--hash=sha256:252f84458a46fa2f0fd4e2f91fc74f50b9ca52c757062e93f6c250c0d8329eb2 \
--hash=sha256:3b7f88de74a28dcfa90c7d90c782b6569a48c2be5f9d4add38472bdaac247ebd
pyright==1.1.393 \
--hash=sha256:8320629bb7a44ca90944ba599390162bf59307f3d9fb6e27da3b7011b8c17ae5 \
--hash=sha256:aeeb7ff4e0364775ef416a80111613f91a05c8e01e58ecfefc370ca0db7aed9c
# via -r requirements/uvxrun-tools.txt
python-utils==3.9.1 \
--hash=sha256:0273d7363c7ad4b70999b2791d5ba6b55333d6f7a4e4c8b6b39fb82b5fab4613 \
Expand Down
2 changes: 1 addition & 1 deletion requirements/lock/py312-uvxrun-tools.txt.hash.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"../uvxrun-tools.txt": "70df4b9e65f5870c9252765006c8bddf"
"../uvxrun-tools.txt": "590c2644a1ca41ffa45318a1b1d00384"
}
2 changes: 1 addition & 1 deletion requirements/py310-test-extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py310-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py311-test-extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py311-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py312-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py312-test-extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py312-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py313-test-extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py313-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py38-test-extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
2 changes: 1 addition & 1 deletion requirements/py38-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pyproject2conda
# with the following command:
#
# $ pyproject2conda project --verbose
# $ pre-commit
#
# You should not manually edit this file.
# Instead edit the corresponding pyproject.toml file.
Expand Down
Loading

0 comments on commit 77470c2

Please sign in to comment.