Skip to content
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
30 changes: 15 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 36

Expand All @@ -67,7 +67,7 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 37

Expand All @@ -79,7 +79,7 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 38

Expand All @@ -91,7 +91,7 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 39

Expand All @@ -103,7 +103,7 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 310

Expand All @@ -115,9 +115,14 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test, test-report
- run-tests:
pyversion: 311
- store_test_results:
path: reports
- run:
name: Upload coverage report
command: coveralls

test-python312:
executor:
Expand All @@ -128,7 +133,7 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 312

Expand All @@ -141,14 +146,9 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: test
extra: dev, test
- run-tests:
pyversion: 313
- store_test_results:
path: reports
- run:
name: Upload coverage report
command: coveralls

analysis:
executor:
Expand All @@ -157,10 +157,10 @@ jobs:
steps:
- checkout
- install-dependencies:
extra: analysis, test
extra: dev, analysis, test
- run:
name: Verify
command: python setup.py verify
command: poe verify

publish:
executor:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reports/
*.egg-info/
pip-wheel-metadata/
dist/
build/

# Ignore stupid .DS_Store
.DS_Store
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ With seamless we mean that any features we add will work truly seamlessly. You s
## Working with the code
### Prerequisites

* PostgreSQL 10 or newer.
* Django 2.0 or newer (including 3.x, 4.x).
* Python 3.6 or newer.
* PostgreSQL 14 or newer.
* Django 5.x or newer.
* Python 3.11 or newer.

These are just for local development. CI for code analysis etc runs against these. Tests will pass on all Python, Django and PostgreSQL versions documented. Linting, formatting and type-checking the code might not work on other Python and/or Django versions.

### Getting started

Expand All @@ -86,16 +88,16 @@ With seamless we mean that any features we add will work truly seamlessly. You s

4. Install the development/test dependencies:

λ pip install .[test] .[analysis]
λ pip install -r requirements-test.txt

5. Run the tests:

λ tox
λ poe test

6. Run the benchmarks:

λ py.test -c pytest-benchmark.ini
λ poe benchmark

7. Auto-format code, sort imports and auto-fix linting errors:

λ python setup.py fix
λ poe fix
4 changes: 2 additions & 2 deletions psqlextra/backend/migrations/patched_autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
class AddOperationHandler:
"""Handler for when operations are being added to a new migration.

This is where we intercept operations such as
:see:CreateModel to replace it with our own.
This is where we intercept operations such as :see:CreateModel to
replace it with our own.
"""

def __init__(self, autodetector, app_label, args, kwargs):
Expand Down
6 changes: 3 additions & 3 deletions psqlextra/backend/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,9 @@ def replace_materialized_view_model(self, model: Type[Model]) -> None:

This is used to alter the backing query of a materialized view.

Replacing a materialized view is a lot trickier than a normal view.
For normal views we can use `CREATE OR REPLACE VIEW`, but for
materialized views, we have to create the new view, copy all
Replacing a materialized view is a lot trickier than a normal
view. For normal views we can use `CREATE OR REPLACE VIEW`, but
for materialized views, we have to create the new view, copy all
indexes and constraints and drop the old one.

