Skip to content

Commit

Permalink
Merge pull request #92 from jedie/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jedie authored Dec 17, 2023
2 parents 2fa1682 + 58a48dc commit e94046d
Show file tree
Hide file tree
Showing 16 changed files with 957 additions and 538 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ max_line_length = 119
indent_style = tab
insert_final_newline = false

[*.yml]
[{*.yaml,*.yml}]
indent_size = 2
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.11", "3.10", "3.9"]
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
steps:
- name: Checkout
run: |
Expand Down Expand Up @@ -50,6 +47,9 @@ jobs:
./manage.py safety
- name: 'Run tests with Python v${{ matrix.python-version }}'
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
run: |
./manage.py coverage
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
*.egg-info
__pycache__
/dist/
/coverage.json
/coverage.xml
/coverage.*
*.orig

!.github
!.editorconfig
!.flake8
!.gitignore
!.gitkeep

# for django-dbbackup
/backups/
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ Because this is a project and not really a reuse-able-app ;)

[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [**dev**](https://github.com/jedie/django-for-runners/compare/v0.17.4...main)
* 2023-12-17 - Use cli_base.cli_tools.git_history.update_readme_history()
* 2023-12-17 - Update requirements ; TODO: Update to Django 5.0
* 2023-12-17 - Code style fixes
* 2023-12-17 - Apply manageprojects updates
* [v0.17.4](https://github.com/jedie/django-for-runners/compare/v0.17.3...v0.17.4)
* 2023-11-07 - audo generate README history
* 2023-11-07 - Update Requirements
Expand All @@ -233,12 +238,12 @@ Because this is a project and not really a reuse-able-app ;)
* [v0.17.2](https://github.com/jedie/django-for-runners/compare/v0.17.1...v0.17.2)
* 2023-04-02 - release 0.17.2
* 2023-04-02 - Bugfix adding all template files
* [v0.17.1](https://github.com/jedie/django-for-runners/compare/v0.17.0...v0.17.1)
* 2023-04-02 - Bugfix packaging and missing files
* 2023-04-02 - update link to https://github.com/kbr/autotask

<details><summary>Expand older history entries ...</summary>

* [v0.17.1](https://github.com/jedie/django-for-runners/compare/v0.17.0...v0.17.1)
* 2023-04-02 - Bugfix packaging and missing files
* 2023-04-02 - update link to https://github.com/kbr/autotask
* [v0.17.0](https://github.com/jedie/django-for-runners/compare/v0.16.0...v0.17.0)
* 2023-04-02 - Bugfix edit a `GpxModel` instance in admin with a large GPX track
* 2023-04-02 - Bugfix manage call and merge project test code
Expand Down
2 changes: 1 addition & 1 deletion for_runners/gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def iter_coordinates(gpxpy_instance):
def get_2d_coordinate_list(gpxpy_instance):
lat_list = []
lon_list = []
for latitude, longitude, elevation in iter_coordinates(gpxpy_instance):
for latitude, longitude, _elevation in iter_coordinates(gpxpy_instance):
lat_list.append(latitude)
lon_list.append(longitude)

Expand Down
2 changes: 1 addition & 1 deletion for_runners/gpx_tools/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def human_duration(t):
if t < 60 * 60:
return _("%.1f min") % round(t / 60, 1)

for seconds, name in chunks:
for seconds, name in chunks: # noqa: B007
count = t / seconds
if count >= 1:
count = round(count, 1)
Expand Down
5 changes: 4 additions & 1 deletion for_runners/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ def generate_gpx_track(
point_count,
pace_min,
start_longitude=0,
start_date=datetime(2018, 5, 30, 10, 00),
start_date=None,
):
if start_date is None:
start_date = datetime(2018, 5, 30, 10, 00)

distance_km = track_length_km / point_count
print("km between points:", distance_km)

Expand Down
2 changes: 1 addition & 1 deletion for_runners_project/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Download map via geotiler in for_runners.gpx_tools.gpxpy2map.generate_map
MAP_DOWNLOAD = True

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']
Expand Down
13 changes: 8 additions & 5 deletions for_runners_project/settings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from for_runners_project.settings.prod import * # noqa


# _____________________________________________________________________________
# Manage Django Project

INSTALLED_APPS.append('manage_django_project')

# _____________________________________________________________________________


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
Expand Down Expand Up @@ -45,8 +53,3 @@ def _unmocked_requests_error_message(request, response):
# Set root to not existing path, so that wrong tests will fail:
STATIC_ROOT = '/not/exists/static/'
MEDIA_ROOT = '/not/exists/media/'

# _____________________________________________________________________________
# Manage Django Project

INSTALLED_APPS.append('manage_django_project')
26 changes: 26 additions & 0 deletions for_runners_project/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import unittest.util
from pathlib import Path

from bx_py_utils.test_utils.deny_requests import deny_any_real_request


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)
12 changes: 9 additions & 3 deletions for_runners_project/tests/test_project_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def test_template_dirs(self):
def test_cache(self):
# django cache should work in tests, because some tests "depends" on it
cache_key = 'a-cache-key'
assert cache.get(cache_key) is None
self.assertIs(cache.get(cache_key), None)
cache.set(cache_key, 'the cache content', timeout=1)
assert cache.get(cache_key) == 'the cache content'
self.assertEqual(cache.get(cache_key), 'the cache content', f'Check: {settings.CACHES=}')
cache.delete(cache_key)
assert cache.get(cache_key) is None
self.assertIs(cache.get(cache_key), None)

def test_settings(self):
self.assertEqual(settings.SETTINGS_MODULE, 'for_runners_project.settings.tests')
Expand Down Expand Up @@ -67,6 +67,12 @@ def test_manage(self):
self.assertIn('for_runners_project.settings.tests', output)
self.assertIn(__version__, output)

output = subprocess.check_output([manage_bin, 'check'], text=True)
self.assertIn('System check identified no issues (0 silenced).', output)

output = subprocess.check_output([manage_bin, 'makemigrations'], text=True)
self.assertIn("No changes detected", output)

def test_code_style(self):
call_command(code_style.Command())

Expand Down
30 changes: 10 additions & 20 deletions for_runners_project/tests/test_readme_history.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
from pathlib import Path
from unittest import TestCase
import os
from unittest import TestCase, skipIf

from bx_py_utils.auto_doc import assert_readme_block
from cli_base.cli_tools.git_history import get_git_history

import for_runners


PACKAGE_ROOT = Path(for_runners.__file__).parent.parent
from cli_base.cli_tools.git_history import update_readme_history


class ReadmeHistoryTestCase(TestCase):
@skipIf(
# After a release the history may be "changed" because of version bump
# and we should not block merge requests because of this.
'GITHUB_ACTION' in os.environ,
'Skip on github actions',
)
def test_readme_history(self):
git_history = get_git_history(
current_version=for_runners.__version__,
add_author=False,
)
history = '\n'.join(git_history)
assert_readme_block(
readme_path=PACKAGE_ROOT / 'README.md',
text_block=f'\n{history}\n',
start_marker_line='[comment]: <> (✂✂✂ auto generated history start ✂✂✂)',
end_marker_line='[comment]: <> (✂✂✂ auto generated history end ✂✂✂)',
)
update_readme_history(raise_update_error=True)
13 changes: 12 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import hashlib
import signal
import subprocess
import sys
import venv
Expand Down Expand Up @@ -81,6 +82,14 @@ def verbose_check_call(*popen_args):
return subprocess.check_call(popen_args)


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}" !'

Expand All @@ -104,9 +113,11 @@ def main(argv):
verbose_check_call(PIP_PATH, 'install', '--no-deps', '-e', '.')
store_dep_hash()

signal.signal(signal.SIGINT, noop_sigint_handler) # ignore "Interrupt from keyboard" signals

# Call our entry point CLI:
try:
verbose_check_call(PROJECT_SHELL_SCRIPT, *sys.argv[1:])
verbose_check_call(PROJECT_SHELL_SCRIPT, *argv[1:])
except subprocess.CalledProcessError as err:
sys.exit(err.returncode)

Expand Down
13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "django-for-runners"
dynamic = ["version"]
description = "Store your GPX tracks of your running (or other sports activity) in django."
license = {text = "GPL-3.0-or-later"}
readme = "README.md"
authors = [
{name = 'Jens Diemer', email = '[email protected]'}
Expand All @@ -11,7 +12,7 @@ dependencies = [
"colorlog", # https://github.com/borntyping/python-colorlog
"gunicorn", # https://github.com/benoimyproject.wsgitc/gunicorn

"django",
"django>=4.2,<4.3", # TODO: Update to Django v5.0 !
"django-processinfo", # https://github.com/jedie/django-processinfo/
"django-debug-toolbar", # http://django-debug-toolbar.readthedocs.io/en/stable/changes.html
"django-tools", # https://github.com/jedie/django-tools/
Expand All @@ -38,14 +39,15 @@ dependencies = [
]
[project.optional-dependencies]
dev = [
"manage_django_project>=0.3.0rc0", # https://github.com/jedie/manage_django_project
"manage_django_project>=0.6.4", # https://github.com/jedie/manage_django_project
"tblib", # https://github.com/ionelmc/python-tblib
"pip-tools", # https://github.com/jazzband/pip-tools/
"tox", # https://github.com/tox-dev/tox
"coverage", # https://github.com/nedbat/coveragepy
"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 Down Expand Up @@ -80,6 +82,7 @@ Source = "https://github.com/jedie/django-for-runners"


[project.scripts]
# Must be set in ./manage.py and PROJECT_SHELL_SCRIPT:
for_runners_project = "for_runners_project.__main__:main"

[manage_django_project]
Expand All @@ -104,6 +107,10 @@ include = ["for_runners*", "for_runners_project*"]
version = {attr = "for_runners.__version__"}


[tool.cli_base]
version_module_name = "for_runners" # Used by update_readme_history()


[tool.darker]
src = ['.']
revision = "origin/main..."
Expand Down Expand Up @@ -191,13 +198,15 @@ applied_migrations = [
"89aadc0", # 2023-03-17T09:44:50+01:00
"2281f4b", # 2023-04-02T17:40:58+02:00
"10c547a", # 2023-04-04T20:37:52+02:00
"d65b082", # 2023-12-17T12:51:22+01:00
]

[manageprojects.cookiecutter_context.cookiecutter]
full_name = "Jens Diemer"
github_username = "jedie"
author_email = "[email protected]"
package_name = "for_runners"
project_name = "django-for-runners"
package_version = "0.16.0rc2"
package_description = "Store your GPX tracks of your running (or other sports activity) in django."
package_url = "https://github.com/jedie/django-for-runners"
Expand Down
Loading

0 comments on commit e94046d

Please sign in to comment.