conda pypi convert#
Build and convert local Python sdists, wheels or projects to conda packages
usage: conda pypi convert [-h] [--output-folder OUTPUT_FOLDER] [-e]
[-t TEST_DIR] [--name-mapping NAME_MAPPING]
[--build-number BUILD_NUMBER]
PROJECT
Positional Arguments#
- PROJECT
Convert named path as conda package.
Named Arguments#
- --output-folder
Folder to write output package(s)
- -e, --editable
Build an editable package linking PROJECT to the target conda environment when installed.
- -t, --test-dir
Directory containing test files to inject into the conda package. Must be structured as a conda test directory for the tests to work.
- --name-mapping
Path to json file containing pypi to conda name mapping
- --build-number
Build number for the converted package. Defaults to the leading digits of the wheel filename build tag, or 0 if absent.
Examples:
Convert a local wheel to conda format without installing:
conda pypi convert ./requests-2.32.5-py3-none-any.whl
Convert a local Python project to conda package:
conda pypi convert ./my-python-project
Convert a package and save to a specific output folder:
conda pypi convert --output-folder ./conda-packages ./numpy-2.3.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Override the conda build number:
conda pypi convert --build-number 2 ./requests-2.32.5-py3-none-any.whl
Convert a local Python project to an editable package:
conda pypi convert -e . --output-folder ./conda-packages
Convert a package from a Git repository:
git clone https://github.com/user/repo.git
conda pypi convert ./repo
Convert a package and inject test files:
conda pypi convert --test-dir ./my-tests-dir ./my-python-project
Custom Name Mapping#
The --name-mapping option allows you to provide a custom JSON file that maps
Python distribution package names to conda package names. This is useful when you need to
replace the built-in grayskull mapping with your own mapping file.
When --name-mapping is provided, the built-in mapping is not used for that
conversion. The JSON file is treated as the complete mapping source.
The mapping file should be a JSON object where:
Keys are Python distribution package names (canonicalized, lowercase)
Values are dictionaries with at least a
conda_namekey (string)Optionally can include
pypi_name,import_name, andmapping_sourcekeys
Example mapping file (mapping.json):
{
"requests": {
"pypi_name": "requests",
"conda_name": "requests",
"import_name": "requests",
"mapping_source": "custom"
},
"my-package": {
"conda_name": "my-package-conda"
}
}
Usage example:
conda pypi convert --name-mapping ./mapping.json ./my-package-1.0.0-py3-none-any.whl
The mapping will be used during conversion to determine the conda package name for dependencies and the main package being converted.
Build Number#
When converting a wheel, the conda build_number is taken from the optional
PEP 427 build tag in the wheel filename (leading digits only). If the filename
has no build tag, the build number defaults to 0. Use --build-number to
override that value:
conda pypi convert --build-number 2 ./my-package-1.0.0-py3-none-any.whl