Skip to content

Commit

Permalink
Merge pull request #137 from boxine/dev
Browse files Browse the repository at this point in the history
Project upgrades
  • Loading branch information
jedie authored Dec 22, 2023
2 parents 43c658e + 8142c1b commit dd05cf2
Show file tree
Hide file tree
Showing 15 changed files with 2,341 additions and 902 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ max_line_length = 119
indent_style = tab
insert_final_newline = false

[*.yml]
[{*.yaml,*.yml}]
indent_size = 2
15 changes: 6 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


name: tests

on:
Expand All @@ -17,16 +15,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.11", "3.10", "3.9"]
django-version: ["4.2", "4.1", "3.2"]
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
python-version: ["3.12", "3.11", "3.10"]
django-version: ["5.0", "4.2", "3.2"]
steps:
- name: Checkout
run: |
echo $GITHUB_REF $GITHUB_SHA
git clone --depth 1 https://github.com/$GITHUB_REPOSITORY.git .
git clone https://github.com/$GITHUB_REPOSITORY.git .
git fetch origin $GITHUB_SHA:temporary-ci-branch
git checkout $GITHUB_SHA || (git fetch && git checkout $GITHUB_SHA)
Expand All @@ -53,6 +48,9 @@ jobs:
# ./manage.py safety

- name: 'Python ${{ matrix.python-version }} Django ${{ matrix.django-version }}'
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
run: |
./manage.py tox -e $(echo py${{ matrix.python-version }}-django${{ matrix.django-version }} | tr -d .)
Expand All @@ -62,4 +60,3 @@ jobs:
with:
fail_ci_if_error: false
verbose: true

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.egg-info
__pycache__
/dist/
/build/
/coverage.*
*.orig

Expand Down
4 changes: 1 addition & 3 deletions huey_monitor_project/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@

# _____________________________________________________________________________

if __os.environ.get('AUTOLOGIN') == '1':
if __os.environ.get('AUTOLOGIN') != '0':
# Auto login for dev. server:
MIDDLEWARE = MIDDLEWARE.copy()
MIDDLEWARE += ['django_tools.middlewares.local_auto_login.AlwaysLoggedInAsSuperUserMiddleware']


# _____________________________________________________________________________
# Manage Django Project

INSTALLED_APPS.append('manage_django_project')


# _____________________________________________________________________________
# Django-Debug-Toolbar

Expand Down
4 changes: 2 additions & 2 deletions huey_monitor_project/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
print(f'Generate {__SECRET_FILE}')
from secrets import token_urlsafe as __token_urlsafe

__SECRET_FILE.open('w').write(__token_urlsafe(128))
__SECRET_FILE.write_text(__token_urlsafe(128))

SECRET_KEY = __SECRET_FILE.open('r').read().strip()
SECRET_KEY = __SECRET_FILE.read_text().strip()


# Application definition
Expand Down
3 changes: 3 additions & 0 deletions huey_monitor_project/settings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from huey_monitor_project.settings.prod import * # noqa


ALLOWED_HOSTS = ['testserver']


# Huey Configuration
# ----------------------------------------------------------------------------
HUEY = huey_tests_instance.HUEY
Expand Down
2 changes: 1 addition & 1 deletion huey_monitor_project/test_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def linear_processing_task(task, desc=None, total=2000, no_total=False):
else:
process_info = ProcessInfo(task, desc=desc, total=total)

for i in range(total):
for _ in range(total):
time.sleep(0.1)
process_info.update(n=1)

Expand Down
24 changes: 22 additions & 2 deletions huey_monitor_project/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import os
import unittest.util
from pathlib import Path

from bx_py_utils.test_utils.deny_requests import deny_any_real_request

# Hacky way to expand the failed test output:
unittest.util._MAX_LENGTH = os.environ.get('UNITTEST_MAX_LENGTH', 300)

def pre_configure_tests() -> None:
print(f'Configure unittests via "load_tests Protocol" from {Path(__file__).relative_to(Path.cwd())}')

# Hacky way to display more "assert"-Context in failing tests:
_MIN_MAX_DIFF = unittest.util._MAX_LENGTH - unittest.util._MIN_DIFF_LEN
unittest.util._MAX_LENGTH = int(os.environ.get('UNITTEST_MAX_LENGTH', 300))
unittest.util._MIN_DIFF_LEN = unittest.util._MAX_LENGTH - _MIN_MAX_DIFF

# Deny any request via docket/urllib3 because tests they should mock all requests:
deny_any_real_request()


def load_tests(loader, tests, pattern):
"""
Use unittest "load_tests Protocol" as a hook to setup test environment before running tests.
https://docs.python.org/3/library/unittest.html#load-tests-protocol
"""
pre_configure_tests()
return loader.discover(start_dir=Path(__file__).parent, pattern=pattern)
10 changes: 5 additions & 5 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import hashlib
import shlex
import signal
import subprocess
import sys
Expand All @@ -33,7 +34,7 @@ def print_no_pip_error():
sys.exit(-1)


