Skip to content

Commit

Permalink
updated docs and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 10, 2024
1 parent 2b6b891 commit a56e58c
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 122 deletions.
30 changes: 30 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This is used by the action https://github.com/dorny/paths-filter
dependencies: &dependencies
- 'pyproject.toml'

python: &python
- added|modified: 'src/**'
- added|modified: 'tests/**'
- 'manage.py'

changelog:
- added|modified: 'changes/**'
- 'CHANGELOG.md'

mypy:
- *python
- 'mypy.ini'

run_tests:
- *python
- *dependencies
- 'pytest.ini'
- '.github/workflows/test.yml'
- '.github/file-filters.yml'

lint:
- *python
- '.flake8'
- 'pyproject.toml'
- '.github/file-filters.yml'
- '.github/workflows/lint.yml'
62 changes: 62 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Lint

on:
push:
branches:
- '**' # matches every branch

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}-lint"
cancel-in-progress: true

defaults:
run:
shell: bash

permissions:
id-token: write
attestations: write


jobs:
changes:
runs-on: ubuntu-latest
timeout-minutes: 1
defaults:
run:
shell: bash
outputs:
lint: ${{steps.changes.outputs.lint }}
steps:
- name: Checkout code
uses: actions/[email protected]
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
with:
base: ${{ github.ref }}
token: ${{ github.token }}
filters: .github/file-filters.yml

lint:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: [ changes ]
if: needs.changes.outputs.lint
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
architecture: 'x64'
- uses: yezz123/setup-uv@v4
- name: lint
if: needs.changes.outputs.lint
run: |
uv run isort src/ --check-only
uv run flake8 src/
160 changes: 108 additions & 52 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,113 @@
name: Test

on:
push:
branches:
- master
- develop
pull_request:
push:
branches:
- '**' # matches every branch

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}-test"
cancel-in-progress: true

defaults:
run:
shell: bash

permissions:
id-token: write
attestations: write


jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2

- name: Install dependencies
run: |
python -m pip install --upgrade pip flake8 isort
- name: Lint with flake8
run: |
flake8 src
isort -c src
test:
# if: ${{github.event}} && ${{ !contains(github.event.head_commit.message, 'ci skip') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.11", "3.12"]
django-version: [ "4.2", "5.1"]
env:
PY_VER: ${{ matrix.python-version}}
DJ_VER: ${{ matrix.django-version}}

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: python -m pip install tox

- name: Test with Tox
run: tox -e d${DJ_VER//.}-py${PY_VER//.} -- --create-db --cov-report=xml --cov-report=term --junitxml=pytest.xml

- uses: codecov/codecov-action@v1
with:
# files: ./coverage1.xml,./coverage2.xml # optional
# flags: unittests # optional
# name: codecov-umbrella # optional
# fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
changes:
runs-on: ubuntu-latest
timeout-minutes: 1
defaults:
run:
shell: bash
outputs:
run_tests: ${{steps.changes.outputs.run_tests }}
lint: ${{steps.changes.outputs.lint }}
steps:
- name: Checkout code
uses: actions/[email protected]
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
with:
base: ${{ github.ref }}
token: ${{ github.token }}
filters: .github/file-filters.yml

ci:
runs-on: ubuntu-latest
name: Test py${{ matrix.python-version }}/dj${{matrix.django-version}}
defaults:
run:
shell: bash
strategy:
max-parallel: 1
matrix:
python-version: [ "3.11", "3.12" ]
django-version: [ "4.2", "5.1" ]
fail-fast: true
needs: [ changes ]
# if: needs.changes.outputs.run_tests || needs.changes.outputs.lint
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Restore cached venv
id: cache-venv-restore
uses: actions/cache/restore@v4
with:
path: |
.cache-uv/
.venv/
key: ${{ matrix.python-version }}-${{matrix.django-version}}-${{ hashFiles('pyproject.toml') }}-venv

- uses: yezz123/setup-uv@v4
with:
python: ${{ matrix.python-version }}

- name: Test
# if: needs.changes.outputs.run_tests
run: |
uv add "django==${{ matrix.django-version }}.*"
uv run --cache-dir .cache-uv/ \
python -m pytest tests/ \
--junit-xml junit-${{ matrix.python-version }}-${{matrix.django-version}}.xml \
--cov --cov-report xml
- name: Cache venv
if: steps.cache-venv-restore.outputs.cache-hit != 'true'
id: cache-venv-save
uses: actions/cache/save@v4
with:
path: |
.cache-uv/
.venv/
key: ${{ matrix.python-version }}-${{matrix.django-version}}-${{ hashFiles('pyproject.toml') }}-venv

- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: pytest-results-${{ matrix.python-version }}-${{matrix.django-version}}
path: junit-${{ matrix.python-version }}-${{matrix.django-version}}.xml
if: ${{ always() }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == 3.12
continue-on-error: true
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
flags: unittests
files: ./coverage.xml
verbose: false
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-${{env.GITHUB_REF_NAME}}
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,14 @@ provides decorators to easily add custom buttons to Django Admin pages and/or ad
It allows easy creation of wizards, actions and/or links to external resources
as well as api only views.

Three decorators are available:
Four decorators are available:

- ``button()`` to mark a method as extra view and show related button
- ``link()`` This is used for "external" link, where you don't need to invoke local views.
- ``view()`` View only decorator, this adds a new url but do not render any button.
- ``choice()`` Menu like button, can be used to group multiple @views().


Install
-------

pip install django-admin-extra-buttons


After installation add it to ``INSTALLED_APPS``

INSTALLED_APPS = (
...
'admin_extra_buttons',
)

How to use it
-------------

Expand Down
27 changes: 27 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Contributing


Install [uv](https://docs.astral.sh/uv/)


git clone ..
uv venv .venv --python 3.12
source .venv/bin/activate
uv sync --extra docs
pre-commit install



## Run tests
pytests tests


## Run demo app

tests/demoapp/manage.py migrate

tests/demoapp/manage.py runserver

!!! note

You can login in the demo application as superuser using any username/password
12 changes: 12 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Install


pip install django-admin-extra-buttons


After installation add it to ``INSTALLED_APPS``

INSTALLED_APPS = (
...
'admin_extra_buttons',
)
5 changes: 0 additions & 5 deletions docs/requirements.txt

This file was deleted.

Loading

0 comments on commit a56e58c

Please sign in to comment.