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]
                          PROJECT

Positional Arguments#

PROJECT

Convert named path as conda package.

Named Arguments#

--output-folder

Folder to write output package(s)

-e, --editable

Build PROJECT as an editable package.

-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

Examples:

Convert a PyPI package 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

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 PyPI 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 PyPI package names (canonicalized, lowercase)

  • Values are dictionaries with at least a conda_name key (string)

  • Optionally can include pypi_name, import_name, and mapping_source keys

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.