Skip to content

Commit

Permalink
Merge pull request #20 from ministryofjustice/declarative-build
Browse files Browse the repository at this point in the history
Migrate to modern/declarative packaging
  • Loading branch information
ushkarev authored Nov 7, 2023
2 parents 8605fa7 + 97d03c2 commit 8ba0111
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 168 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install linting dependencies
run: pip install -U setuptools pip wheel -r requirements-lint.txt
- name: Update setuptools pip and wheel
run: pip install -U setuptools pip wheel
- name: Install linting requirements
run: pip install -r requirements-lint.txt
- name: Lint code
run: flake8 --verbose
9 changes: 6 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ jobs:
run: sudo apt-get install gettext
- name: Update setuptools pip and wheel
run: pip install -U setuptools pip wheel
- name: Install twine
run: pip install twine
- name: Install release requirements
run: pip install -r requirements-release.txt
- name: Build and release to PYPI
run: |
python setup.py compilemessages sdist bdist_wheel
python scripts/messages.py compile
python -m build
unzip -l dist/*.whl
tar tzf dist/*.tar.gz
twine upload --non-interactive dist/*
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ jobs:
- name: Install django
run: pip install django~=${{ matrix.django-version }}.0
- name: Run tests
run: python setup.py compilemessages test
run: |
pip install --editable .
python scripts/messages.py compile
python -m tests
25 changes: 20 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
.PHONY: help clean test test-all coverage release
.PHONY: help init clean test test-all coverage lint release

help:
@echo "Using make is entirely optional; these are simply shortcuts"
@echo "See README.rst for normal usage."
@echo ""
@echo "init - create virtual environment"
@echo "clean - remove all build and test artifacts"
@echo "test - run all tests using current python environment"
@echo "test-all - run all tests in all supported python environments"
@echo "coverage - check code coverage while running all tests using current python environment"
@echo "lint - check code style"
@echo "release - NOT NORMALLY USED; See README.rst for release process"

init:
[ -d venv ] || python -m venv venv
./venv/bin/pip install -U setuptools pip wheel
./venv/bin/pip install --editable .
@echo `./venv/bin/python --version` virtual environment installed. Activate it using '`. ./venv/bin/activate`'

clean:
rm -fr build/ dist/ .eggs/ .tox/ .coverage
find . -name '*.pyc' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

test: clean
python setup.py test
test:
pip install --editable .
python scripts/messages.py compile
python -m tests

test-all:
pip install --upgrade tox
Expand All @@ -27,7 +37,12 @@ coverage:
coverage run setup.py test
coverage report --show-missing

lint:
pip install -r requirements-lint.txt
flake8 --verbose

release: clean
pip install --upgrade twine
python setup.py compilemessages sdist bdist_wheel
pip install -r requirements-release.txt
python scripts/messages.py compile
python -m build
twine upload dist/*
25 changes: 19 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,31 @@ Development

Please report bugs and open pull requests on `GitHub`_.

Use ``python setup.py test`` to run all tests.
To work on changes to this library, it’s recommended to install it in editable mode into a virtual environment,
i.e. ``pip install --editable .``

If any localisable strings change, run ``python setup.py makemessages compilemessages``.
Use ``python -m tests`` to run all tests locally.
Alternatively, you can use ``tox`` if you have multiple python versions.

Distribute a new version to `PyPI`_ by updating the ``VERSION`` tuple in ``zendesk_tickets/__init__.py`` and
publishing a release in GitHub (this triggers a GitHub Actions workflow to automatically upload it).
Alternatively, run ``python setup.py compilemessages sdist bdist_wheel upload`` locally.
Remember to update `History`_.
Update translation files using ``python scripts/messages.py update``, when any localisable strings change.
Compile them using ``python scripts/messages.py compile``; this is *required* before testing and distribution.
Updating and compiling translation files requires the gettext system package to be installed.

[Only for GitHub team members] Distribute a new version to `PyPI`_ by:

- updating the ``VERSION`` tuple in ``zendesk_tickets/__init__.py``
- adding a note to the `History`_
- publishing a release on GitHub which triggers an upload to PyPI;
alternatively, run ``python scripts/messages.py compile; python -m build; twine upload dist/*`` locally

History
-------

Unreleased
Migrated test, build and release processes away from deprecated setuptools commands.
Translation files are updated and compiled through scripts which are not included in distribution.
No significant library changes.

0.16
Drop support for python 3.6 and 3.7.
Add support for python 3.11.
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
2 changes: 2 additions & 0 deletions requirements-release.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
twine
41 changes: 41 additions & 0 deletions scripts/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
import argparse
import logging
import os
import pathlib
import sys

from django.core.management import call_command


def main():
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

parser = argparse.ArgumentParser(description='Manage gettext localisation messages')
sub_parsers = parser.add_subparsers()
description = 'Update localisation message files from source code'
sub_parser = sub_parsers.add_parser('update', help=description, description=description)
sub_parser.set_defaults(command='update')
description = 'Compile gettext binary localisation message files'
sub_parser = sub_parsers.add_parser('compile', help=description, description=description)
sub_parser.set_defaults(command='compile')

args = parser.parse_args()
if not hasattr(args, 'command'):
parser.print_help()
sys.exit(1)

root_path = pathlib.Path(__file__).parent.parent
os.chdir(root_path / 'zendesk_tickets')

if args.command == 'update':
logging.info('Updating localisation message files')
call_command('makemessages', all=True, no_wrap=True, keep_pot=True)

if args.command == 'compile':
logging.info('Compiling localisation message files')
call_command('compilemessages', fuzzy=False)


if __name__ == '__main__':
main()
46 changes: 46 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
[metadata]
name = django-zendesk-tickets
version = attr: zendesk_tickets.__version__
url = https://github.com/ministryofjustice/django-zendesk-tickets
author = Ministry of Justice Digital & Technology
author_email = [email protected]
description = Django views and forms that submit tickets to Zendesk
long_description = file: README.rst
license = MIT
keywords =
django
tickets
zendesk
classifiers =
Development Status :: 4 - Beta
Framework :: Django
Framework :: Django :: 2.2
Framework :: Django :: 3.0
Framework :: Django :: 3.1
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Framework :: Django :: 4.1
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11

[options]
; NB: looser python version requirement than what's tested
python_requires = >=3.6
packages =
zendesk_tickets
zendesk_tickets.locale.cy.LC_MESSAGES
zendesk_tickets.locale.en_GB.LC_MESSAGES
zendesk_tickets.templates.zendesk_tickets
include_package_data = true
install_requires =
Django>=2.2,<4.3
requests

[flake8]
exclude = .git/,.eggs/,.tox/,build/,dist/,env/,venv/
max-complexity = 10
Expand Down
57 changes: 2 additions & 55 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,10 @@
#!/usr/bin/env python
import importlib
import os
import sys
import warnings

from setuptools import setup

if sys.version_info[0:2] < (3, 8):
warnings.warn('This package is tested with Python version 3.8+', stacklevel=1)
warnings.warn('This package is only tested on Python version 3.8+', stacklevel=1)

root_path = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(root_path, 'README.rst')) as readme:
README = readme.read()

package_info = importlib.import_module('zendesk_tickets')
setup_extensions = importlib.import_module('zendesk_tickets.setup_extensions')
command_classes = setup_extensions.command_classes.copy()

setup(
name='django-zendesk-tickets',
version=package_info.__version__,
author=package_info.__author__,
author_email='[email protected]',
url='https://github.com/ministryofjustice/django-zendesk-tickets',
packages=[
'zendesk_tickets',
'zendesk_tickets.locale.cy.LC_MESSAGES',
'zendesk_tickets.locale.en_GB.LC_MESSAGES',
'zendesk_tickets.templates.zendesk_tickets',
],
include_package_data=True,
license='MIT',
description='Django views and forms that submit tickets to Zendesk',
long_description=README,
keywords='zendesk django tickets',
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Framework :: Django :: 4.1',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
cmdclass=command_classes,
python_requires='>=3.6', # looser requirement than what's tested
setup_requires=['Django>=2.2,<4.3'],
install_requires=['Django>=2.2,<4.3', 'requests'],
tests_require=[],
test_suite='tests.run',
)
setup()
51 changes: 0 additions & 51 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,51 +0,0 @@
import os
import sys

import django
from django.conf import settings
from django.test.runner import DiscoverRunner

test_settings = dict(
DEBUG=True,
SECRET_KEY='a' * 50,
ROOT_URLCONF='tests.urls',
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'zendesk_tickets',
),
MIDDLEWARE=[
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
],
SESSION_ENGINE='django.contrib.sessions.backends.signed_cookies',
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
'APP_DIRS': True,
}],
ZENDESK_BASE_URL='https://zendesk.local/',
ZENDESK_API_USERNAME='zendesk_user',
ZENDESK_API_TOKEN='api_token',
ZENDESK_REQUESTER_ID=111111,
ZENDESK_GROUP_ID=222222,
ZENDESK_CUSTOM_FIELDS={
'referer': 31,
'username': 32,
'user_agent': 33,
'contact_email': 34,
},
)


def run():
if not settings.configured:
settings.configure(**test_settings)
django.setup()
failures = DiscoverRunner(verbosity=2, failfast=False, interactive=False).run_tests(['tests'])
sys.exit(failures)


if __name__ == '__main__':
run()
51 changes: 51 additions & 0 deletions tests/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pathlib
import sys

if __name__ == '__main__':
import django
from django.conf import settings
from django.test.runner import DiscoverRunner

tests_path = pathlib.Path(__file__).parent
root_path = tests_path.parent

test_settings = dict(
DEBUG=True,
SECRET_KEY='a' * 50,
ROOT_URLCONF='tests.urls',
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'zendesk_tickets',
),
MIDDLEWARE=[
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
],
SESSION_ENGINE='django.contrib.sessions.backends.signed_cookies',
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [tests_path / 'templates'],
'APP_DIRS': True,
}],
ZENDESK_BASE_URL='https://zendesk.local/',
ZENDESK_API_USERNAME='zendesk_user',
ZENDESK_API_TOKEN='api_token',
ZENDESK_REQUESTER_ID=111111,
ZENDESK_GROUP_ID=222222,
ZENDESK_CUSTOM_FIELDS={
'referer': 31,
'username': 32,
'user_agent': 33,
'contact_email': 34,
},
)

if not settings.configured:
settings.configure(**test_settings)
django.setup()

test_runner = DiscoverRunner(verbosity=2, failfast=False, interactive=False, top_level=root_path)
failures = test_runner.run_tests(['tests'])
sys.exit(failures)
Loading

0 comments on commit 8ba0111

Please sign in to comment.