简体   繁体   中英

conda build how to use subpackages

I'm trying to build my python package with conda and I'm having some trouble.

The package is basically two subpackages and at the moment, it works fine if installed with python using setuptools. I can easily call the subpackages with:

python -m my_package.the_subpackage

My real question is first of all, what do I have to do to differently with conda build for this to translate to my conda package.

And secondly, how do I call my subpackages assuming it get installed with conda? Is it the same, or is it my_package the_subpackage or something similar?

Thanks in advance for any help!

If I understood right, your first question is how to create conda packages for python if you already have setup.py. The answer is pretty common, just google it. One helpful reference: https://docs.conda.io/projects/conda-build/en/latest/user-guide/tutorials/build-pkgs.html

Very short (and not necessarily generic way) is:

conda install conda-build
mkdir conda-recipe && pushd conda-recipe
echo "python setup.py install --single-version-externally-managed" > build.sh
touch meta.yaml # populate meta.yaml with proper config. Something to start with: https://docs.conda.io/projects/conda-build/en/latest/_downloads/d42b166defebcb482accb83c6edec8c9/meta.yaml

# with <CWD> being your current working directory.
popd && conda-build <CWD>/conda-recipe -croot build --output-folder <CWD>/dist/conda 

For the second question, consulting https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#implicit-metapackages , one way is to define different subpackages via the outputs configuration.

Rough config for your case:

package:
  name: my_package

requirements:
  host: 
   - python
  run:
    - my_package-the_subpackage1
    - my_package-the_subpackage2

outputs:
  - name: my_package.the_subpackage1
    requirements:
      - some-dep
    script: some_build_script.sh
  - name: my_package.the_subpackage2
    requirements:
      - some-other-dep
    script: some_other_build_script.sh

this will create 3 pacakges (2 subpackages and a parent meta package having dependency on the subpackages. to install them, you can do:

conda install my_package to get the whole thing or

conda install my_package.the_subpackage1 to only install the first subpackage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM