Skip to content

Commit

Permalink
Add action for publishing to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
jdehning committed Aug 12, 2023
1 parent 136515f commit 49ec84e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 112 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/main.yaml

This file was deleted.

66 changes: 11 additions & 55 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,61 +1,17 @@
name: Release

name: Publish to PyPI.org
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
release:
name: Release
types: [published]
jobs:
pypi:
runs-on: ubuntu-latest
timeout-minutes: 10

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3

- uses: conda-incubator/setup-miniconda@v2
- name: Checkout
uses: actions/checkout@v3
with:
miniconda-version: "latest"
mamba-version: "1.*"
environment-file: conda/dev.yaml
channels: conda-forge,nodefaults
channel-priority: true
activate-environment: comodi
use-mamba: true
miniforge-variant: Mambaforge

- name: Install deps
run: poetry install

- name: Run semantic release (for tests)
if: ${{ github.event_name != 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make release-dry

- name: Release command
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi ${PYPI_TOKEN}
make release-ci
- name: Generate documentation with changes from semantic-release
if: ${{ github.event_name == 'workflow_dispatch' }}
run: make docs-build

- name: GitHub Pages action
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: peaceiris/[email protected]
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html
password: ${{ secrets.PYPI_API_TOKEN }}
19 changes: 8 additions & 11 deletions comodi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
from .tools import hierarchical_priors


def _get_version() -> str:
"""Return the program version."""
try:
return importlib_metadata.version(__name__)
except importlib_metadata.PackageNotFoundError: # pragma: no cover
return "0.1.0" # Default version


version: str = _get_version()

__author__ = "Jonas Dehning"
__email__ = "[email protected]"
__version__: str = version

from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("package-name")
except PackageNotFoundError:
# package is not installed
pass
10 changes: 6 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@
# for |version| and |release|, also used in various other places throughout
# the built documents.
#
# The short X.Y version.
version = "0.1.0"
# The full version, including alpha/beta/rc tags.
release = "0.1.0"

from importlib.metadata import version
release = version('myproject')
# for example take major/minor
version = '.'.join(release.split('.')[:2])


# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools"]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"


Expand All @@ -21,8 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
#dynamic = ["version"]
version = "0.1.0"
dynamic = ["version"]
requires-python = '>=3.8.1'
dependencies = [
"numpy",
Expand Down Expand Up @@ -103,4 +102,7 @@ no_strict_optional = false
[tool.setuptools]
packages = ["comodi"]

[tool.setuptools_scm]
write_to = "comodi/_version.py"


0 comments on commit 49ec84e

Please sign in to comment.