Skip to content

Commit

Permalink
chore: refactor development setup
Browse files Browse the repository at this point in the history
  • Loading branch information
afuetterer committed Oct 19, 2023
1 parent 84ecb26 commit 368b10b
Show file tree
Hide file tree
Showing 26 changed files with 500 additions and 104 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: CI

on:
push:
branches:
- master
pull_request:
# run CI only if files in these whitelisted paths are changed
paths:
- '.github/workflows/**'
- 'rdmo_plugins/**'
- .pre-commit-config.yaml
- pyproject.toml

# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PYTHONDONTWRITEBYTECODE: 1
FORCE_COLOR: 1 # colored output by pytest etc.
CLICOLOR_FORCE: 1 # colored output by ruff

jobs:

lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.12"
cache: pip
- run: python -m pip install --upgrade pip setuptools wheel
- run: python -m pip install -e .[dev]
- name: Set up pre-commit cache
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: lint-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run linters via pre-commit (ruff, eslint)
run: pre-commit run --all-files --color=always

test:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.8', '3.12']
db-backend: [mysql, postgres]
name: "Test (Python: ${{ matrix.python-version }}, DB: ${{ matrix.db-backend }})"
# TODO needs: lint
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install Dependencies
run: |
sudo apt update
sudo apt install --yes pandoc texlive-xetex
python -m pip install --upgrade pip setuptools wheel
pandoc --version
- name: Install rdmo[mysql] and start mysql
run: |
python -m pip install --editable .[ci]
python -m pip install rdmo[mysql]
sudo systemctl start mysql.service
if: matrix.db-backend == 'mysql'
- name: Install rdmo[postgres] and start postgresql
run: |
python -m pip install --editable .[ci]
python -m pip install rdmo[postgres]
sudo systemctl start postgresql.service
pg_isready
sudo -u postgres psql --command="CREATE USER postgres_user PASSWORD 'postgres_password' CREATEDB"
if: matrix.db-backend == 'postgres'
- name: Prepare Env
run: |
cp -r testing/media testing/media_root
mkdir testing/log
- name: Run Tests
run: |
pytest -p randomly -p no:cacheprovider --cov --reuse-db --numprocesses=auto --dist=loadscope
# coveralls --service=github
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# GITHUB_DB_BACKEND: ${{ matrix.db-backend }}
# COVERALLS_FLAG_NAME: '${{ matrix.db-backend }}: ${{ matrix.python-version }}'
# COVERALLS_PARALLEL: true

dev-setup:
# Ref: structlog (MIT licensed) <https://github.com/hynek/structlog/blob/main/.github/workflows/ci.yml>
name: "Test dev setup on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.12"
cache: pip
- run: python -Im pip install -e .[dev]
- run: python -Ic 'import rdmo_plugins; print(rdmo_plugins.__version__)'

required-checks-pass:
if: always()
needs:
- lint
- test
- dev-setup
runs-on: ubuntu-22.04
steps:
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
30 changes: 0 additions & 30 deletions .github/workflows/django.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ dist
*.egg-info

/env

.pytest_cache
.ruff_cache
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

repos:
- repo: meta
hooks:
- id: check-hooks-apply
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-xml
- id: check-yaml
- id: end-of-file-fixer
exclude: \.html$|\.txt$
- id: trailing-whitespace
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Add the `rdmo_plugins` to the `INSTALLED_APPS` in `config/settings/local.py`:

```python
from . import INSTALLED_APPS
INSTALLED_APPS = ['rdmo_plugins'] + INSTALLED_APPS
INSTALLED_APPS = ["rdmo_plugins", *INSTALLED_APPS]
```

Add the export plugins to the `PROJECT_EXPORTS` in `config/settings/local.py`:

```python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from . import PROJECT_EXPORTS

PROJECT_EXPORTS += [
Expand All @@ -50,7 +50,7 @@ PROJECT_EXPORTS += [
Add the import plugins to the `PROJECT_IMPORTS` in `config/settings/local.py`:

```python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from . import PROJECT_IMPORTS

