Skip to content

Instantly share code, notes, and snippets.

@qin-yu
Created November 6, 2023 14:22
Show Gist options
  • Select an option

  • Save qin-yu/c0293a935a3fb0009b60ee966d5dbf6c to your computer and use it in GitHub Desktop.

Select an option

Save qin-yu/c0293a935a3fb0009b60ee966d5dbf6c to your computer and use it in GitHub Desktop.

Revisions

  1. qin-yu created this gist Nov 6, 2023.
    46 changes: 46 additions & 0 deletions upload-to-pypi-and-conda.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # Upload Package to PyPI and Conda <!-- omit in toc -->

    - [Publishing to PyPI Manually](#publishing-to-pypi-manually)
    - [Resources](#resources)
    - [Workflow](#workflow)
    - [Contributing to Conda Manually](#contributing-to-conda-manually)
    - [Resources](#resources-1)
    - [Workflow](#workflow-1)

    ## Publishing to PyPI Manually

    ### Resources
    - The official guide for building Python packages from scratch:
    - [Python Packaging User Guide » Tutorials » Packaging Python Projects](https://packaging.python.org/en/latest/tutorials/packaging-projects/)
    - The Python project manager, Hatch, for building and publishing packages:
    - [Hatch: a modern, extensible Python project manager](https://hatch.pypa.io/latest/)

    ### Workflow
    - Create `README.md` in the directory root
    - Create `LICENSE` in the directory root
    - Create `setup.py` in the directory root
    - Put Python modules in a subdirectory, `src` or whatever
    - Put Python tests in a subdirectory, `tests` or whatever
    - Create `__init__.py` in the subdirectory to make it discoverable
    - Initialise the package with Hatch: `hatch new --init`
    - This creates `pyproject.toml`
    - Build the package with Hatch: `hatch build`
    - Before running this `hatch version x.y.z` to set the version number
    - This creates `dist/`
    - Upload the package to PyPI with Hatch: `hatch publish -u __token__ -a TOKEN`
    - the username is `__token__` and the authentication token is created on PyPI

    ## Contributing to Conda Manually

    ### Resources
    - The official guide for building conda packages that are independent of PyPI:
    - [User guide / Tutorials / Building conda packages from scratch](https://docs.conda.io/projects/conda-build/en/latest/user-guide/tutorials/build-pkgs.html)
    - Description of the `meta.yaml` file which is the core of a conda package:
    - [Resources / Defining metadata (meta.yaml)](https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html)

    ### Workflow
    - `conda install conda-build`
    - `conda install anaconda-client`
    - Create `meta.yaml` in a folder named `conda-recipe` or whatever
    - Build the package by `conda build .`
    - Upload the package to Anaconda Cloud by `anaconda upload /g/kreshuk/yu/miniconda3/envs/ENV_NAME/conda-bld/noarch/PACKAGE_NAME-pypy_1.tar.bz2`