assert sys.version_info >= (3, 9), 'Python version is too old!'
assert sys.version_info >= (3, 10), f'Python version {sys.version_info} is too old!'


if sys.platform == 'win32': # wtf
Expand All @@ -52,7 +53,7 @@ def print_no_pip_error():
PIP_PATH = BIN_PATH / f'pip{FILE_EXT}'
PIP_SYNC_PATH = BIN_PATH / f'pip-sync{FILE_EXT}'

DEP_LOCK_PATH = BASE_PATH / 'requirements.django42.txt'
DEP_LOCK_PATH = BASE_PATH / 'requirements.dev.txt'
DEP_HASH_PATH = VENV_PATH / '.dep_hash'

# script file defined in pyproject.toml as [console_scripts]
Expand All @@ -78,7 +79,7 @@ def venv_up2date():


def verbose_check_call(*popen_args):
print(f'\n+ {" ".join(str(arg) for arg in popen_args)}\n')
print(f'\n+ {shlex.join(str(arg) for arg in popen_args)}\n')
return subprocess.check_call(popen_args)


Expand All @@ -87,15 +88,14 @@ def noop_sigint_handler(signal_num, frame):
Don't exist cmd2 shell on "Interrupt from keyboard"
e.g.: User stops the dev. server by CONTROL-C
"""
pass


def main(argv):
assert DEP_LOCK_PATH.is_file(), f'File not found: "{DEP_LOCK_PATH}" !'

# Create virtual env in ".venv/":
if not PYTHON_PATH.is_file():
print('Create virtual env here:', VENV_PATH.absolute())
print(f'Create virtual env here: {VENV_PATH.absolute()}')
builder = venv.EnvBuilder(symlinks=True, upgrade=True, with_pip=True)
builder.create(env_dir=VENV_PATH)
# Update pip
Expand Down
16 changes: 10 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"
authors = [
{name = 'Jens Diemer', email = '[email protected]'}
]
requires-python = ">=3.9,<4" # Keep Python 3.9 until Yunohost contains a newer Python Version ;)
requires-python = ">=3.10"
dependencies = [
"huey", # https://github.com/coleifer/huey
"django",
Expand All @@ -18,7 +18,7 @@ dependencies = [
dev = [
"django-redis",
"psycopg2-binary",
"manage_django_project>=0.3.0", # https://github.com/jedie/manage_django_project
"manage_django_project", # https://github.com/jedie/manage_django_project
"django-debug-toolbar", # http://django-debug-toolbar.readthedocs.io/en/stable/changes.html
"colorlog", # https://github.com/borntyping/python-colorlog
"gunicorn", # https://github.com/benoimyproject.wsgitc/gunicorn
Expand All @@ -29,6 +29,7 @@ dev = [
"autopep8", # https://github.com/hhatto/autopep8
"pyupgrade", # https://github.com/asottile/pyupgrade
"flake8", # https://github.com/pycqa/flake8
"flake8-bugbear", # https://github.com/PyCQA/flake8-bugbear
"pyflakes", # https://github.com/PyCQA/pyflakes
"codespell", # https://github.com/codespell-project/codespell
"EditorConfig", # https://github.com/editorconfig/editorconfig-core-py
Expand All @@ -51,8 +52,8 @@ dev = [
"requests-mock",
]
django32=["django>=3.2,<3.3"]
django41=["django>=4.1,<4.2"]
django42=["django>=4.2,<4.3"]
django50=["django>=5.0,<5.1"]

[project.urls]
Documentation = "https://github.com/boxine/django-huey-monitor/"
Expand Down Expand Up @@ -137,7 +138,7 @@ exclude_lines = [
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py{312,311,310,39}-django{42,41,32}
envlist = py{312,311,310}-django{50,42,32}
skip_missing_interpreters = True
[testenv]
Expand All @@ -146,12 +147,12 @@ skip_install = true
commands_pre =
pip install -U pip-tools
django32: pip-sync requirements.django32.txt
django41: pip-sync requirements.django41.txt
django42: pip-sync requirements.django42.txt
django50: pip-sync requirements.django50.txt
commands =
django32: {envpython} -m coverage run --context='{envname}' -m huey_monitor_project test --buffer
django41: {envpython} -m coverage run --context='{envname}' -m huey_monitor_project test --buffer --shuffle --parallel
django42: {envpython} -m coverage run --context='{envname}' -m huey_monitor_project test --buffer --shuffle --parallel
django50: {envpython} -m coverage run --context='{envname}' -m huey_monitor_project test --buffer --shuffle --parallel
"""


Expand All @@ -169,6 +170,9 @@ initial_revision = "53a7e85"
initial_date = 2023-04-10T19:08:56+02:00
cookiecutter_template = "https://github.com/jedie/cookiecutter_templates/"
cookiecutter_directory = "managed-django-project"
applied_migrations = [
"3c16cf7", # 2023-12-21T22:22:06+01:00
]

[manageprojects.cookiecutter_context.cookiecutter]
full_name = "Jens Diemer"
Expand Down
Loading

0 comments on commit dd05cf2

Please sign in to comment.