From a4d18d3b30e2ac3fa01f7b879a0393e51f6b8b74 Mon Sep 17 00:00:00 2001 From: Henri Hulski Date: Fri, 18 Feb 2022 11:11:55 +0100 Subject: [PATCH] chore: refactor the whole setup similar to Mezzanine --- .github/workflows/main.yml | 112 +++++++++++++++++++++++++++++++++++++ .gitignore | 23 +++++++- .hgignore | 14 +++-- .isort.cfg | 2 + .releaserc | 19 +++++++ .travis.yml | 17 ------ .tx/config | 4 +- MANIFEST.in | 8 ++- project.toml | 13 +++++ pytest.ini | 8 +++ setup.cfg | 62 +++++++++++++++++++- setup.py | 93 +----------------------------- tox.ini | 72 ++++++++++++++++++++++++ 13 files changed, 328 insertions(+), 119 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .isort.cfg create mode 100644 .releaserc delete mode 100644 .travis.yml create mode 100644 project.toml create mode 100644 pytest.ini create mode 100644 tox.ini diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..c2b0a55e0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,112 @@ +name: Test and release + +# Fires on all incoming commits +on: + pull_request: + push: + +jobs: + + # Test all supported Python & Django versions + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + # Django 2.2 + - tox-env: "py36-dj22" + python-version: "3.6" + - tox-env: "py37-dj22" + python-version: "3.7" + - tox-env: "py38-dj22" + python-version: "3.8" + - tox-env: "py39-dj22" + python-version: "3.9" + # Django 3.0 + - tox-env: "py36-dj30" + python-version: "3.6" + - tox-env: "py37-dj30" + python-version: "3.7" + - tox-env: "py38-dj30" + python-version: "3.8" + - tox-env: "py39-dj30" + python-version: "3.9" + # Django 3.1 + - tox-env: "py36-dj31" + python-version: "3.6" + - tox-env: "py37-dj31" + python-version: "3.7" + - tox-env: "py38-dj31" + python-version: "3.8" + - tox-env: "py39-dj31" + python-version: "3.9" + # Django 3.2 + - tox-env: "py36-dj32" + python-version: "3.6" + - tox-env: "py37-dj32" + python-version: "3.7" + - tox-env: "py38-dj32" + python-version: "3.8" + - tox-env: "py39-dj32" + python-version: "3.9" + - tox-env: "py310-dj32" + python-version: "3.10" + # Django 4.0 + - tox-env: "py38-dj40" + python-version: "3.8" + - tox-env: "py39-dj40" + python-version: "3.9" + - tox-env: "py310-dj40" + python-version: "3.10" + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: pip install -U pip tox + - name: Run tests + run: tox -e ${{ matrix.tox-env }} + - name: Publish Test Report + uses: mikepenz/action-junit-report@v2 + with: + report_paths: '**/junit/TEST-*.xml' + + # Lint + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install dependencies + run: pip install tox -U pip + - name: Lint + run: tox -e package -e lint -e pyupgrade + + # Create a new semantic release + # Only runs on the original repo, not forks + release: + if: github.repository_owner == 'stephenmcd' + needs: [test, lint] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.9 + - uses: actions/setup-node@v2 + with: + node-version: '14' # https://github.com/cycjimmy/semantic-release-action/issues/79#issuecomment-955463633 + - uses: cycjimmy/semantic-release-action@v2 + with: + semantic_version: 18 + extra_plugins: | + @semantic-release/exec@5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} diff --git a/.gitignore b/.gitignore index 69fe69aed..6906162d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,25 @@ *.pyc *.pyo *.db -*.egg-info -.idea/ +*.pot +*.doctree +*.swp +.vscode +.doctrees .DS_Store +.coverage +.idea/ +.pytest_cache +junit/ +local_settings.py +.eggs/ +.tox/ +Mezzanine.egg-info/ +build/ +docs/build/ +docs/_build/ +dist/ +htmlcov/ +mezzanine/project_template/static/ +/mezzanine/.project +/mezzanine/.pydevproject \ No newline at end of file diff --git a/.hgignore b/.hgignore index 61dc5d59d..64ab2e295 100644 --- a/.hgignore +++ b/.hgignore @@ -2,11 +2,17 @@ syntax: glob *.pyc *.pyo *.db +*.pot +*.doctree +.doctrees .DS_Store .coverage +.idea local_settings.py -build/* -dist/* -*.egg-info/* +build +dist +*.egg-info +*.egg project_template/static - +.project +.pydevproject diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 000000000..f238bf7ea --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +profile = black diff --git a/.releaserc b/.releaserc new file mode 100644 index 000000000..796b01e27 --- /dev/null +++ b/.releaserc @@ -0,0 +1,19 @@ +{ + "branches": [ + "+([0-9])?(.{+([0-9]),x}).x", + "stable", + {"name": "alpha", "prerelease": true}, + {"name": "beta", "prerelease": true}, + {"name": "rc", "prerelease": true} + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/github", + ["@semantic-release/exec", { + "verifyConditionsCmd": "python -m pip install -U pip setuptools wheel twine", + "prepareCmd": "sed -i 's/9999dev0/${nextRelease.version}/' mezzanine/__init__.py", + "publishCmd": "python setup.py sdist bdist_wheel && twine upload dist/*" + }] + ] +} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 969511a69..000000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: python -env: - - DJANGO="Django>=1.11,<1.12" -python: - - "2.7" - - "3.4" - - "3.5" -install: - - pip install $DJANGO - - pip install -e git://github.com/stephenmcd/mezzanine.git#egg=mezzanine - - pip install pyPdf -script: - - python setup.py test -notifications: - irc: "irc.freenode.org#mezzanine" - on_success: change - on_failure: change diff --git a/.tx/config b/.tx/config index d9a15624c..546b7c0fa 100644 --- a/.tx/config +++ b/.tx/config @@ -1,9 +1,9 @@ [main] host = https://www.transifex.com +lang_map = sr@latin:sr_Latn [cartridge.default] file_filter = cartridge/shop/locale//LC_MESSAGES/django.po source_file = cartridge/shop/locale/en/LC_MESSAGES/django.po source_lang = en -trans.es = cartridge/shop/locale/es/LC_MESSAGES/django.po - +type = PO diff --git a/MANIFEST.in b/MANIFEST.in index 6d16fc197..d5be8f25f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,11 @@ -include CHANGELOG LICENSE README.rst +include AUTHORS CHANGELOG LICENSE *.rst recursive-include docs * recursive-exclude docs/build * recursive-include cartridge * recursive-exclude */project_template/static * + +global-exclude __pycache__ +global-exclude *.py[co] +prune .tx +prune tests +exclude .releaserc .isort.cfg tox.ini pytest.ini .coveragerc \ No newline at end of file diff --git a/project.toml b/project.toml new file mode 100644 index 000000000..b3973ce95 --- /dev/null +++ b/project.toml @@ -0,0 +1,13 @@ +[tool.black] +exclude = ''' +( + /( + \.eggs + | \.git + | \.tox + | \.venv + | build + | dist + )/ +) +''' diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..503c41e08 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,8 @@ +[pytest] +addopts = + --tb short + --cov=cartridge + --cov-report html + --cov-report term:skip-covered + # Original coverage was 54% (not great), but at least ensure we don't go below + --cov-fail-under 57 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 5e4090017..0409daaab 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,60 @@ -[wheel] -universal = 1 +[metadata] +name = Cartridge +version = attr: cartridge.__version__ +description = AA Django shopping cart application. +long_description = file: README.rst +long_description_content_type = text/x-rst +author = Stephen McDonald +author_email = stephen.mc@gmail.com +url = http://cartridge.jupo.org/ +license = BSD +license_file = LICENSE +classifiers = + Development Status :: 5 - Production/Stable + Environment :: Web Environment + Framework :: Django + Intended Audience :: Developers + License :: OSI Approved :: BSD License + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Framework :: Django + Framework :: Django :: 2.2 + Framework :: Django :: 3.0 + Framework :: Django :: 3.1 + Framework :: Django :: 3.2 + Framework :: Django :: 4.0 + Topic :: Internet :: WWW/HTTP + Topic :: Internet :: WWW/HTTP :: Dynamic Content + Topic :: Internet :: WWW/HTTP :: WSGI + Topic :: Software Development :: Libraries :: Application Frameworks + Topic :: Software Development :: Libraries :: Python Modules + +[options] +python_requires = >=3.6 +packages = cartridge +include_package_data = true +install_requires = + mezzanine >= 5.1.1 + xhtml2pdf + +[options.extras_require] +stripe = stripe +testing = + pytest-django >= 4, <5 + pytest-cov >= 2, < 3 +codestyle = + flake8 >= 3, <4 + black==20.8b1 + isort >= 5, <6 + pyupgrade >= 2, <3 + +# Building + +[bdist_wheel] +universal = 1 \ No newline at end of file diff --git a/setup.py b/setup.py index 0a54e25e2..606849326 100644 --- a/setup.py +++ b/setup.py @@ -1,92 +1,3 @@ -import os -import sys -from setuptools import setup, find_packages -from shutil import rmtree -from cartridge import __version__ as version +from setuptools import setup - -exclude = ["cartridge/project_template/dev.db", - "cartridge/project_template/project_name/local_settings.py"] -if sys.argv == ["setup.py", "test"]: - exclude = [] -exclude = {e: None for e in exclude} -for e in exclude: - if e.endswith(".py"): - try: - os.remove("%sc" % e) - except: - pass - try: - with open(e) as f: - exclude[e] = (f.read(), os.stat(e)) - os.remove(e) - except: - pass - -if sys.argv[:2] == ["setup.py", "bdist_wheel"]: - # Remove previous build dir when creating a wheel build, - # since if files have been removed from the project, - # they'll still be cached in the build dir and end up - # as part of the build, which is really neat! - try: - rmtree("build") - except: - pass - - -try: - setup( - - name="Cartridge", - version=version, - author="Stephen McDonald", - author_email="stephen.mc@gmail.com", - description="A Django shopping cart application.", - long_description=open("README.rst", 'rb').read().decode('utf-8'), - license="BSD", - url="http://cartridge.jupo.org/", - zip_safe=False, - include_package_data=True, - packages=find_packages(), - test_suite="runtests.main", - tests_require=["pyflakes>=0.6.1", "pep8>=1.4.1"], - - install_requires=[ - "mezzanine >= 5.1.1", - "xhtml2pdf", - ], - extras_require={ - 'stripe': ['stripe'], - }, - - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Web Environment", - "Framework :: Django", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Internet :: WWW/HTTP :: Dynamic Content", - "Topic :: Internet :: WWW/HTTP :: WSGI", - "Topic :: Software Development :: Libraries :: " - "Application Frameworks", - "Topic :: Software Development :: Libraries :: Python Modules", - ]) - -finally: - for e in exclude: - if exclude[e] is not None: - data, stat = exclude[e] - try: - with open(e, "w") as f: - f.write(data) - os.chown(e, stat.st_uid, stat.st_gid) - os.chmod(e, stat.st_mode) - except: - pass +setup() diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..44396d40a --- /dev/null +++ b/tox.ini @@ -0,0 +1,72 @@ +[tox] +envlist = + py{36,37,38,39,310}-dj{22,30,31,32,40} + package + lint + +[testenv] +# Run test suite +usedevelop = true +deps = + .[testing] + dj22: Django>=2.2, <3 + dj30: Django>=3.0, <3.1 + dj31: Django>=3.1, <3.2 + dj32: Django>=3.2, <3.3 + dj40: Django>=4.0, <4.1 +commands = + pytest --basetemp="{envtmpdir}" --junitxml="junit/TEST-{envname}.xml" {posargs} + +[testenv:package] +# Check package integrity and compatibility with PyPI +deps = + twine + check-manifest +skip_install = true +commands = + python setup.py -q sdist --dist-dir="{envtmpdir}/dist" + twine check "{envtmpdir}/dist/*" + check-manifest --ignore-bad-ideas '*.mo' {toxinidir} + +[testenv:lint] +skip_install = true +deps = .[codestyle] +commands = + isort --diff --atomic . + black --check . + flake8 . + +[testenv:pyupgrade] +# Run pyupgrade with non-zero exit code (notice `+` at the end of command) +skip_install = true +allowlist_externals = sh +deps = .[codestyle] +commands = + sh -c 'find . -path ./.tox -prune -false -o -name "*.py" -exec pyupgrade --py36-plus \{\} +' + +[testenv:format] +# This env is not run by default. It's provided here for you to easily +# autoformat code by running `tox -e format` +skip_install = true +allowlist_externals = sh +deps = .[codestyle] +commands = + sh -c 'find . -path ./.tox -prune -false -o -name "*.py" -exec pyupgrade --py36-plus \{\} \;' + isort --atomic . + black . + +[flake8] +# Configured to match black +ignore = + E203 + W503 + E731 +max-line-length = 88 +exclude = + migrations + .tox + .git + .eggs + *.egg-info + build + dist