This operation is atomic as it runs in a transaction.
Expand Down
4 changes: 2 additions & 2 deletions psqlextra/models/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def _view_query_as_sql_with_params(

When copying the meta options from the model, we convert any
from the above to a raw SQL query with bind parameters. We do
this is because it is what the SQL driver understands and
we can easily serialize it into a migration.
this is because it is what the SQL driver understands and we can
easily serialize it into a migration.
"""

# might be a callable to support delayed imports
Expand Down
2 changes: 1 addition & 1 deletion psqlextra/partitioning/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def apply(self, using: Optional[str]) -> None:
def print(self) -> None:
"""Prints this model plan to the terminal in a readable format."""

print(f"{self.config.model.__name__}:")
print(f"{self.config.model.__name__}: ")

for partition in self.deletions:
print(" - %s" % partition.name())
Expand Down
6 changes: 3 additions & 3 deletions psqlextra/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def annotate(self, **annotations) -> "Self": # type: ignore[valid-type, overrid
name of an existing field on the model as the alias name. This
version of the function does allow that.

This is done by temporarily renaming the fields in order to avoid the
check for conflicts that the base class does.
We rename all fields instead of the ones that already exist because
This is done by temporarily renaming the fields in order to
avoid the check for conflicts that the base class does. We
rename all fields instead of the ones that already exist because
the annotations are stored in an OrderedDict. Renaming only the
conflicts will mess up the order.
"""
Expand Down
3 changes: 2 additions & 1 deletion psqlextra/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def postgres_set_local(

The effect is undone when the context manager exits.

See https://www.postgresql.org/docs/current/runtime-config-client.html
See
https://www.postgresql.org/docs/current/runtime-config-client.html
for an overview of all available options.
"""

Expand Down
60 changes: 59 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude = '''
| .env
| env
| venv
| tests/snapshots
| tests/__snapshots__
)/
)
'''
Expand All @@ -25,3 +25,61 @@ ignore_missing_imports = true

[tool.django-stubs]
django_settings_module = "settings"

[tool.poe.tasks]
_autoflake = "python3 -m autoflake --remove-all -i -r setup.py psqlextra tests"
_autopep8 = "autopep8 -i -r setup.py psqlextra tests"
_isort_setup_py = "isort setup.py"
_isort_psqlextra = "isort psqlextra"
_isort_tests = "isort tests"
_isort_verify_setup_py = "isort -c setup.py"
_isort_verify_psqlextra = "isort -c psqlextra"
_isort_verify_tests = "isort -c tests"

[tool.poe.tasks.lint]
cmd = "python3 -m flake8 --builtin=__version__ setup.py psqlextra tests"
help = "Lints all the code."

[tool.poe.tasks.lint_fix]
sequence = ["_autoflake", "_autopep8"]
help = "Auto-fixes linter errors."

[tool.poe.tasks.lint_types]
cmd = "mypy --package psqlextra --pretty --show-error-codes"
help = "Type-checks the code."

[tool.poe.tasks.format]
cmd = "black setup.py psqlextra tests"
help = "Auto-formats the code."

[tool.poe.tasks.format_verify]
cmd = "black --check setup.py psqlextra tests"
help = "Verifies that the code was formatted properly."

[tool.poe.tasks.format_docstrings]
cmd = "docformatter -r -i ."
help = "Auto-formats doc strings."

[tool.poe.tasks.format_docstrings_verify]
cmd = "docformatter -r -c ."
help = "Verifies all doc strings are properly formatted."

[tool.poe.tasks.sort_imports]
sequence = ["_isort_setup_py", "_isort_psqlextra", "_isort_tests"]
help = "Auto-sorts the imports."

[tool.poe.tasks.sort_imports_verify]
sequence = ["_isort_verify_setup_py", "_isort_verify_psqlextra", "_isort_verify_tests"]
help = "Verifies that the imports are properly sorted."

[tool.poe.tasks.fix]
sequence = ["format", "format_docstrings", "sort_imports", "lint_fix", "lint", "lint_types"]
help = "Automatically format code and fix linting errors."

[tool.poe.tasks.verify]
sequence = ["format_verify", "format_docstrings_verify", "sort_imports_verify", "lint", "lint_types"]
help = "Automatically format code and fix linting errors."

[tool.poe.tasks.test]
cmd = "pytest --cov=psqlextra --cov-report=term --cov-report=xml:reports/xml --cov-report=html:reports/html --junitxml=reports/junit/tests.xml --reuse-db -vv"
help = "Runs all the tests."
4 changes: 3 additions & 1 deletion requirements-all.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-e .
-e .[local]
-e .[dev]
-e .[test]
-e .[test-report]
-e .[analysis]
-e .[docs]
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e .
-e .[dev]
-e .[test]
20 changes: 18 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import dj_database_url
import os

from urllib.parse import urlparse


def _parse_db_url(/service/url: str):
parsed_url = urlparse(url)

return {
'ENGINE': 'django.db.backends.postgresql',
'NAME': (parsed_url.path or '').strip('/') or "postgres",
'HOST': parsed_url.hostname or None,
'PORT': parsed_url.port or None,
'USER': parsed_url.username or None,
'PASSWORD': parsed_url.password or None,
}


DEBUG = True
TEMPLATE_DEBUG = True
Expand All @@ -8,7 +24,7 @@
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

DATABASES = {
'default': dj_database_url.config(default='postgres:///psqlextra'),
'default': _parse_db_url(https://github.com/os.environ.get('DATABASE_URL',%20'%3C/span%3Epostgres:///psqlextra'%3Cspan%20class=%22x%20x-first%20x-last%22%3E)),
}

DATABASES['default']['ENGINE'] = 'tests.psqlextra_test_backend'
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ lines_between_types=1
include_trailing_comma=True
known_third_party=pytest,freezegun
float_to_top=true
skip_glob=tests/snapshots/*.py
Loading