PROJECT_IMPORTS += [
Expand Down
143 changes: 143 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools", "wheel"]

[project]
name = "rdmo-plugins"
description = "Import and export plugins for RDMO."
readme = "README.md"
keywords = [
"data management plan",
"dmp",
"rdmo",
"research data",
"research data management",
]
license = {text = "Apache-2.0"}
authors = [
{name = "RDMO Arbeitsgemeinschaft", email = "[email protected]"},
]
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django :: 4.2",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dynamic = [
"version",
]
dependencies = [
"rdmo"
]

[project.optional-dependencies]
ci = [
"coveralls~=3.3",
"rdmo-plugins[dev]",
]
dev = [
"pre-commit~=3.5",
"rdmo[allauth]",
"rdmo-plugins[pytest]",
]
pytest = [
"pytest~=7.4",
"pytest-cov~=4.1",
"pytest-django~=4.5",
"pytest-mock~=3.11",
"pytest-randomly~=3.15",
"pytest-xdist~=3.3",
]

[project.urls]
documentation = "https://rdmo.readthedocs.io"
homepage = "https://rdmorganiser.github.io"
issues = "https://github.com/rdmorganiser/rdmo-plugins/issues"
repository = "https://github.com/rdmorganiser/rdmo-plugins.git"
slack = "https://rdmo.slack.com"

[tool.setuptools.packages.find]
include = ["rdmo_plugins*"]

[tool.setuptools.package-data]
"*" = ["*"]

[tool.setuptools.dynamic]
version = {attr = "rdmo_plugins.__version__"}

[tool.ruff]
target-version = "py38"
line-length = 120
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"PGH", # pygrep-hooks
"RUF", # ruff
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
ignore = [
"B006", # mutable-argument-default
"B007", # unused-loop-control-variable
"B018", # useless-expression
"RUF012", # mutable-class-default
]

[tool.ruff.isort]
known-first-party = ["rdmo"]
section-order = [
"future",
"standard-library",
"pytest",
"django",
"third-party",
"first-party",
"local-folder"
]

[tool.ruff.isort.sections]
pytest = ["pytest"]
django = ["django"]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "config.settings"
testpaths = ["tests"]
pythonpath = [".", "tests"]
addopts = "-p no:randomly"
filterwarnings = [
# fail on RemovedInDjango50Warning exception
"error::django.utils.deprecation.RemovedInDjango50Warning",

# ignore warnings raised from within coreapi 2.3.3
"ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning",
"ignore:pkg_resources is deprecated as an API:DeprecationWarning",

# ignore warnings raised from within django itself
# django/core/files/storage/__init__.py
"ignore:django.core.files.storage.get_storage_class is deprecated:django.utils.deprecation.RemovedInDjango51Warning",
]

[tool.coverage.run]
source = ["rdmo"]
branch = true
parallel = true

[tool.coverage.report]
exclude_lines = [
"raise Exception",
"except ImportError:"
]
9 changes: 1 addition & 8 deletions rdmo_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
__title__ = 'rdmo-plugins'
__version__ = '1.0.0'
__author__ = 'Jochen Klar'
__email__ = '[email protected]'
__license__ = 'Apache-2.0'
__copyright__ = 'Copyright 2020 RDMO-Arbeitsgemeinschaft'

VERSION = __version__
VERSION = __version__ = "1.0.0"
3 changes: 2 additions & 1 deletion rdmo_plugins/exports/datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict

from django.http import HttpResponse

from rdmo.core.exports import prettify_xml
from rdmo.core.renderers import BaseXMLRenderer
from rdmo.projects.exports import Export
Expand Down Expand Up @@ -374,7 +375,7 @@ def get_datasets(self):
'title':
self.get_text('project/dataset/title', set_index=set_index) or
self.get_text('project/dataset/id', set_index=set_index) or
'Dataset #{}'.format(set_index + 1)
f'Dataset #{set_index + 1}'
}]

# publisher
Expand Down
Loading

0 comments on commit 368b10b

Please sign in to comment.