Skip to content

Commit 902a119

Browse files
Merge pull request #1 from SmartMonkey-git/rr/setup
Basic Setup
2 parents 5c62064 + 4a3ab27 commit 902a119

File tree

16 files changed

+430
-2
lines changed

16 files changed

+430
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Setup/Cache Env
2+
description: 'Sets up and caches a python env. Will only install dependencies if no cache was hit.'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Get project version with yq
8+
id: get_python_version
9+
uses: mikefarah/yq@v4.46.1
10+
with:
11+
cmd: yq '.project.requires-python' pyproject.toml
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v5.6.0
15+
with:
16+
python-version: ${{ steps.get_python_version.outputs.result }}
17+
18+
- name: Cache Env
19+
uses: actions/cache@v4.2.3
20+
id: env-cache
21+
with:
22+
path: ${{ env.pythonLocation }}
23+
key: ${{ hashFiles('./requirements/requirements.txt') }}-${{ hashFiles('./requirements/requirements_scripts.txt') }}-${{ hashFiles('./requirements/requirements_test.txt') }}
24+
25+
- name: Install Dependencies
26+
if: ${{ steps.env-cache.outputs.cache-hit != 'true' }}
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -r requirements/requirements.txt
30+
pip install -r requirements/requirements_test.txt
31+
shell: bash

.github/workflows/cd.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CD
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish-to-pypi:
9+
name: Build distribution 📦
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
14+
steps:
15+
- name: Check out Repo
16+
uses: actions/checkout@v4
17+
with:
18+
persist-credentials: false
19+
fetch-depth: 0
20+
21+
- name: Get project version with yq
22+
id: get_python_version
23+
uses: mikefarah/yq@v4.46.1
24+
with:
25+
cmd: yq '.project.requires-python' pyproject.toml
26+
27+
- name: Initialize Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ steps.get_python_version.outputs.result }}
31+
32+
- name: Install build
33+
run: >-
34+
pip install build==1.2.2.post1
35+
36+
- name: Build a binary wheel and a source tarball
37+
run: python3 -m build
38+
39+
- name: Publish distribution 📦 to PyPI
40+
env:
41+
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.release.tag_name }}
42+
with:
43+
packages-dir: dist/
44+
repository-url: https://pypi.org/legacy/
45+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/ci.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
10+
env:
11+
PYTEST_ADDOPTS: "--color=yes"
12+
13+
jobs:
14+
test:
15+
name: Test
16+
timeout-minutes: 15
17+
runs-on: ubuntu-latest
18+
steps:
19+
20+
- name: Check out Repo
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup Env
26+
uses: ./.github/actions/setup_env
27+
28+
- name: Test with pytest
29+
id: tests
30+
run: |
31+
pytest --disable-warnings ./
32+
33+
formatting:
34+
name: Formatting
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 15
37+
steps:
38+
- name: Check out Repo
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Setup Env
44+
uses: ./.github/actions/setup_env
45+
46+
- name: Ruff Formatting
47+
run: ruff format --check
48+
49+
linting:
50+
name: Linting
51+
runs-on: ubuntu-latest
52+
timeout-minutes: 15
53+
steps:
54+
- name: Check out Repo
55+
uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
59+
- name: Setup Env
60+
uses: ./.github/actions/setup_env
61+
62+
- name: Ruff Linting
63+
run: ruff check
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Create Master Cache
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
- master
9+
10+
permissions:
11+
id-token: write
12+
contents: read
13+
14+
env:
15+
PYTEST_ADDOPTS: "--color=yes"
16+
17+
jobs:
18+
create_master_cache:
19+
name: Caching
20+
timeout-minutes: 15
21+
runs-on: ubuntu-latest
22+
steps:
23+
24+
- name: Check out Repo
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Setup Env
30+
uses: ./.github/actions/setup_env

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,9 @@ cython_debug/
191191
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
192192
# refer to https://docs.cursor.com/context/ignore-files
193193
.cursorignore
194-
.cursorindexingignore
194+
.cursorindexingignore
195+
196+
.vscode/
197+
.idea/
198+
199+
_version.py

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
# robinson-group-python-template
1+
## Robinson Group Python Template
2+
This repo serves as a template for python projects in the [Robinson Group](https://robinsongroup.github.io/) of the BIH.
3+
To get started copy or fork this project and follow the steps below.
4+
### Install conda
5+
If you not already have conda, miniconda or Anaconda installed. Check out the [miniconda installation guide](https://www.anaconda.com/docs/getting-started/miniconda/install#quickstart-install-instructions).
6+
7+
#### Setup env
8+
Open `requirements/environment.yml` and adjust `<Project-Name>`.
9+
10+
To create and activate the env execute:
11+
12+
```
13+
conda env create -f requirements/environment.yml
14+
conda activate <Project-Name>
15+
```
16+
17+
### Renaming
18+
As this is a template project, some of the directories and setting have generic names. To ensure the project is set up, that it aligns with your intended name please:
19+
20+
1. Rename the folder inside of src
21+
2. Open the pyproject.toml
22+
- Rename all variables in the sections ``[project]`` and ``[project.urls]``
23+
24+
### Ruff Linting and Formatting
25+
Ruff helps to maintain the same code style and prevent the most common bugs in our code base. Keeping the code style uniform simplifies the collaboration - it is much easier to review a pull request without hundreds of whitespace changes.
26+
27+
Please take a moment to learn how to use the IDE plugins. In PyCharm, the formatting action can be invoked with right-clicking at any code location and the same applies for VS Code. The keyboard shortcuts are also available. However, it is recommended to format and lint on saving a file.
28+
29+
Besides the IDE, Ruff can also be run as a command line tool. Assuming that the virtual environment is active, the following command will format/lint the entire project:
30+
31+
**Formatting**
32+
```bash
33+
ruff format
34+
```
35+
**Linting**
36+
```bash
37+
ruff check
38+
```
39+
We recommend to run commit the resulting changes before opening a PR, because the unformatted code will fail the Continuous Integration (CI) pipeline. A PR cannot be merged until the code passes the CI.
40+
41+
#### Ruff Plugins
42+
- [Pycharm - Ruff Plugin](https://plugins.jetbrains.com/plugin/20574-ruff)
43+
- [VSCode - Ruff Plugin](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)
44+
45+
### Continuous Delivery
46+
You've done it, your package is at a state, where you want other to use it. Luckily, this repository features a CD-Pipeline,
47+
that will build and upload your packages to Pypi for you. To get the CD running you need to first follow these [instructions](https://docs.pypi.org/trusted-publishers/adding-a-publisher/). The pipeline uses [OIDC](https://openid.net/developers/how-connect-works/) to authenticate on Pypi. Make sure your [pyproject.toml](pyproject.toml) is set up correctly.
48+
49+
Then open your repository page on Github. To the right you should find **Create new Release**. Press it!
50+
51+
You will find this page:
52+
![img.png](release_page.png)
53+
54+
Create a new Tag for your release, add a title and a description. Press **Publish release**, watch the CD launch in the **Actions Tab** and enjoy your well deserved coffee. ☕

pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[build-system]
2+
requires = ["setuptools>=80.9.0", "wheel==0.45.1", "setuptools_scm==8.3.1"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "robinson-group-python-template"
7+
description = "A template for python projects build in the robinson group"
8+
authors = [{ name = "Rouven Reuter" }]
9+
requires-python = ">=3.10"
10+
dynamic = ["dependencies", "version"]
11+
license = { file = "LICENSE" }
12+
readme = "README.md"
13+
14+
[project.urls]
15+
homepage = "https://github.com/SmartMonkey-git/robinson-group-python-template"
16+
repository = "https://github.com/SmartMonkey-git/robinson-group-python-template.git"
17+
documentation = "https://github.com/SmartMonkey-git/robinson-group-python-template"
18+
bugtracker = "https://github.com/SmartMonkey-git/robinson-group-python-template/issues"
19+
20+
[tool.setuptools]
21+
packages.find = { where = ["src"] }
22+
23+
[tool.setuptools_scm]
24+
version_file = "src/project_name/_version.py"
25+
26+
[tool.setuptools.dynamic]
27+
version = { attr = "project_name._version.version" }
28+
dependencies = {file = ["requirements/requirements.txt"]}

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
minversion = 7.0
3+
pythonpath = src
4+
testpaths =
5+
tests

release_page.png

68.8 KB
Loading

requirements/environment.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: <Project-Name>
2+
3+
dependencies:
4+
- python>=3.10
5+
- pip
6+
7+
- pip:
8+
- -r requirements.txt
9+
- -r requirements_test.txt

0 commit comments

Comments
 (0)