From 6ae6222b398ef04776edce3962ba16a856a40156 Mon Sep 17 00:00:00 2001 From: olivierdalang Date: Wed, 13 Sep 2023 12:25:26 +0200 Subject: [PATCH 1/3] modern python packaging using pyproject.toml --- .editorconfig | 3 ++ .github/workflows/pypi.yml | 14 ++------ .gitignore | 2 +- Dockerfile | 13 ++++---- MANIFEST.in | 3 +- README.md | 4 +-- django_toosimple_q/__init__.py | 1 - docker-compose.yml | 5 ++- pyproject.toml | 46 +++++++++++++++++++++++++++ requirements-dev.txt | 10 ------ requirements.txt | 3 -- scripts/ci_assert_version_from_git.py | 14 -------- scripts/ci_set_version_from_git.py | 12 ------- setup.py | 41 ------------------------ 14 files changed, 63 insertions(+), 108 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements-dev.txt delete mode 100644 requirements.txt delete mode 100644 scripts/ci_assert_version_from_git.py delete mode 100644 scripts/ci_set_version_from_git.py delete mode 100644 setup.py diff --git a/.editorconfig b/.editorconfig index f9366fa..e1f5f10 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,6 @@ indent_size = 4 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[*.{yml,yaml,html}] +indent_size = 2 diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 78b7cb0..4b7f498 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -15,19 +15,9 @@ jobs: with: python-version: '3.7' - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Set version - env: - GITHUB_TAG: ${{github.ref}} - run: python scripts/ci_set_version_from_git.py + run: python -m pip install --upgrade pip twine build - name: Build - run: python setup.py sdist bdist_wheel - - name: Assert version - env: - GITHUB_TAG: ${{github.ref}} - run: python scripts/ci_assert_version_from_git.py + run: python -m build - name: Publish env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} diff --git a/.gitignore b/.gitignore index 52d4844..d4dcaba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ __pycache__ .vscode *.egg-info *.sqlite3 -build dist +django_toosimple_q/__version__.py diff --git a/Dockerfile b/Dockerfile index 1571ec0..f45cddf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,12 @@ FROM python:$TOOSIMPLEQ_PY_VERSION WORKDIR /app -# Install app in editable mode -ADD ./requirements.txt /app/requirements.txt -ADD ./requirements-dev.txt /app/requirements-dev.txt -RUN touch /app/README.md -ADD ./django_toosimple_q/__init__.py /app/django_toosimple_q/__init__.py -ADD ./setup.py /app/setup.py -RUN pip install -r requirements-dev.txt +# Install empty project (source added/mounted later) +ENV SETUPTOOLS_SCM_PRETEND_VERSION 0.0.0 +ADD pyproject.toml ./ +RUN touch README.md +RUN mkdir django_toosimple_q +RUN pip install -e .[dev] # Override django version ARG TOOSIMPLEQ_DJ_VERSION diff --git a/MANIFEST.in b/MANIFEST.in index 38edd58..e634e0c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1 @@ -recursive-include django_toosimple_q * -recursive-exclude django_toosimple_q *.pyc +prune django_toosimple_q/tests diff --git a/README.md b/README.md index 884499e..6cd4a19 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ Then connect on 127.0.0.1:8000/admin/ To run tests locally without Docker (by default, tests runs against an in-memory sqlite database): ```shell -pip install -r requirements-dev.txt +pip install -e .[dev] python manage.py test ``` @@ -338,7 +338,7 @@ python manage.py test Code style is done with pre-commit : ```shell -pip install -r requirements-dev.txt +pip install -e .[dev] pre-commit install ``` diff --git a/django_toosimple_q/__init__.py b/django_toosimple_q/__init__.py index b7e977b..c177817 100644 --- a/django_toosimple_q/__init__.py +++ b/django_toosimple_q/__init__.py @@ -1,2 +1 @@ -__version__ = "dev" # DO NOT CHANGE THIS LINE - it will be replaced by CI workflow default_app_config = "django_toosimple_q.apps.DjangoToosimpleQConfig" diff --git a/docker-compose.yml b/docker-compose.yml index 89d2730..4bc36b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,7 @@ version: "3" -x-default-django: - &default-django +x-default-django: &default-django build: context: . args: @@ -31,7 +30,7 @@ services: worker: <<: *default-django - command: worker --queue demo --reload never + command: worker --queue demo postgres: image: postgres diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..bf67ed8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +[build-system] +requires = ["setuptools>=61.0", "setuptools-scm[toml]>=7.1"] +build-backend = "setuptools.build_meta" + +[project] +requires-python = ">=3.6" +name = "django-toosimple-q" +authors = [{ name = "Olivier Dalang", email = "olivier.dalang@gmail.com" }] +description = "A simplistic task queue and cron-like scheduler for Django" +keywords = ["django", "task", "queue", "worker", "scheduler", "cron", "job"] +classifiers = [ + "Development Status :: 4 - Beta", + "Framework :: Django", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +license = { text = "MIT License" } +dynamic = ["version", "readme"] +dependencies = [ + "django>=3.2", + "django-picklefield>=3.0", + "croniter>=1.3", +] + +[project.optional-dependencies] +dev = [ + # tests + "freezegun==1.2.1", + "psycopg2==2.*", + # devenv + "pre-commit", + "mypy", +] + +[project.urls] +homepage = "https://github.com/olivierdalang/django-toosimple-q" +repository = "https://github.com/olivierdalang/django-toosimple-q" +tracker = "https://github.com/olivierdalang/django-toosimple-q/issues" + +[tool.setuptools_scm] +version_scheme = "post-release" +write_to = "django_toosimple_q/__version__.py" + +[tool.setuptools.dynamic] +readme = { file = ["README.md"], content-type = "text/markdown" } diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index f2284e8..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,10 +0,0 @@ -# tests -freezegun==1.2.1 -psycopg2==2.* - -# devenv -pre-commit -mypy - -# django-toosimple-q --e . diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e1a9323..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -django>=3.2 -django-picklefield>=3.0 -croniter>=1.3 diff --git a/scripts/ci_assert_version_from_git.py b/scripts/ci_assert_version_from_git.py deleted file mode 100644 index 07f4dde..0000000 --- a/scripts/ci_assert_version_from_git.py +++ /dev/null @@ -1,14 +0,0 @@ -import os -import sys - -basedir = os.path.dirname(os.path.dirname(__file__)) -sys.path.append(basedir) - -import django_toosimple_q # noqa - -version = django_toosimple_q.__version__ -tag = os.getenv("GITHUB_TAG") - -assert ( - f"refs/heads/{version}" == tag or f"refs/tags/{version}" == tag -), f"Version mismatch : {version} != {tag}" diff --git a/scripts/ci_set_version_from_git.py b/scripts/ci_set_version_from_git.py deleted file mode 100644 index 55ef0c3..0000000 --- a/scripts/ci_set_version_from_git.py +++ /dev/null @@ -1,12 +0,0 @@ -import os - -basedir = os.path.dirname(os.path.dirname(__file__)) - -name = os.getenv("GITHUB_TAG").split("/")[2] -path = os.path.join(basedir, "django_toosimple_q", "__init__.py") - -# read file -contents = open(path, "r").read() - -# replace contents -open(path, "w").write(contents.replace("dev", name, 1)) diff --git a/setup.py b/setup.py deleted file mode 100644 index a49eff2..0000000 --- a/setup.py +++ /dev/null @@ -1,41 +0,0 @@ -import os -import re - -from setuptools import find_packages, setup - - -def get_version(*file_paths): - """Retrieves the version from django_toosimple_q/__init__.py""" - filename = os.path.join(os.path.dirname(__file__), *file_paths) - version_file = open(filename).read() - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) - if version_match: - return version_match.group(1) - raise RuntimeError("Unable to find version string.") - - -setup( - name="django-toosimple-q", - version=get_version("django_toosimple_q", "__init__.py"), - description="""A simplistic task queue and cron-like scheduler for Django""", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - author="Olivier Dalang", - author_email="olivier.dalang@gmail.com", - url="https://github.com/olivierdalang/django-toosimple-q", - packages=find_packages(include=["django_toosimple_q", "django_toosimple_q.*"]), - include_package_data=True, - install_requires=open("requirements.txt").readlines(), - license="MIT", - zip_safe=False, - keywords="django-toosimple-q", - classifiers=[ - "Development Status :: 3 - Alpha", - "Framework :: Django :: 2.2", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Natural Language :: English", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - ], -) From 7e4597c285125da955340cf3d5228ef17867c74c Mon Sep 17 00:00:00 2001 From: olivierdalang Date: Wed, 13 Sep 2023 13:05:02 +0200 Subject: [PATCH 2/3] cd: build using recent python --- .github/workflows/pypi.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 4b7f498..67e4591 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -10,10 +10,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: '3.7' - name: Install dependencies run: python -m pip install --upgrade pip twine build - name: Build From 08972e6c549b05c4e94a8aa86cf7e5a0beb6ccb7 Mon Sep 17 00:00:00 2001 From: olivierdalang Date: Wed, 13 Sep 2023 13:18:51 +0200 Subject: [PATCH 3/3] update pip in the dockerfile still doesn't work in 3.6 but at least we see the error --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index f45cddf..806b28e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ ARG TOOSIMPLEQ_PY_VERSION FROM python:$TOOSIMPLEQ_PY_VERSION +RUN pip install --upgrade pip + WORKDIR /app # Install empty project (source added/mounted later)