From 7121e9575a00d8e5e66adf4fb732fb7e468682c1 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:35:54 +0100 Subject: [PATCH 01/15] Add GitHub Actions test workflow. --- .github/workflows/test.yml | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..50bd76c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: Test + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + python-version: [3.6', '3.7', '3.8'] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Get pip cache dir + id: pip-cache + run: | + echo "::set-output name=dir::$(pip cache dir)" + + - name: Cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: + ${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }} + restore-keys: | + ${{ matrix.python-version }}-v1- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade tox tox-gh-actions + + - name: Tox tests + run: | + tox -v -- --cov --cov-append --cov-report term-missing --cov-report xml + + - name: Upload coverage + uses: codecov/codecov-action@v1 + with: + name: Python ${{ matrix.python-version }} From 0ce25013842169c7eb97484e2b3af0870f64b271 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:36:06 +0100 Subject: [PATCH 02/15] Update tox config. --- tox.ini | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tox.ini b/tox.ini index 394c01c..cd7b06f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,27 +1,25 @@ [tox] envlist = - py{36,37,38}-django{21,22,30,31,trunk} + py{36,37,38}-dj{21,22,30,31,trunk} flake8 [testenv] deps = freezegun==0.3.12 -rrequirements-test.txt - django22: Django==2.2.* - django21: Django==2.1.* - django30: Django==3.0.* - django31: Django==3.1.* - djangotrunk: https://github.com/django/django/archive/master.tar.gz + dj22: Django==2.2.* + dj21: Django==2.1.* + dj30: Django==3.0.* + dj31: Django==3.1.* + djtrunk: https://github.com/django/django/archive/master.tar.gz ignore_outcome = - djangotrunk: True + djtrunk: True passenv = CI - TRAVIS - TRAVIS_* - + GITHUB_* +usedevelop = True commands = - pip install -e . - py.test {posargs} + pytest {posargs} [testenv:flake8] basepython = @@ -37,3 +35,9 @@ ignore = W503 ; line break before binary operator E402 ; module level import not at top of file E501 ; line too long + +[gh-actions] +python = + 3.6: py36 + 3.7: py37, flake8 + 3.8: py38 From 2cd07a9e89f78e7fdd273a50b8d5d78600ae885d Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:39:17 +0100 Subject: [PATCH 03/15] Use setuptools_scm --- docs/conf.py | 16 +++++----------- model_utils/__init__.py | 8 +++++++- setup.py | 13 ++++--------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d234b3f..0d47d51 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +from pkg_resources import get_distribution # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -44,20 +45,13 @@ copyright = '2015, Carl Meyer' parent_dir = os.path.dirname(os.path.dirname(__file__)) -def get_version(): - with open(os.path.join(parent_dir, 'model_utils', '__init__.py')) as f: - for line in f: - if line.startswith('__version__ ='): - return line.split('=')[1].strip().strip('"\'') - # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # -# The full version, including alpha/beta/rc tags. -release = get_version() -# The short X.Y version. -version = release +release = get_distribution('django-model-utils').version +# 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. diff --git a/model_utils/__init__.py b/model_utils/__init__.py index 0275e64..ff00ad6 100644 --- a/model_utils/__init__.py +++ b/model_utils/__init__.py @@ -1,4 +1,10 @@ +from pkg_resources import get_distribution, DistributionNotFound + from .choices import Choices # noqa:F401 from .tracker import FieldTracker, ModelTracker # noqa:F401 -__version__ = '4.0.1' +try: + __version__ = get_distribution("django-model-utils").version +except DistributionNotFound: + # package is not installed + pass diff --git a/setup.py b/setup.py index 313a33c..8ecaa16 100644 --- a/setup.py +++ b/setup.py @@ -15,23 +15,18 @@ HERE = os.path.abspath(os.path.dirname(__file__)) long_description = "\n\n".join(long_desc(HERE)) -def get_version(root_path): - with open(os.path.join(root_path, 'model_utils', '__init__.py')) as f: - for line in f: - if line.startswith('__version__ ='): - return line.split('=')[1].strip().strip('"\'') - - setup( name='django-model-utils', - version=get_version(HERE), + use_scm_version={"version_scheme": "post-release"}, + setup_requires=["setuptools_scm"], license="BSD", description='Django model mixins and utilities', long_description=long_description, + long_description_content_type='text/x-rst', author='Carl Meyer', author_email='carl@oddbird.net', maintainer='JazzBand', - url='https://github.com/jazzband/django-model-utils/', + url='https://github.com/jazzband/django-model-utils', packages=find_packages(exclude=['tests*']), install_requires=['Django>=2.0.1'], classifiers=[ From 000528d8d8cf835c34cc9b556e872c7750c67702 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:39:53 +0100 Subject: [PATCH 04/15] Remove old Mercurial cruft. --- .hgignore | 7 ------- .hgtags | 6 ------ 2 files changed, 13 deletions(-) delete mode 100644 .hgignore delete mode 100644 .hgtags diff --git a/.hgignore b/.hgignore deleted file mode 100644 index cfb8076..0000000 --- a/.hgignore +++ /dev/null @@ -1,7 +0,0 @@ -^dist/ -^django_model_utils\.egg-info/ -^HGREV$ -^\.coverage$ -^\.tox/ -^Django.*\.egg$ -^htmlcov/ diff --git a/.hgtags b/.hgtags deleted file mode 100644 index 21c952e..0000000 --- a/.hgtags +++ /dev/null @@ -1,6 +0,0 @@ -b5efc435bb7e21b0d7ba422d28d174ccca3b3322 0.2.0 -71b54b8b44fa2456beebd51c474ba55ad625486a 0.3.1 -1e6f730f8c3a648c9fb70844a68fcfa663608600 0.4.0 -004dbee634cb661c52acac034063989e521c4bb8 0.5.0 -bd164041e5fabd64de19c38fefe9af9237a2a59e 1.0.0 -92792fb14a51b580e5cc8991e815f3b3b57a6204 1.1.0 From c3f25724f48cce94ea89d30efeaf94627c1e7832 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:40:07 +0100 Subject: [PATCH 05/15] Ignore coverage xml. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d6b55d2..f73e7a9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ docs/_build/ .idea/ .eggs/ .venv/ +coverage.xml From ec7ef185fb2b0175a0a8b6303279c6b3a138ffac Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:40:18 +0100 Subject: [PATCH 06/15] Add release workflow. --- .github/workflows/release.yml | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f367713 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + build: + if: github.repository == 'jazzband/django-model-utils' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -U setuptools twine wheel + + - name: Build package + run: | + python setup.py --version + python setup.py sdist --format=gztar bdist_wheel + twine check dist/* + + - name: Upload packages to Jazzband + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@master + with: + user: jazzband + password: ${{ secrets.JAZZBAND_RELEASE_KEY }} + repository_url: https://jazzband.co/projects/django-model-utils/upload From 24c196ebe368cb3dfb17e6d9560670289a07c80a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:44:11 +0100 Subject: [PATCH 07/15] Fix typo. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50bd76c..263777e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false max-parallel: 5 matrix: - python-version: [3.6', '3.7', '3.8'] + python-version: ['3.6', '3.7', '3.8'] steps: - uses: actions/checkout@v2 From 5b3672b980eda10ed0567a121f9fff2a055366f4 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:51:26 +0100 Subject: [PATCH 08/15] Run Postgres 10 during testing. --- .github/workflows/test.yml | 21 +++++++++++++++++++++ tests/settings.py | 9 +++++---- tox.ini | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 263777e..d9dfc1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,21 @@ jobs: matrix: python-version: ['3.6', '3.7', '3.8'] + services: + postgres: + image: postgres:10 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - uses: actions/checkout@v2 @@ -41,6 +56,12 @@ jobs: - name: Tox tests run: | tox -v -- --cov --cov-append --cov-report term-missing --cov-report xml + env: + DB_NAME: postgres + DB_USER: postgres + DB_PASSWORD: postgres + DB_HOST: localhost + DB_PORT: 5432 - name: Upload coverage uses: codecov/codecov-action@v1 diff --git a/tests/settings.py b/tests/settings.py index e34c891..9d23a70 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -7,10 +7,11 @@ INSTALLED_APPS = ( DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", - "NAME": os.environ.get("DJANGO_DATABASE_NAME_POSTGRES", "modelutils"), - "USER": os.environ.get("DJANGO_DATABASE_USER_POSTGRES", 'postgres'), - "PASSWORD": os.environ.get("DJANGO_DATABASE_PASSWORD_POSTGRES", ""), - "HOST": os.environ.get("DJANGO_DATABASE_HOST_POSTGRES", ""), + "NAME": os.environ.get("DB_NAME", "modelutils"), + "USER": os.environ.get("DB_USER", 'postgres'), + "PASSWORD": os.environ.get("DB_PASSWORD", ""), + "HOST": os.environ.get("DB_HOST", ""), + "PORT": os.envrion.get("DB_PORT", 5432) }, } SECRET_KEY = 'dummy' diff --git a/tox.ini b/tox.ini index 2a98cff..b0f81ac 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,7 @@ ignore_outcome = passenv = CI GITHUB_* + DB_* usedevelop = True commands = pytest {posargs} From 1b9e1fa435879abd608928f4582d97fb3083b243 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:53:42 +0100 Subject: [PATCH 09/15] Update changelog. --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 5fe4332..5f4e19a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,7 @@ CHANGES update_fieldsparameter when 'status' is present in it to make sure it is not forgotten. - Update test requirements +- Move tests to GitHub Actions: https://github.com/jazzband/django-model-utils/actions 4.0.0 (2019-12-11) ------------------ From e2e2cc8485a0dfd72fd98deb1c5758cd2ed7e2ee Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:53:56 +0100 Subject: [PATCH 10/15] Remove old Travis cruft. --- .travis.yml | 36 ------------------------------------ README.rst | 4 ++-- 2 files changed, 2 insertions(+), 38 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2b01674..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -version: ~> 1.0 -dist: bionic -os: linux -language: python -cache: pip -python: -- 3.6 -- 3.7 -- 3.8 -- 3.9 -arch: - - amd64 - - ppc64le -jobs: - include: - - python: 3.8 - env: TOXENV=flake8 -install: pip install tox-travis codecov -# positional args ({posargs}) to pass into tox.ini -script: tox -- --cov --cov-append -addons: - postgresql: '10' -services: - - postgresql -after_success: codecov -deploy: - provider: pypi - username: jazzband - server: https://jazzband.co/projects/django-model-utils/upload - distributions: sdist bdist_wheel - password: - secure: JxUmEdYS8qT+7xhVyzmVD4Gkwqdz5XKxoUhKP795CWIXoJjtlGszyo6w0XfnFs0epXtd1NuCRXdhea+EqWKFDlQ3Yg7m6Y/yTQV6nMHxCPSvicROho7pAiJmfc/x+rSsPt5ag8av6+S07tOqvMnWBBefYbpHRoel78RXkm9l7Mc= - on: - tags: true - repo: jazzband/django-model-utils - python: 3.6 diff --git a/README.rst b/README.rst index 17fc15f..c07f109 100644 --- a/README.rst +++ b/README.rst @@ -5,8 +5,8 @@ django-model-utils .. image:: https://jazzband.co/static/img/badge.svg :target: https://jazzband.co/ :alt: Jazzband -.. image:: https://travis-ci.org/jazzband/django-model-utils.svg?branch=master - :target: https://travis-ci.org/jazzband/django-model-utils +.. image:: https://github.com/jazzband/django-model-utils/workflows/Test/badge.svg + :target: https://github.com/jazzband/django-model-utils/actions .. image:: https://codecov.io/gh/jazzband/django-model-utils/branch/master/graph/badge.svg :target: https://codecov.io/gh/jazzband/django-model-utils .. image:: https://img.shields.io/pypi/v/django-model-utils.svg From 124ca269015408248b6c6b429fd43f3709aa92b0 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:54:15 +0100 Subject: [PATCH 11/15] Remove duplicate version mapping. --- tox.ini | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tox.ini b/tox.ini index b0f81ac..5920732 100644 --- a/tox.ini +++ b/tox.ini @@ -3,11 +3,11 @@ envlist = py{36,37,38,39}-dj{21,22,30,31,master} flake8 -[travis] +[gh-actions] python = 3.6: py36 3.7: py37 - 3.8: py38 + 3.8: py38, flake8 3.9: py39 [testenv] @@ -46,9 +46,3 @@ ignore = W503 ; line break before binary operator E402 ; module level import not at top of file E501 ; line too long - -[gh-actions] -python = - 3.6: py36 - 3.7: py37 - 3.8: py38, flake8 From 415742ccdf2ae3792ef641de0025c55288f7b269 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 14:54:45 +0100 Subject: [PATCH 12/15] Fix typo. --- tests/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/settings.py b/tests/settings.py index 9d23a70..6fc2bdb 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -11,7 +11,7 @@ DATABASES = { "USER": os.environ.get("DB_USER", 'postgres'), "PASSWORD": os.environ.get("DB_PASSWORD", ""), "HOST": os.environ.get("DB_HOST", ""), - "PORT": os.envrion.get("DB_PORT", 5432) + "PORT": os.environ.get("DB_PORT", 5432) }, } SECRET_KEY = 'dummy' From e630935fa309aa1259a4baf2f682e7f0398921ff Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 15:00:33 +0100 Subject: [PATCH 13/15] Please coverage --- model_utils/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model_utils/__init__.py b/model_utils/__init__.py index ff00ad6..766f756 100644 --- a/model_utils/__init__.py +++ b/model_utils/__init__.py @@ -5,6 +5,6 @@ from .tracker import FieldTracker, ModelTracker # noqa:F401 try: __version__ = get_distribution("django-model-utils").version -except DistributionNotFound: +except DistributionNotFound: # pragma: no cover # package is not installed - pass + __version__ = None From 8689faf2ad2d30202ceaea548336a81cad2ee875 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 15:12:19 +0100 Subject: [PATCH 14/15] Update tox.ini Co-authored-by: Simon Charette --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 5920732..cee8e64 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{36,37,38,39}-dj{21,22,30,31,master} + py{36,37,38,39}-dj{22,30,31,master} flake8 [gh-actions] From 382110f84c493c5d2af5f47ff8f3f00194ccdaba Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 29 Nov 2020 15:34:22 +0100 Subject: [PATCH 15/15] Update .github/workflows/test.yml Co-authored-by: Hasan Ramezani --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d9dfc1b..ac6d847 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false max-parallel: 5 matrix: - python-version: ['3.6', '3.7', '3.8'] + python-version: ['3.6', '3.7', '3.8', '3.9'] services: postgres: