Skip to content

Commit

Permalink
Add testing (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl authored Jan 24, 2024
1 parent 09edd77 commit d887b49
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 11 deletions.
45 changes: 45 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// For format details, see https://containers.dev/implementors/json_reference/
{
"name": "Python 3 Developer Container",
"build": {
"dockerfile": "../Dockerfile",
"target": "developer"
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}",
},
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"github.vscode-github-actions",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"charliermarsh.ruff"
]
}
},
"features": {
// Some default things like git config
"ghcr.io/devcontainers/features/common-utils:2": {
"upgradePackages": false
}
},
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
"--net=host",
// Make sure SELinux does not disable with access to host filesystems like tmp
"--security-opt=label=disable"
],
// Mount the parent as /workspaces so we can pip install peers as editable
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// After the container is created, install the python project in editable form
"postCreateCommand": "pip install -c dev-requirements.txt -e '.[dev]'"
}
4 changes: 3 additions & 1 deletion .github/workflows/_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Install system packages
run: sudo apt-get install graphviz
Expand Down Expand Up @@ -45,7 +47,7 @@ jobs:
run: python .github/pages/make_switcher.py --add $DOCS_VERSION ${{ github.repository }} build/switcher.json

- name: Publish Docs to gh-pages
if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
if: github.ref_type == 'tag' || github.ref_name == 'main'
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7 # v3.9.2
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/_tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
workflow_call:
inputs:
tox:
type: string
description: What to run under tox
required: true


jobs:
run:
runs-on: "ubuntu-latest"

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- run: find

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install python packages
run: pip install -c dev-requirements.txt -e .[dev]

- name: Run tox
run: tox -e ${{ inputs.tox }}
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ jobs:
# TODO: Use the CI straight from the template
uses: ./.github/workflows/_check.yml

# TODO: add pre-commit and ctt
# TODO: Use the CI straight from the template
test:
needs: check
if: ${{ ! needs.check.outputs.branch-pr }}
uses: ./.github/workflows/_tox.yml
with:
tox: pre-commit,pytest

docs:
needs: check
if: ${{ ! needs.check.outputs.branch-pr }}
uses: ./.github/workflows/_docs.yml
permissions:
contents: write

release:
if: github.ref_type == 'tag'
Expand Down
72 changes: 70 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,71 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
.venv
build/
*.egg-info
.tox/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
**/_version.py

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
cov.xml
.pytest_cache/
.mypy_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# likely venv names
.venv*
venv*

# further build artifacts
lockfiles/

# ruff cache
.ruff_cache/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "example"]
path = example
url = https://github.com/DiamondLightSource/python-copier-template-example.git
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ repos:

- repo: local
hooks:
- id: ruff
name: lint with ruff
language: system
entry: ruff check --force-exclude
types: [python]
require_serial: true

- id: ruff-format
name: format with ruff
language: system
entry: ruff format --force-exclude
types: [python]
require_serial: true

- id: constraints
name: check constraints match installed
language: system
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
]
}
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Unit Test",
"type": "python",
"request": "launch",
"justMyCode": false,
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
},
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Tests, lint and docs",
"command": "tox -p",
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": [],
}
]
}
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} as developer
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
24 changes: 20 additions & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=dev --no-annotate --output-file=dev-requirements.txt --strip-extras
#
accessible-pygments==0.0.4
alabaster==0.7.16
annotated-types==0.6.0
babel==2.14.0
beautifulsoup4==4.12.3
build==1.0.3
Expand All @@ -14,14 +15,19 @@ cfgv==3.4.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
copier==9.1.1
decorator==5.1.1
distlib==0.3.8
docutils==0.20.1
dunamai==1.19.0
filelock==3.13.1
funcy==2.0
identify==2.5.33
idna==3.6
imagesize==1.4.1
importlib-metadata==7.0.1
iniconfig==2.0.0
jinja2==3.1.3
jinja2-ansible-filters==1.3.2
livereload==2.6.3
markdown-it-py==3.0.0
markupsafe==2.1.4
Expand All @@ -31,16 +37,25 @@ myst-parser==2.0.0
nodeenv==1.8.0
packaging==23.2
pathlib2==2.3.7.post1
pathspec==0.12.1
pip-tools==7.3.0
platformdirs==4.1.0
pluggy==1.3.0
plumbum==1.8.2
pre-commit==3.6.0
prompt-toolkit==3.0.36
py==1.11.0
pydantic==2.5.3
pydantic-core==2.14.6
pydata-sphinx-theme==0.15.2
pygments==2.17.2
pyproject-hooks==1.0.0
pytest==7.4.4
pyyaml==6.0.1
pyyaml-include==1.3.2
questionary==2.0.1
requests==2.31.0
ruff==0.1.14
six==1.16.0
snowballstemmer==2.2.0
soupsieve==2.5
Expand All @@ -54,15 +69,16 @@ sphinxcontrib-htmlhelp==2.0.5
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.7
sphinxcontrib-serializinghtml==1.1.10
tomli==2.0.1
tornado==6.4
tox==3.28.0
tox-direct==0.4
treecomp==1.0.0
typer==0.9.0
typing-extensions==4.9.0
urllib3==2.1.0
virtualenv==20.25.0
wcwidth==0.2.13
wheel==0.42.0
zipp==3.17.0

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
project = "python-copier-template"

# The full version, including alpha/beta/rc tags.
release = check_output(['git', 'describe', '--always', '--tags']).decode()
release = check_output(["git", "describe", "--always", "--tags"]).decode()

# The short X.Y version.
if "-" in release:
Expand Down
1 change: 1 addition & 0 deletions example
Submodule example added at 24c2b7
Loading

0 comments on commit d887b49

Please sign in to comment.