Skip to content

Commit

Permalink
Publishing on pypi (#9)
Browse files Browse the repository at this point in the history
* chore: added 'build' and 'twine' packages as dependencies

* docs: added md file with publishing steps

* chore: prepared pyproject.toml for publishing

* docs: updated install part in readme

* feat: added publish.in and publish.txt as source and target for requriements compilaton cmd in Makefile

* feat: added make cmd install-gh-publish

* feat: added publish.yml to publish on pypi after release creation

* chore: 0.1.1
  • Loading branch information
eschmidt42 authored Sep 18, 2023
1 parent 92f42a1 commit ae8a4bc
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 21 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# based on https://simonwillison.net/2021/Nov/4/publish-open-source-python-library/
name: publish python package

on:
release:
types: [created]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml','**/requirements/core.txt', '**/requirements/test.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
make install-gh-test
- name: Run tests
run: |
pytest -v
deploy:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: actions/cache@v3
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-publish-pip-${{ hashFiles('**/pyproject.toml','**/requirements/core.txt', '**/requirements/publish.txt') }}
restore-keys: |
${{ runner.os }}-publish-pip-
- name: Install dependencies
run: |
make install-gh-publish
- name: Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m build
twine upload dist/*
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ req-core-in := requirements/core.in # input file for compilation of core requi
req-core-out := requirements/core.txt # output file of core requirements compilation
req-test-in := requirements/test.in # input file for compilation of test requirements
req-test-out := requirements/test.txt # output file of test requirements compilation
req-publish-in := requirements/publish.in # input file for compilation of publish requirements
req-publish-out := requirements/publish.txt # output file of publish requirements compilation
req-dev-in := requirements/dev.in # input file for compilation of dev requirements
req-dev-out := requirements/dev.txt # output file of dev requirements compilation

Expand All @@ -35,45 +37,48 @@ compile:
source .venv/bin/activate && \
pip-compile $(req-core-in) -o $(req-core-out) --resolver=backtracking && \
pip-compile $(req-test-in) -o $(req-test-out) --resolver=backtracking && \
pip-compile $(req-publish-in) -o $(req-publish-out) --resolver=backtracking && \
pip-compile $(req-dev-in) -o $(req-dev-out) --resolver=backtracking

.PHONY: compile-upgrade
compile-upgrade:
source .venv/bin/activate && \
pip-compile -U $(req-core-in) -o $(req-core-out) --resolver=backtracking && \
pip-compile -U $(req-test-in) -o $(req-test-out) --resolver=backtracking && \
pip-compile -U $(req-publish-in) -o $(req-publish-out) --resolver=backtracking && \
pip-compile -U $(req-dev-in) -o $(req-dev-out) --resolver=backtracking

# ==============================================================================
# install requirements
# ==============================================================================

req-in := pyproject.toml # input file for compilation of requirements
req-out := requirements.txt # output file of requirements compilation


# default environment (for local development)
.PHONY: install
install: venv
source .venv/bin/activate && \
pip-sync $(req-core-out) $(req-test-out) $(req-dev-out) && \
pip-sync $(req-core-out) $(req-test-out) $(req-publish-out) $(req-dev-out) && \
pip install -e . && \
pre-commit install

# github actions test environment
# github actions test environment
.PHONY: install-gh-test
install-gh-test:
pip install -r $(req-core-out) -r $(req-test-out) && \
pip install -e .

# github actions test environment
.PHONY: install-gh-publish
install-gh-publish:
pip install -r $(req-core-out) -r $(req-publish-out)

# ==============================================================================
# update requirements and virtual env after changes to requirements/*.txt files
# ==============================================================================

.PHONY: update
update:
source .venv/bin/activate && \
pip-sync $(req-core-out) $(req-test-out) $(req-dev-out) && \
pip-sync $(req-core-out) $(req-test-out) $(req-publish-out) $(req-dev-out) && \
pip install -e .

# ==============================================================================
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ Implementations of a random selection of artificial neural net based models and

Development is done using [`pyenv`](https://realpython.com/intro-to-pyenv/), pinning the python version to the one in the file `.python-version`.

## Installation
## Installation (on Linux)

On Linux:
Package + notebooks:

git clone https://github.com/eschmidt42/random-neural-net-models.git
cd random-neural-net-models
make install

Package only:

pip install random-neural-net-models

## Usage

See jupyter notebooks in `nbs/` for:
Expand Down
19 changes: 19 additions & 0 deletions publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# publishing

Set up an account on TestPyPi and PyPi. Then after enabling two factor authentication set up a token. Once this is done add as described on (Test)PyPi to $HOME/.pypirc.

Then run

python -m build

twine check dist/*

twine upload -r testpypi dist/*

twine upload -r pypi dist/*

rm -r dist

## References

https://realpython.com/pypi-publish-python-package/
16 changes: 12 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
[build-system]
requires = ["setuptools>=65.0"]
requires = ["setuptools>=65.0","wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "random-neural-net-models"
description = "My implementation of a random selection of artificial neural net based models."
requires-python = ">=3.10"

version = "0.1.0"
version = "0.1.1"
authors = [
{name = "eschmidt42", email="[email protected]"}
]
description = "My implementation of a random selection of artificial neural net based models."
readme = "README.md"
license = { file = "LICENSE" }
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
]
keywords = ["neural-networks", "machine-learning", "deep-learning"]
# dependencies = [] - now via requirements/*.in files

[tool.black]
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-c core.txt
-c test.txt
-c publish.txt
black
isort
pre-commit
Expand Down
29 changes: 21 additions & 8 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ black==23.9.1
bleach==6.0.0
# via nbconvert
certifi==2023.7.22
# via requests
# via
# -c requirements/publish.txt
# requests
cffi==1.15.1
# via argon2-cffi-bindings
# via
# -c requirements/publish.txt
# argon2-cffi-bindings
cfgv==3.4.0
# via pre-commit
charset-normalizer==3.2.0
# via requests
# via
# -c requirements/publish.txt
# requests
click==8.1.7
# via black
comm==0.1.4
Expand Down Expand Up @@ -66,6 +72,7 @@ identify==2.5.28
# via pre-commit
idna==3.4
# via
# -c requirements/publish.txt
# anyio
# jsonschema
# requests
Expand Down Expand Up @@ -198,7 +205,7 @@ overrides==7.4.0
# via jupyter-server
packaging==23.1
# via
# -c requirements/test.txt
# -c requirements/publish.txt
# black
# ipykernel
# jupyter-server
Expand Down Expand Up @@ -235,10 +242,12 @@ ptyprocess==0.7.0
pure-eval==0.2.2
# via stack-data
pycparser==2.21
# via cffi
# via
# -c requirements/publish.txt
# cffi
pygments==2.16.1
# via
# -c requirements/core.txt
# -c requirements/publish.txt
# ipython
# nbconvert
python-dateutil==2.8.2
Expand All @@ -264,7 +273,9 @@ referencing==0.30.2
# jsonschema-specifications
# jupyter-events
requests==2.31.0
# via jupyterlab-server
# via
# -c requirements/publish.txt
# jupyterlab-server
rfc3339-validator==0.1.4
# via
# jsonschema
Expand Down Expand Up @@ -332,7 +343,9 @@ traitlets==5.10.0
uri-template==1.3.0
# via jsonschema
urllib3==2.0.4
# via requests
# via
# -c requirements/publish.txt
# requests
virtualenv==20.24.5
# via pre-commit
wcwidth==0.2.6
Expand Down
3 changes: 3 additions & 0 deletions requirements/publish.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-c core.txt
build
twine
83 changes: 83 additions & 0 deletions requirements/publish.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --config=pyproject.toml --output-file=requirements/publish.txt --resolver=backtracking requirements/publish.in
#
build==1.0.3
# via -r requirements/publish.in
certifi==2023.7.22
# via requests
cffi==1.15.1
# via cryptography
charset-normalizer==3.2.0
# via requests
cryptography==41.0.3
# via secretstorage
docutils==0.20.1
# via readme-renderer
idna==3.4
# via requests
importlib-metadata==6.8.0
# via
# keyring
# twine
jaraco-classes==3.3.0
# via keyring
jeepney==0.8.0
# via
# keyring
# secretstorage
keyring==24.2.0
# via twine
markdown-it-py==3.0.0
# via
# -c requirements/core.txt
# rich
mdurl==0.1.2
# via
# -c requirements/core.txt
# markdown-it-py
more-itertools==10.1.0
# via jaraco-classes
nh3==0.2.14
# via readme-renderer
packaging==23.1
# via
# -c requirements/core.txt
# build
pkginfo==1.9.6
# via twine
pycparser==2.21
# via cffi
pygments==2.16.1
# via
# -c requirements/core.txt
# readme-renderer
# rich
pyproject-hooks==1.0.0
# via build
readme-renderer==42.0
# via twine
requests==2.31.0
# via
# requests-toolbelt
# twine
requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==13.5.2
# via
# -c requirements/core.txt
# twine
secretstorage==3.3.3
# via keyring
twine==4.0.2
# via -r requirements/publish.in
urllib3==2.0.4
# via
# requests
# twine
zipp==3.16.2
# via importlib-metadata
2 changes: 2 additions & 0 deletions src/random_neural_net_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "0.1.1"

0 comments on commit ae8a4bc

Please sign in to comment.