Skip to content

Commit

Permalink
v9.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny Vedrilla committed Oct 26, 2023
1 parent 310505a commit 6f36e76
Show file tree
Hide file tree
Showing 34 changed files with 257 additions and 86 deletions.
10 changes: 9 additions & 1 deletion .ambient-package-update/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from ambient_package_update.metadata.author import PackageAuthor
from ambient_package_update.metadata.constants import DEV_DEPENDENCIES, LICENSE_MIT
from ambient_package_update.metadata.constants import (
DEV_DEPENDENCIES,
LICENSE_MIT,
SUPPORTED_DJANGO_VERSIONS,
SUPPORTED_PYTHON_VERSIONS,
)
from ambient_package_update.metadata.package import PackageMetadata
from ambient_package_update.metadata.readme import ReadmeContent
from ambient_package_update.metadata.ruff_ignored_inspection import RuffIgnoredInspection
Expand Down Expand Up @@ -50,6 +55,9 @@
'bleach>=1.4,<6',
'python-dateutil>=2.5.3',
],
supported_django_versions=SUPPORTED_DJANGO_VERSIONS,
supported_python_versions=SUPPORTED_PYTHON_VERSIONS,
has_migrations=True,
optional_dependencies={
'dev': [
*DEV_DEPENDENCIES,
Expand Down
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
omit =
setup.py,
*_test.py,
tests.py,
*tests*,
tests/*,
testapp/*,
conftest.py
61 changes: 54 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
linting:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.12"

Expand All @@ -21,13 +21,31 @@ jobs:
- name: Run pre-commit hooks
run: pre-commit run --all-files --hook-stage push

build:

validate_migrations:
name: Validate migrations
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
run: python -m pip install -U pip-tools && pip-compile --extra dev,drf,graphql,sentry,view-layer, -o requirements.txt pyproject.toml --resolver=backtracking && pip-sync

- name: Validate migration integrity
run: python manage.py makemigrations --check --dry-run


tests:
name: Python ${{ matrix.python-version }}, django ${{ matrix.django-version }}
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
django-version: [32, 41, 42]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', ]
django-version: ['32', '41', '42', ]

exclude:
- python-version: '3.12'
Expand All @@ -38,9 +56,9 @@ jobs:
django-version: 32

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: setup python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
Expand All @@ -49,3 +67,32 @@ jobs:
env:
TOXENV: django${{ matrix.django-version }}
run: tox
- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: '.coverage*'

coverage:
name: Coverage
runs-on: ubuntu-22.04
needs: tests
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
run: python -m pip install --upgrade coverage[toml]

- name: Download data
uses: actions/download-artifact@v3
with:
name: coverage-data

- name: Combine coverage and fail if it's <100%
run: |
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=100
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
rev: 23.10.0
hooks:
- id: black
args: [ --check, --diff, --config, ./pyproject.toml ]
stages: [ push ]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.292'
rev: 'v0.1.1'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
args: [ --fix, --unsafe-fixes, --exit-non-zero-on-fix ]

- repo: https://github.com/asottile/pyupgrade
rev: v3.14.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [ --py38-plus ]
Expand Down
31 changes: 31 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- method: pip
path: .
extra_requirements:
- dev
24 changes: 0 additions & 24 deletions .readthedocs.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

**9.1.4** (2023-10-20)
* Added migration docs to Readme
* Added migration check to GitHub actions
* Updates from ambient updater

**9.1.3** (2023-10-11)
* Fixed scrubber tests

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![PyPI release](https://img.shields.io/pypi/v/ambient-toolbox.svg)](https://pypi.org/project/ambient-toolbox/)
[![Downloads](https://static.pepy.tech/badge/ambient-toolbox)](https://pepy.tech/project/ambient-toolbox)
[![Coverage](https://img.shields.io/badge/Coverage-100%25-success)](https://github.com/ambient-innovation/ambient-toolbox/actions?workflow=CI)
[![Linting](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Coding Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![Documentation Status](https://readthedocs.org/projects/ambient-toolbox/badge/?version=latest)](https://ambient-toolbox.readthedocs.io/en/latest/?badge=latest)
Expand Down Expand Up @@ -59,6 +60,14 @@ The migration is really simple, just:
````
- Apply migrations by running:
`python ./manage.py migrate`
## Contribute
### Setup package for development
Expand All @@ -83,6 +92,12 @@ The migration is really simple, just:
pytest --ds settings tests
````
- Check coverage
````
coverage run -m pytest --ds settings tests
coverage report -m
````
### Git hooks (via pre-commit)
We use pre-push hooks to ensure that only linted code reaches our remote repository and pipelines aren't triggered in
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets."""

__version__ = '9.1.3'
__version__ = '9.1.4'
2 changes: 1 addition & 1 deletion ambient_toolbox/admin/views/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, *args, **kwargs):
# Build fieldset
fieldset_list = ['']
for field in self.fields:
fieldset_list.append(Div(field, css_class='form-row field-name'))
fieldset_list.append(Div(field, css_class='form-row field-name')) # noqa: PERF401

# Crispy
self.helper = FormHelper()
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/drf/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def validate_authentication_required(self, *, url: str, method: str, view: str):

self.assertIn(response.status_code, [status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN])

def execute_request(
def execute_request( # noqa: PLR0913
self,
*,
url,
Expand Down
13 changes: 7 additions & 6 deletions ambient_toolbox/gitlab/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys
from difflib import ndiff
from http import HTTPStatus

import httpx

Expand Down Expand Up @@ -36,7 +37,7 @@ def get_latest_target_branch_commit_sha(self) -> str:
Get the latest commit which is in the current branch and the target compare branch.
"""
result = subprocess.run(
['git', 'merge-base', '--fork-point', f'origin/{self.target_branch}'], stdout=subprocess.PIPE
['git', 'merge-base', '--fork-point', f'origin/{self.target_branch}'], stdout=subprocess.PIPE, check=True
)
return result.stdout.decode("utf-8").strip()

Expand All @@ -45,7 +46,7 @@ def get_pipeline_id_by_commit_sha(self, sha: str) -> int | None:
response = httpx.get(pipeline_url)
status_code = response.status_code

if status_code == 200:
if status_code == HTTPStatus.OK:
pipelines = json.loads(response.content)
if pipelines and len(pipelines) > 0:
return pipelines[0].get('id', None)
Expand All @@ -66,7 +67,7 @@ def get_coverage_from_pipeline(self, pipeline_id: int, job_name: str) -> (float,
jobs_response = httpx.get(jobs_with_token_url)
jobs_status_code = jobs_response.status_code

if jobs_status_code != 200:
if jobs_status_code != HTTPStatus.OK:
raise ConnectionError(f'Call to jobs api endpoint failed with status code {jobs_status_code}')

jobs = json.loads(jobs_response.content)
Expand All @@ -81,7 +82,7 @@ def get_coverage_from_pipeline(self, pipeline_id: int, job_name: str) -> (float,
pipeline_response = httpx.get(pipeline_with_token_url)
pipeline_status_code = pipeline_response.status_code

if pipeline_status_code != 200:
if pipeline_status_code != HTTPStatus.OK:
raise ConnectionError(f'Call to pipeline api endpoint failed with status code {pipeline_status_code}')

pipeline = json.loads(pipeline_response.content)
Expand All @@ -104,7 +105,7 @@ def get_coverage_from_pipeline(self, pipeline_id: int, job_name: str) -> (float,
job_response = httpx.get(job_with_token_url)
job_status_code = job_response.status_code

if job_status_code != 200:
if job_status_code != HTTPStatus.OK:
raise ConnectionError(f'Call to job api endpoint failed with status code {job_status_code}')

print(f'Job-Log-URL: {job_url}')
Expand Down Expand Up @@ -208,7 +209,7 @@ def process(self):
print(f'Pipelines-API-URL: {self.pipelines_url}')

# Ensure call did not go sideways
if status_code != 200:
if status_code != HTTPStatus.OK:
raise ConnectionError(f'Call to global pipeline api endpoint failed with status code {status_code}')

# Read target pipeline ID from content
Expand Down
1 change: 1 addition & 0 deletions ambient_toolbox/mixins/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PermissionModelMixin:
class Meta:
# No database table creation or deletion operations will be performed for this model.
managed = False
default_permissions = []


class SaveWithoutSignalsMixin:
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/permissions/fixtures/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def process(self) -> (List[Permission], List[Permission]):
# Check which permissions were removed for the given group
for existing_permission in group.permissions.all():
if existing_permission not in defined_permission_list:
removed_permissions.append(existing_permission)
removed_permissions.append(existing_permission) # noqa: PERF401

if not self.dry_run:
# Persist changes on removed permissions
Expand Down
Loading

0 comments on commit 6f36e76

Please sign in to comment.