Conda package builder for Hatch. Hatch is modern, extensible Python project manager.
Add hatch-conda-build
within the build-system.requires field in your pyproject.toml file.
[build-system]
requires = ["hatchling", "hatch-conda-build"]
build-backend = "hatchling.build"
Additionally conda-build
must be in your current path when running a
hatch build.
hatch-conda-build
uses grayskull to translate the requirements section of your pyproject.toml
, which
specifies dependencies on PyPi, to appropriate conda package names.
The builder plugin defines the conda
target.
To start build process, run hatch build -t conda
:
$ hatch build -t conda
[conda]
...
The ouptut package is written to the dist/conda
directory. This directory is a fully-indexed
conda channel and can be used to install the package.
$ conda install -c ./dist/conda <package-name>
...
Additional builder configuration can be set in the following TOML header.
[tool.hatch.build.targets.conda]
...
Following table contains available customization of builder behavior.
Option | Type | Default | Description |
---|---|---|---|
channels | list[str] | ['conda-forge'] | Channels used for package build and testing |
default_numpy_version | str | None | numpy version, otherwise use conda-build default |
github_action_metadata | bool | false | Include extra metadata into recipe from Github runner environment variables |
When github_action_metadata
is True and the Github runner environment variables are present, the follow metadata is added to the
extra
section of the recipe:
Variable(s) | Field | Value |
---|---|---|
GITHUB_SHA | sha |
${GITHUB_SHA} |
GITHUB_SERVER_URL GITHUB_REPOSITORY |
remote_url |
${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} |
GITHUB_RUN_ID | flow_run_id |
${GITHUB_RUN_ID} |
You can specify recipe metadata keys in following TOML header
[tool.hatch.build.targets.conda.recipe]
...
Recipe metadata is defined in TOML syntax. The metadata is merged using deepmerge with the following strategies
recipe_merger = Merger(
type_strategies=[
(dict, ["merge"]),
(list, ["append"])
],
fallback_strategies=["override"],
type_conflict_strategies=["override"]
)
Most importantly, this will append list values if the key already exists. For example you can use nested key TOML syntax:
[tool.hatch.build.targets.conda.recipe]
requirements.run = ["anaconda-anon-usage"]
test.imports = ["my_package"]
will append the package name anaconda-anon-usage
to the autogenerated run requirements and inject the test
section into the recipe before it is built.
Plugin hatch-conda-build is distributed under the terms of the MIT license.