Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with Github CI #1413

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test & Docs

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
tests:
timeout-minutes: 60
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:12-2.5
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
dependencies: [normal, minimal]
database: [postgresql]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Change dependencies to minimal supported versions
run: sed -i -e '/requires-python/!s/>=/==/g; /requires-python/!s/~=.*==\(.*\)/==\1/g; /requires-python/!s/~=/==/g;' pyproject.toml
if: matrix.dependencies == 'minimal'
- name: Install dependencies
run: |
sudo apt update
sudo apt install libgdal-dev
python -m pip install --upgrade pip
make develop installjs vendors
- name: run tests
run: make test
env:
DJANGO_SETTINGS_MODULE: 'umap.tests.settings'
UMAP_SETTINGS: 'umap/tests/settings.py'
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python3 -m pip install -e .[test,dev]

- name: Run Lint
run: make lint

- name: Run Docs
run: make docs
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ umap/settings/local/*
docs/_build
umap/remote_static
tmp/*
node_modules/*
umap/static/umap/vendors
site/*
.pytest_cache/
node_modules
umap.conf
data

### Python ###
# Byte-compiled / optimized / DLL files
Expand Down
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ develop: ## Install the test and dev dependencies
python3 -m pip install -e .[test,dev]
playwright install

.PHONY: pretty-templates
pretty-templates: ## Prettify template files
djlint umap/templates --reformat

.PHONY: lint-templates
lint-templates: ## Lint template files
djlint umap/templates --lint
.PHONY: format
format: ## Format the code and templates files
djlint umap/templates --reformat &&\
isort --profile black . &&\
ruff format --target-version=py38 .

.PHONY: lint
lint: ## Lint the code and template files
djlint umap/templates --lint &&\
isort --check --profile black . &&\
ruff format --check --target-version=py38 . &&\
vermin --no-tips --violations -t=3.8- .

docs: ## Compile the docs
mkdocs build

.PHONY: version
version: ## Display the current version
Expand Down Expand Up @@ -47,10 +55,10 @@ publish: ## Publish the Python package to Pypi
make clean

test:
py.test -xv umap/tests/
pytest -xv umap/tests/

test-integration:
py.test -xv umap/tests/integration/
pytest -xv umap/tests/integration/

clean:
rm -f dist/*
Expand Down
5 changes: 1 addition & 4 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"umap.settings"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings")

from django.core.management import execute_from_command_line

Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"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",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"Django>=4.1",
"Django>=4.2,<5",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite fails otherwise with Django 4.1 (see #1426)

"django-agnocomplete==2.2.0",
"django-compressor==4.3.1",
"django-environ==0.10.0",
Expand All @@ -47,17 +45,20 @@ dependencies = [
[project.optional-dependencies]
dev = [
"hatch==1.7.0",
"black==23.3.0",
"ruff==0.1.6",
"djlint==1.31.0",
"mkdocs==1.5.2",
"vermin==1.5.2",
"pymdown-extensions==10.4",
"isort==5.12",
]
test = [
"factory-boy==3.2.1",
"playwright==1.38.0",
"playwright>=1.39,<2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to be able to support python 3.12.

"pytest==6.2.5",
"pytest-django==4.5.2",
"pytest-playwright==0.4.2",

"pytest-playwright>=0.4.3,<1",
"pytest-xdist>=3.5.0,<4",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useful to speedup the tests.

]
docker = [
"uwsgi==2.0.21",
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
DJANGO_SETTINGS_MODULE=umap.tests.settings
addopts = --pdbcls=IPython.terminal.debugger:Pdb --no-migrations
addopts = --pdbcls=IPython.terminal.debugger:Pdb --no-migrations --numprocesses auto
10 changes: 7 additions & 3 deletions umap/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from django.contrib.gis import admin
from .models import Map, DataLayer, Pictogram, TileLayer, Licence

from .models import DataLayer, Licence, Map, Pictogram, TileLayer


class TileLayerAdmin(admin.ModelAdmin):
list_display = ('name', 'rank', )
list_editable = ('rank', )
list_display = (
"name",
"rank",
)
list_editable = ("rank",)


class MapAdmin(admin.GISModelAdmin):
Expand Down
8 changes: 3 additions & 5 deletions umap/autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from agnocomplete.core import AgnocompleteModel
from agnocomplete.register import register
from django.conf import settings
from django.contrib.auth import get_user_model


from agnocomplete.register import register
from agnocomplete.core import AgnocompleteModel


@register
class AutocompleteUser(AgnocompleteModel):
model = get_user_model()
fields = settings.USER_AUTOCOMPLETE_FIELDS

def item(self, current_item):
data = super().item(current_item)
data['url'] = current_item.get_url()
data["url"] = current_item.get_url()
return data
7 changes: 2 additions & 5 deletions umap/bin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@


def main():
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"umap.settings"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings")
management.execute_from_command_line()


if __name__ == '__main__':
if __name__ == "__main__":
main()
9 changes: 4 additions & 5 deletions umap/decorators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from functools import wraps

from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404
from django.http import HttpResponseForbidden
from django.conf import settings
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy

from .views import simple_json_response
from .models import Map

from .views import simple_json_response

LOGIN_URL = getattr(settings, "LOGIN_URL", "login")
LOGIN_URL = reverse_lazy(LOGIN_URL) if not LOGIN_URL.startswith("/") else LOGIN_URL
Expand Down
10 changes: 5 additions & 5 deletions umap/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django import forms
from django.contrib.gis.geos import Point
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _
from django.template.defaultfilters import slugify
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.gis.geos import Point
from django.forms.utils import ErrorList
from django.template.defaultfilters import slugify
from django.utils.translation import gettext_lazy as _

from .models import Map, DataLayer
from .models import DataLayer, Map

DEFAULT_LATITUDE = (
settings.LEAFLET_LATITUDE if hasattr(settings, "LEAFLET_LATITUDE") else 51
Expand Down
20 changes: 9 additions & 11 deletions umap/management/commands/generate_js_locale.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
from pathlib import Path

from django.core.management.base import BaseCommand
from django.conf import settings
from django.core.management.base import BaseCommand
from django.template.loader import render_to_string
from django.utils.translation import to_locale

ROOT = Path(settings.PROJECT_DIR) / 'static/umap/locale/'
ROOT = Path(settings.PROJECT_DIR) / "static/umap/locale/"


class Command(BaseCommand):

def handle(self, *args, **options):
self.verbosity = options['verbosity']
self.verbosity = options["verbosity"]
for code, name in settings.LANGUAGES:
code = to_locale(code)
if self.verbosity > 0:
print("Processing", name)
path = ROOT / '{code}.json'.format(code=code)
path = ROOT / "{code}.json".format(code=code)
if not path.exists():
print(path, 'does not exist.', 'Skipping')
print(path, "does not exist.", "Skipping")
else:
with path.open(encoding="utf-8") as f:
if self.verbosity > 1:
print("Found file", path)
self.render(code, f.read())

def render(self, code, json):
path = ROOT / '{code}.js'.format(code=code)
path = ROOT / "{code}.js".format(code=code)
with path.open("w", encoding="utf-8") as f:
content = render_to_string('umap/locale.js', {
"locale": json,
"locale_code": code
})
content = render_to_string(
"umap/locale.js", {"locale": json, "locale_code": code}
)
if self.verbosity > 1:
print("Exporting to", path)
f.write(content)
Loading