Skip to content

Latest commit

 

History

History
214 lines (155 loc) · 5.66 KB

.deployment-instructions.md

File metadata and controls

214 lines (155 loc) · 5.66 KB

Deploying Python Packages


Pypi Deployment


Uploading a package to PyPI

The link in this tutorial will explain the steps to upload a package to pypi: https://dzone.com/articles/executable-package-pip-install

Use Github Actions to deploy

  1. Create an API token to authenticate with PyPI:

    • In your Pypi account settings, go to API tokens section and select "Add API token"

    • Add the token to the Github Actions Secret.

  2. Create a github workflow with the following content:

name: Publish to PyPI
on:
  push:
    tags:
      - "*"

jobs:
  build-n-publish:
    if: github.event.base_ref == 'refs/heads/<branch-for-deploy>' && startsWith(github.ref, 'refs/tags')
    name: Build and publish package
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.6
      uses: actions/setup-python@v2
      with:
        python-version: 3.6
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        make dev
    - name: <optional step to lint and test the code>
      run: |
        make lint
        make test
    - name: Build
      run: |
        pip install setuptools wheel twine
        python setup.py sdist bdist_wheel
    - name: Publish
      uses: pypa/gh-action-pypi-publish@master
      with:
        user: __token__
        password: ${{ secrets.pypi_password }}

Configure bump2version

For the versioning control we a using the package bump2version.

  1. Run pip install bump2version in your environment
  2. Add the following attributes to the setup.cfg file:
[bumpversion]
current_version = <version_number>
allow_dirty = True
tag_name = version-{new_version}
tag = True
commit = True
[bumpversion:file:<path_to_file_version_file>]
[bumpversion:file:<path_to_setup_file>]

Note: If NotADirectoryError: [Errno 20] Not a directory, check c4urself/bump2version#139 for a fix.

For more information see these links


  1. Run the command bumperversion [major|minor|patch] to increase the version number. This will create a new tag and commit the changes.

  2. Push the changes to the developer branch.

  3. Create a pull request onto master. To deploy pymove to Pypi using you must be in the master branch, pushing a tagged commit.

  4. After merging the new version into the master branch, push the new tag created by bump2version.

    • git push --tags

Conda-Forge Deployment


Uploading a package to conda-forge

The link in this tutorial will explain the steps to upload a package to conda-forge: https://conda-forge.org/docs/maintainer/adding_pkgs.html


Building conda recipe

With the package published to Pypi, we can easily deploy to the conda-forge chanel. First we create a conda recipe.

  1. Run the command conda conda skeleton pypi <package_name>. This will create a conda recipe for the package.

  2. Now add some information to the <package_name>/meta.yaml file.

{% set name = <package_name> %}
{% set version = <package_version> %}

package:
  name: "{{ name|lower }}"
  version: "{{ version }}"

source:
  url: "https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz"
  sha256: <package_version_sha256>

build:
  number: 0
  script: "{{ PYTHON }} -m pip install . -vv"
  noarch: python

requirements:
  host:
    - pip
    - python >=3.6
  run:
    - <package_requirements>
    - python >=3.6

test:
  imports:
    - <all_possible_imports>

about:
  home: <repository_url>
  license: <licence>
  license_family: <licence_family>
  license_file: <path_to_licence_file>
  summary: <package_summary>
  doc_url: <package_docs_url>
  dev_url:

extra:
  recipe-maintainers:
    - <your_github_username>
    - <other_package_maintainers>

All package run requirements must be available in the conda-forge channel.

Request the publication to the conda-forge channel

  1. Fork the example recipes repository at https://github.com/conda-forge/staged-recipes

  2. Copy the <package_name>/meta.yaml file created in the step above to the forked repo staged-recipes/recipes/example directory

  3. Push the changes to your forked repository.

  4. Make a pull request for your repository to the master branch on the stage-recipes repository.

    • conda-forge:master from <your_github_username>:<package_name>
  5. Now, the pull request will be checked.

    • Complete the checklist for the pull requests.

    • The recipe meta.yaml file will be checked by the conda-forge-linting service.

    • The recipe will be built for linux64, macos64 and windows64 systems.

  6. If there are any problems with the PR, a review team member will give you feedback, pointing out improvements and answering questions.

  7. Once everything is in order, the pull request will be aproved.


Maintaining the feedstock repository

  1. After the pull request, a new repository for the package will be created similar to https://github.com/conda-forge/<package_name>-feedstock.

  2. You will be added as a maintainer for the newly created repository

  3. The repository will automatically build the conda package and upload to https://anaconda.org/conda-forge

  4. To make any changes to the conda package, send a PR to the git feedstock repository main branch from a fork.

  5. Branches of the main repository are used for maintaining different versions only.

The regro-cf-autotick-bot will make an automatic Pull Request when it detects that the PyPi package has been updated.

Follow the PR instructions to update the conda-forge package.