Skip to content

Commit

Permalink
black, pre-commit, ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Jan 22, 2024
1 parent aa94a0b commit dce8aca
Show file tree
Hide file tree
Showing 38 changed files with 580 additions and 106 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: CI

on: [push, pull_request, ]
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8, 3.9, "3.10", "3.11"]
python: [3.8, 3.9, "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python }}
Expand Down Expand Up @@ -39,21 +39,20 @@ jobs:
# run: tox -e py${{ matrix.python }}-${{ matrix.django }}
run: tox -e py39-django32-coverage


lint:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.9]
python: [3.12]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install flake8
run: pip install flake8
- name: Run flake8
- name: pre-commit
run: pip install pre-commit
- name: Run pre-commit
# Run tox using the version of Python in `PATH`
# run: tox -e py${{ matrix.python }}-${{ matrix.django }}
run: flake8
run: pre-commit run --all-files
37 changes: 18 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
name: Release on PYPI
on:
push:
branches: [main]

branches: [main]

jobs:
build-and-publish:
runs-on: ubuntu-latest
if: github.repository == 'bnzk/django-postgres-searchindex'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel twine
- name: Build
run: |
python setup.py sdist
python setup.py bdist_wheel --universal
- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER_BNZK }}
TWINE_PASSWORD: ${{ secrets.PYPI_PW_BNZK }}
run: twine upload dist/*
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel twine
- name: Build
run: |
python setup.py sdist
python setup.py bdist_wheel --universal
- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER_BNZK }}
TWINE_PASSWORD: ${{ secrets.PYPI_PW_BNZK }}
run: twine upload dist/*
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ coverage.xml

# Sphinx documentation
docs/_build/

61 changes: 61 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "^package.json|^package-lock.json"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# syntax
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-xml
- id: pretty-format-json
args: ["--autofix"]
# git & filesystem
- id: check-added-large-files
- id: check-symlinks
- id: detect-private-key
- id: check-merge-conflict
- id: check-case-conflict # file conflicts: a.txt vs. A.txt
# formatters
- id: mixed-line-ending
- id: trailing-whitespace
exclude: "(.*\\.html|.*\\.md)$"
- id: end-of-file-fixer
exclude: "(.*\\.xml|.*\\.svg)$"
# python
- id: check-ast # abstract syntax tree
- id: check-builtin-literals # no {} and [], but dict() and list()
- id: debug-statements
# - id: name-tests-test
# args: [--pytest-test-first]
# django-upgrade suggestions
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.14.0"
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
# tha black
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.7.0"
hooks:
- id: black
# flake8 replacement (&more)
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.284"
hooks:
- id: ruff
args: [--fix]
# js/sass/etc formatter
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.2
hooks:
- id: prettier
args: [--list-different]
exclude: "(.*\\.html|.*\\.md)$"
# eslinth, shall we? urrfff
# - repo: https://github.com/pre-commit/mirrors-eslint
# rev: v8.47.0
# hooks:
# - id: eslint
1 change: 0 additions & 1 deletion CHANGELOG.txt → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
=== (ongoing) ===

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Everything in postgres, accessible via Django ORM, using
postgres fullext search capabilites
postgres fullext search capabilites
8 changes: 5 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import sys

if __name__ == "__main__":
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
# 'postgres_searchindex.tests.south_settings')
'postgres_searchindex.tests.settings')
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
# 'postgres_searchindex.tests.south_settings')
"postgres_searchindex.tests.settings",
)

from django.core.management import execute_from_command_line

Expand Down
1 change: 1 addition & 0 deletions postgres_searchindex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"
25 changes: 20 additions & 5 deletions postgres_searchindex/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
LANGUAGE_2_PGCONFIG = {
"en": "english",
"de": "german",
"fr": "french",
}
from django.conf import settings

POSTGRES_SEARCHINDEX = getattr(
settings,
"POSTGRES_SEARCHINDEX",
{
"default": {},
},
)


LANGUAGE_2_PGCONFIG = getattr(
settings,
"POSTGRES_SEARCHINDEX_LANGUAGE_2_PGCONFIG",
{
"en": "english",
"de": "german",
"fr": "french",
},
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.core.management import BaseCommand
from django.contrib.contenttypes.models import ContentType
from django.core.management import BaseCommand

from postgres_searchindex import conf
from postgres_searchindex.models import IndexEntry
from postgres_searchindex.source_pool import source_pool

Expand All @@ -10,7 +10,7 @@ class Command(BaseCommand):
help = "Update/build index"

def handle(self, *args, **options):
for index_key, index in settings.POSTGRES_SEARCHINDEX.items():
for index_key, index in conf.POSTGRES_SEARCHINDEX.items():
self.stdout.write("====================================")
self.stdout.write(
f"Updating index \"{index_key}\" with kwargs {index.get('kwargs', {})}"
Expand All @@ -28,14 +28,11 @@ def handle(self, *args, **options):
current_ids.append(obj.id)
# remove no more existing
content_type = ContentType.objects.get_for_model(source.model)
delete_result = (
IndexEntry.objects.filter(
index_key=index_key,
content_type=content_type,
)
.exclude(
object_id__in=current_ids,
)
.delete()
to_delete = IndexEntry.objects.filter(
index_key=index_key,
content_type=content_type,
).exclude(
object_id__in=current_ids,
)
delete_result = to_delete.delete()
self.stdout.write(f"> Done. Removed from index: {delete_result[0]}")
58 changes: 41 additions & 17 deletions postgres_searchindex/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
# Generated by Django 3.2.21 on 2024-01-14 17:21

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('sites', '0002_alter_domain_unique'),
("contenttypes", "0002_remove_content_type_name"),
("sites", "0002_alter_domain_unique"),
]

operations = [
migrations.CreateModel(
name='IndexEntry',
name="IndexEntry",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('modified_at', models.DateTimeField(auto_now=True)),
('index_key', models.CharField(default='default', max_length=32)),
('object_id', models.PositiveIntegerField()),
('original_modified_at', models.DateTimeField(default=django.utils.timezone.now)),
('title', models.CharField(max_length=1024)),
('content', models.TextField(default='')),
('url', models.TextField()),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
('site_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sites.site')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("modified_at", models.DateTimeField(auto_now=True)),
("index_key", models.CharField(default="default", max_length=32)),
("object_id", models.PositiveIntegerField()),
(
"original_modified_at",
models.DateTimeField(default=django.utils.timezone.now),
),
("title", models.CharField(max_length=1024)),
("content", models.TextField(default="")),
("url", models.TextField()),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="contenttypes.contenttype",
),
),
(
"site_id",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="sites.site",
),
),
],
options={
'abstract': False,
"abstract": False,
},
),
]
1 change: 1 addition & 0 deletions postgres_searchindex/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = "benzkji"
Loading

0 comments on commit dce8aca

Please sign in to comment.