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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ac6d847 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,69 @@ +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', '3.9'] + + 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 + + - 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 + env: + DB_NAME: postgres + DB_USER: postgres + DB_PASSWORD: postgres + DB_HOST: localhost + DB_PORT: 5432 + + - name: Upload coverage + uses: codecov/codecov-action@v1 + with: + name: Python ${{ matrix.python-version }} 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 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 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/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) ------------------ 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 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..766f756 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: # pragma: no cover + # package is not installed + __version__ = None diff --git a/setup.py b/setup.py index 11096ca..f15f968 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=[ diff --git a/tests/settings.py b/tests/settings.py index e34c891..6fc2bdb 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.environ.get("DB_PORT", 5432) }, } SECRET_KEY = 'dummy' diff --git a/tox.ini b/tox.ini index 60d6576..cee8e64 100644 --- a/tox.ini +++ b/tox.ini @@ -1,35 +1,34 @@ [tox] envlist = - py{36,37,38,39}-django{22,30,31,master} + py{36,37,38,39}-dj{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] deps = freezegun==0.3.12 -rrequirements-test.txt - django22: Django==2.2.* - django30: Django==3.0.* - django31: Django==3.1.* - djangomaster: https://github.com/django/django/archive/master.tar.gz + dj22: Django==2.2.* + dj30: Django==3.0.* + dj31: Django==3.1.* + djmaster: https://github.com/django/django/archive/master.tar.gz ignore_outcome = - djangotrunk: True + djmaster: True passenv = CI - TRAVIS - TRAVIS_* - + GITHUB_* + DB_* +usedevelop = True commands = - pip install -e . pytest {posargs} -[testenv:py{36,37,38,39}-djangomaster] +[testenv:py{36,37,38,39}-djmaster] ignore_errors = True [testenv:flake8]