8000 Fix.cicd (#5) · Gusakovskiy/django-liquidb@8327aa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Fix.cicd (#5)
Browse files Browse the repository at this point in the history
Separate `dev` and `not-dev` dependencies. Migrate to pyproject.toml. Use compiled dependencies. Fix linting and formatting. Drop support for old Django(<3.2) and Python(<3.8) versions
  • Loading branch information
Gusakovskiy authored Oct 27, 2023
1 parent 0d0f13d commit 8327aa7
Show file tree
Hide file tree
Showing 17 changed files with 789 additions and 472 deletions.
6 changes 8000 : 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7.17, 3.8, 3.9]
python-version: [3.8, 3.9, 3.10.13, 3.11, 3.12]

steps:
- uses: actions/checkout@v2
Expand All @@ -26,13 +26,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
python -m pip install --no-cache-dir --no-deps -r requirements-dev.txt
- name: Test with pytest
run: |
pytest
- name: Analyze with pylint
run: |
pylint --load-plugins pylint_django liquidb
pylint --load-plugins=pylint_django --django-settings-module=liquidb.pylint_settings liquidb
- name: Analyze with black
run: |
black --check .
3 changes: 2 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --no-cache-dir --no-deps .
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
python -m build
twine upload dist/*
41 changes: 39 additions & 2 deletions README.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Requirements
============

Django Liquidb requires:
* Django 2.2 or later;
* Python 3.6 or later.
* Django 3.2 or later;
* Python 3.8 or later.


Getting It
Expand Down Expand Up @@ -91,6 +91,43 @@ translation in your language. If you have some time to spare and like to help us

- GitHub: https://github.com/Gusakovskiy/django-liquidb


Development
==========

Generating dependencies
-----------

Main dependencies::

$ pip-compile --upgrade --resolver backtracking --output-file requirements.txt pyproject.toml

Dev dependencies::

$ pip-compile --upgrade --resolver backtracking --extra dev --output-file requirements-dev.txt pyproject.toml

If you see error that you can't figure out try to add `--verbose` flag


After generating dependencies remember to change `backports.zoneinfo==0.2.1` to `backports.zoneinfo;python_version<"3.9"`
this dependency is not supported by Python >= 3.9, it should be deleted after support for those versions is ended.


Configure environment
-----------

In you local machine create virtual environment and activate it or setup docker container and run command::

$ pip install -r requirements-dev.txt

To run test::

$ pytest tests

To run linting::

$ pylint --load-plugins=pylint_django --django-settings-module=liquidb.pylint_settings liquidb

Support
=======

Expand Down
10 changes: 5 additions & 5 deletions liquidb/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from django.core.checks import messages
Expand All @@ -18,15 +18,16 @@


class SnapshotAdminModelForm(ModelForm):
def _create_snapshot(self, name: str, dry_run: bool): # pylint: disable=no-self-use
@staticmethod
def _create_snapshot(name: str, dry_run: bool):
handler = SnapshotCreationHandler(
name,
False,
)
try:
created = handler.create(dry_run=dry_run)
except SnapshotHandlerException as error:
raise ValidationError(error.error, code="name")
raise ValidationError(error.error, code="name") from error
if not created:
raise ValidationError(
"All migrations saved in currently applied snapshot. Nothing to create",
Expand Down Expand Up @@ -82,7 +83,6 @@ def has_delete_permission(self, request, obj=None):

@admin.register(Snapshot)
class SnapshotAdminView(ModelAdmin):

form = SnapshotAdminModelForm
readonly_fields = (
"created",
Expand Down Expand Up @@ -123,7 +123,7 @@ def get_urls(self):
custom_urls = []
if ADMIN_SNAPSHOT_ACTIONS:
custom_urls.append(
url(
re_path(
r"^(?P<snapshot_id>.+)/apply/$",
self.admin_site.admin_view(self.apply_snapshot),
name="apply_snapshot",
Expand Down
6 changes: 3 additions & 3 deletions liquidb/db_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _checkout_to_snapshot(self, snapshot: Snapshot):
executor = MigrationExecutor(connection)
try:
_: ProjectState = executor.migrate(targets)
except KeyError:
except KeyError as error:
# TODO check exact migration that missing
message = "\n".join(
[
Expand All @@ -58,9 +58,9 @@ def _checkout_to_snapshot(self, snapshot: Snapshot):
f"\nSome migrations are missing.\n"
f'Please make sure all migrations in snapshot: "{snapshot.name}";\n'
f"Are present in corresponding apps: \n{message}"
)
) from error
except NodeNotFoundError as error:
raise SnapshotHandlerException(error.message)
raise SnapshotHandlerException(error.message) from error

@property
def applied_snapshot_exists(self):
Expand Down
6 changes: 3 additions & 3 deletions liquidb/management/commands/_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.db import connection
from django.db.migrations.recorder import MigrationRecorder

from ...db_tools import SnapshotCheckoutHandler, SnapshotHandlerException
from ...models import Snapshot, MigrationState, get_latest_applied_migrations_qs
from liquidb.db_tools import SnapshotCheckoutHandler, SnapshotHandlerException
from liquidb.models import Snapshot, MigrationState, get_latest_applied_migrations_qs


class BaseLiquidbCommand(BaseCommand, metaclass=ABCMeta):
Expand Down Expand Up @@ -68,7 +68,7 @@ def _checkout_snapshot(self, snapshot: Snapshot, force=False):
try:
handler.checkout(force=force)
except SnapshotHandlerException as e:
raise CommandError(e.error)
raise CommandError(e.error) from e

@abstractmethod
def _handle(self, *args, **options):
Expand Down
2 changes: 1 addition & 1 deletion liquidb/management/commands/create_migration_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _handle(self, *args, **options):
try:
created = handler.create()
except SnapshotHandlerException as e:
raise CommandError(e.error)
raise CommandError(e.error) from e
if not created:
self.stdout.write(
"All migrations saved in currently applied snapshot. Nothing to create"
Expand Down
5 changes: 3 additions & 2 deletions liquidb/management/commands/delete_snapshot_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _handle(self, *args, **options):
interactive = options["interactive"]
if interactive:
confirm = input(
f"""
"""
You have requested to delete snapshot history with all migrations.
This action is IRREVERSIBLE.
Are you sure you want to do this?
Expand All @@ -37,5 +37,6 @@ def _handle(self, *args, **options):
snapshots = models.get("liquidb.Snapshot", 0)
migrations_states = models.get("liquidb.MigrationState", 0)
self.stdout.write(
f"Successfully deleted history of {snapshots} snapshots and {migrations_states} migrations"
f"Successfully deleted history of {snapshots} "
f"snapshots and {migrations_states} migrations"
)
1 change: 0 additions & 1 deletion liquidb/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
58 changes: 58 additions & 0 deletions liquidb/pylint_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from pathlib import Path

SECRET_KEY = "fake-key"

INSTALLED_APPS = [
# <editor-fold desc="admin part">
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
# </editor-fold>
"tests",
"liquidb",
]
# <editor-fold desc="Needed for Admin Part">
BASE_DIR = Path(__file__).resolve().parent.parent

MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
ROOT_URLCONF = "tests.test_urls"
# </editor-fold>

DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
USE_TZ = True


LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"root": {
"handlers": ["console"],
"level": "WARNING",
},
}
Loading

0 comments on commit 8327aa7

Please sign in to comment.
0