Skip to content

Commit

Permalink
Projectsetup (#6)
Browse files Browse the repository at this point in the history
* Make project compatible with pip and buildout.

Add optional extras for running tests and development.

* lint

* try to fix build

* fix build?

* wop

* install test dependencies

* allow old python
  • Loading branch information
specialunderwear authored Dec 20, 2023
1 parent fc15664 commit bd365b7
Show file tree
Hide file tree
Showing 13 changed files with 1,390 additions and 179 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
python -m pip install --upgrade pip
pip install .[test]
poetry install --all-extras --no-root
- name: Check code quality
run: |
poetry run black --check oscar_odin/
poetry run pylint oscar_odin/
- name: Test with Django test runner
run: |
poetry run coverage run --branch -- ./runtests.py
poetry run coverage run --branch -- ./manage.py test
poetry run coverage xml --include="oscar_odin/*" -o dist/coverage.xml
poetry run coverage report --include="oscar_odin/*"
48 changes: 18 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.8
python: python3.10


repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- --py38-plus
- --keep-runtime-typing
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: local
hooks:
- id: black
name: black
language: system
types: [python]
entry: black
args: [--check, oscar_odin/]
pass_filenames: false
- id: pylint
name: pylint
entry: pylint
args: [oscar_odin/]
language: system
types: [python]
pass_filenames: false
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: fail-if-no-virtualenv all install lint test black
.PHONY: fail-if-no-virtualenv all install dev lint test black

all: install migrate loaddata collectstatic

Expand All @@ -14,16 +14,19 @@ PIP_INDEX_URL=https://pypi.org/simple
endif


dev: install
pip install .[dev]

install: fail-if-no-virtualenv
pip install poetry
poetry install
pip install .[test]

lint: fail-if-no-virtualenv
black --check oscar_odin/**/*.py
black --check oscar_odin/
pylint oscar_odin/

test: fail-if-no-virtualenv
python3 runtests.py test tests.reverse.test_catalogue
python3 manage.py makemigrations --check --dry-run
@python3 manage.py test tests/

black:
@black oscar_odin/
Expand All @@ -32,5 +35,5 @@ black:
ill:
rm db.sqlite3
cp klaas.sqlite3 db.sqlite3
python3 runtests.py migrate
python3 runtests.py test_illshit
python3 manage.py migrate
python3 manage.py test_illshit
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ product = Product.objects.get(id=1)
product_resource = catalogue.product_to_resource(product)
```

# run tests
# Developing odin

## Using pip:

make install
make tests
make test

## Using poetry:

poetry install --all-extras
poetry run ./manage.py test
2 changes: 1 addition & 1 deletion runtests.py → manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import django
from django.conf import settings
from django.test.utils import get_runner


if __name__ == "__main__":
# Configure path and django settings module
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def tests(session: Session):
)
# fmt: on
session.install("-Ur", "requirements.txt")
session.run(HERE / "runtests.py")
session.run(HERE / "manage.py")
1 change: 1 addition & 0 deletions oscar_odin/django_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class ModelFieldResolver(FieldResolverBase):
"""Field resolver for Django models."""

# pylint: disable=protected-access
def get_field_dict(self) -> Dict[str, Optional[Field]]:
"""Get a dictionary of fields from the source object."""
meta = getmeta(self.obj)
Expand Down
2 changes: 1 addition & 1 deletion oscar_odin/management/commands/test_illshit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# pylint: disable=W0611
import io
import PIL

from decimal import Decimal as D

from django.core.management.base import BaseCommand
from django.core.files import File
from django.test import TestCase
from oscar.core.loading import get_model

from oscar_odin.mappings.catalogue import products_to_db
Expand Down
1 change: 0 additions & 1 deletion oscar_odin/resources/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from oscar.core.loading import get_model

import odin
from odin.annotated_resource.type_aliases import Url

from ..fields import DecimalField
from ._base import OscarResource
Expand Down
1 change: 0 additions & 1 deletion oscar_odin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.db import connection, reset_queries

from typing import Any, Tuple, NamedTuple
from collections import defaultdict

from django.db.models import Model, ManyToManyField, ForeignKey, Q
Expand Down
Loading

0 comments on commit bd365b7

Please sign in to comment.