From 6cba8950e46eec8abbe7d74fd39f7eff5814c0ca Mon Sep 17 00:00:00 2001 From: Swen Kooij Date: Sun, 30 Jan 2022 15:56:53 +0200 Subject: [PATCH] Let CircleCI publish the package to PyPi --- .circleci/config.yml | 43 ++++++++++++++++++++++++++++++++++++++++--- psqlextra/__init__.py | 11 +++++++++++ psqlextra/_version.py | 1 + setup.py | 19 +++++++++++++++++-- 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 psqlextra/_version.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 1134c3a5..f37c7bf2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ executors: version: type: string docker: - - image: python:<< parameters.version >>-alpine + - image: python:<< parameters.version >>-buster - image: postgres:11.0 environment: POSTGRES_DB: 'psqlextra' @@ -22,11 +22,11 @@ commands: steps: - run: name: Install packages - command: apk add postgresql-libs gcc musl-dev postgresql-dev git + command: apt-get update && apt-get install -y --no-install-recommends postgresql-client-11 libpq-dev build-essential git - run: name: Install Python packages - command: pip install --progress-bar off .[<< parameters.extra >>] + command: pip install --progress-bar off '.[<< parameters.extra >>]' run-tests: parameters: @@ -121,6 +121,30 @@ jobs: name: Verify command: python setup.py verify + publish: + executor: + name: python + version: "3.9" + steps: + - checkout + - install-dependencies: + extra: publish + - run: + name: Set version number + command: echo "__version__ = \"${CIRCLE_TAG:1}\"" > psqlextra/_version.py + - run: + name: Build package + command: python -m build + - run: + name: Publish package + command: > + python -m twine upload + --username "${PYPI_REPO_USERNAME}" + --password "${PYPI_REPO_PASSWORD}" + --verbose + --non-interactive + --disable-progress-bar + dist/* workflows: version: 2 @@ -132,3 +156,16 @@ workflows: - test-python39 - test-python310 - analysis + - publish: + requires: + - test-python36 + - test-python37 + - test-python38 + - test-python39 + - test-python310 + - analysis + filters: + branches: + ignore: /.*/ + tags: + only: /^v\d+\.\d+\.\d+$/ diff --git a/psqlextra/__init__.py b/psqlextra/__init__.py index 5b7b21a1..474f803b 100644 --- a/psqlextra/__init__.py +++ b/psqlextra/__init__.py @@ -1,4 +1,15 @@ import django +from ._version import __version__ + if django.VERSION < (3, 2): # pragma: no cover default_app_config = "psqlextra.apps.PostgresExtraAppConfig" + + __all__ = [ + "default_app_config", + "__version__", + ] +else: + __all__ = [ + "__version__", + ] diff --git a/psqlextra/_version.py b/psqlextra/_version.py new file mode 100644 index 00000000..f6bb6f4d --- /dev/null +++ b/psqlextra/_version.py @@ -0,0 +1 @@ +__version__ = "2.0.4" diff --git a/setup.py b/setup.py index 0d91c7cc..ba031bfe 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,8 @@ from setuptools import find_packages, setup +exec(open("psqlextra/_version.py").read()) + class BaseCommand(distutils.cmd.Command): user_options = [] @@ -36,7 +38,7 @@ def run(self): setup( name="django-postgres-extra", - version="2.0.4", + version=__version__, packages=find_packages(exclude=["tests"]), include_package_data=True, license="MIT License", @@ -90,10 +92,23 @@ def run(self): "isort==5.10.0", "docformatter==1.4", ], + "publish": [ + "build==0.7.0", + "twine==3.7.1", + ], }, cmdclass={ "lint": create_command( - "Lints the code", [["flake8", "setup.py", "psqlextra", "tests"]] + "Lints the code", + [ + [ + "flake8", + "--builtin=__version__", + "setup.py", + "psqlextra", + "tests", + ] + ], ), "lint_fix": create_command( "Lints the code",