Skip to content

Commit 8d347b8

Browse files
chore: setup template repo
1 parent a3e6f3c commit 8d347b8

File tree

12 files changed

+665
-3
lines changed

12 files changed

+665
-3
lines changed

.github/dependabot.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: 2
2+
registries:
3+
sevan-packagr:
4+
type: python-index
5+
url: https://api.repoforge.io/EYvhW6SyL
6+
username: ${{secrets.PACKAGR_USERNAME}}
7+
password: ${{secrets.PACKAGR_PASSWORD}}
8+
updates:
9+
- package-ecosystem: "uv"
10+
directory: "/"
11+
insecure-external-code-execution: allow
12+
registries:
13+
- sevan-packagr
14+
schedule:
15+
interval: "monthly"
16+
groups:
17+
main-deps:
18+
patterns:
19+
- "patch"
20+
- "minor"
21+
versioning-strategy: increase-if-necessary
22+
23+
- package-ecosystem: "github-actions"
24+
directory: "/"
25+
schedule:
26+
interval: "monthly"
27+
groups:
28+
actions-deps:
29+
patterns:
30+
- "*"

.github/pull_request_template.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Why is this pull request needed?
2+
3+
This pull request is needed because of....
4+
5+
## What does this pull request change?
6+
7+
Write summary of what this pull request changes if needed.
8+
9+
## Issues related to this change:

.github/workflows/test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
on:
4+
# Workflow dispatch is used for manual triggers
5+
workflow_dispatch:
6+
# Workflow call is used for called from another workflow
7+
workflow_call:
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
13+
env:
14+
UV_INDEX_REPOFORGE_USERNAME: ${{ secrets.PACKAGR_USERNAME }}
15+
UV_INDEX_REPOFORGE_PASSWORD: ${{ secrets.PACKAGR_PASSWORD }}
16+
17+
jobs:
18+
19+
pre-commit: # Static analyzers, formatters and verifying pre-commit hooks has been run
20+
name: Build & Run Pre Commit hooks to verify code structure, quality etc. from pre-commit hooks
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: "Setup: checkout repository"
24+
uses: actions/checkout@v4
25+
26+
- name: "Setup: add python"
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version-file: ".python-version"
30+
31+
- name: "Run: pre-commit"
32+
uses: pre-commit/[email protected]
33+
with:
34+
extra_args: --all-files
35+
36+
test:
37+
38+
name: Run tests
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Install the latest version of uv
45+
uses: astral-sh/setup-uv@v6
46+
with:
47+
enable-cache: true
48+
49+
- name: Run tests with pytest
50+
run: uv run pytest

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ cython_debug/
182182
.abstra/
183183

184184
# Visual Studio Code
185-
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
185+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186186
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187-
# and can be added to the global gitignore or merged into this file. However, if you prefer,
187+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
188188
# you could uncomment the following to ignore the entire vscode folder
189189
# .vscode/
190190

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-toml
7+
- id: check-yaml
8+
args:
9+
- --unsafe
10+
- id: check-json
11+
- id: end-of-file-fixer
12+
- id: trailing-whitespace
13+
- id: name-tests-test
14+
args:
15+
- --pytest-test-first
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.11.13
18+
hooks:
19+
- id: ruff
20+
args:
21+
- --fix
22+
- id: ruff-format

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,95 @@
11
# python-template
2-
A template repository for
2+
A template repository for python projects in Sevan DWT.
3+
4+
## Setup environment with uv
5+
6+
> [!IMPORTANT]
7+
> You only need to follow the steps in this section if you are setting up an uv environment for the first time. If you already have an uv and credentials to sevan internal packages, you can skip to [Run a script](#run-a-script).
8+
9+
[UV](https://docs.astral.sh/uv/) is a Python package and project manager, which handles Python versions and virtual environments for you.
10+
To install uv, type the following in the PowerShell terminal:
11+
12+
```powershell
13+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
14+
```
15+
16+
This will download and install uv to:
17+
18+
```powershell
19+
C:\Users\<your-username>\.local\bin
20+
```
21+
22+
You should receive a message that uv has been installed.
23+
To use uv from the terminal window, you need to add it to your system's PATH.
24+
Write the following in the PowerShell terminal:
25+
26+
```powershell
27+
$env:Path = "C:\Users\<your-username>\.local\bin;$env:Path"
28+
```
29+
30+
After installing uv, you can check that uv is available by running the `uv` command:
31+
32+
```powershell
33+
uv
34+
```
35+
36+
You should see a help menu listing the available commands.
37+
38+
39+
#### Configure credentials for internal packages
40+
41+
To get access to the internal packages, you need to set up your credentials towards Repoforge.
42+
This is done by running the `setup_credentials.ps1` script from the terminal window:
43+
44+
```powershell
45+
.\setup_credentials.ps1
46+
```
47+
48+
You might be prompted to enter your Repoforge token. If that happens, request a token from EBG/SLF.
49+
Enter your token when prompted. The credentials should now be saved to:
50+
51+
```powershell
52+
C:\Users\<your-username>\_netrc
53+
```
54+
55+
Your setup should now be complete.
56+
57+
58+
## Run a script
59+
60+
To test your setup, you can try to run one of your scripts:
61+
62+
```powershell
63+
uv run .\src\main.py
64+
```
65+
66+
## Develop your own scripts
67+
68+
### Add a new package
69+
70+
To add a new package, you can use the `uv add` command. For example, to add the `numpy` package, you can run:
71+
72+
```powershell
73+
uv add numpy
74+
```
75+
76+
### Running the tests
77+
78+
To run the tests for the projec:
79+
80+
```powershell
81+
uv run pytest
82+
```
83+
84+
### Linting and formatting
85+
86+
Pre-commit is used to format and lint the code-base before a commit is done. To install git-hooks:
87+
88+
```console
89+
uv run pre-commit install
90+
```
91+
It will now automatically run on the files changed when trying to commit. To run on all files:
92+
93+
```console
94+
uv run pre-commit run --all-files
95+
```

pyproject.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[project]
2+
name = "python-template" # Change this to your package name
3+
version = "0.1.0"
4+
description = "<Add your description here>"
5+
readme = "README.md"
6+
requires-python = ">=3.10, <4"
7+
dependencies = [
8+
]
9+
10+
[dependency-groups]
11+
dev = [
12+
"pre-commit>=4.2.0",
13+
"pytest (>=8.3.3, <9)",
14+
"pre-commit (>=4.0.1, <5)",
15+
"pytest-cov (>=6.0.0, <7)",
16+
]
17+
18+
[[tool.uv.index]]
19+
name = "sevan-internal-package-index"
20+
url = "https://api.repoforge.io/EYvhW6SyL/"
21+
22+
[tool.pytest.ini_options]
23+
pythonpath = [
24+
"src"
25+
]
26+
27+
[tool.ruff]
28+
src = ["src"]
29+
line-length = 120
30+
31+
[tool.ruff.lint]
32+
select = [
33+
"E", # pycodestyle errors
34+
"W", # pycodestyle warnings
35+
"F", # pyflakes
36+
"I", # isort
37+
"S", # flake8-bandit
38+
"C", # flake8-comprehensions
39+
"B", # flake8-bugbear
40+
"UP", # automatically upgrade syntax for newer versions of the language
41+
]
42+
43+
[tool.ruff.lint.per-file-ignores]
44+
"__init__.py" = ["F401"]

setup_credentials.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Get user home directory
2+
$homePath = $env:USERPROFILE
3+
# Define the path to the auth.toml file
4+
$authTomlPath = Join-Path $env:APPDATA "pypoetry\auth.toml"
5+
6+
Write-Host "Trying to find existing credentials..."
7+
8+
# Check if the auth.toml file exists and extract the token
9+
if (Test-Path $authTomlPath) {
10+
$authContent = Get-Content -Path $authTomlPath -Raw
11+
if ($authContent -match '\[http-basic\.packagr\]\s+username\s*=\s*"__token__"\s+password\s*=\s*"([^"]+)"') {
12+
$tokenText = $matches[1]
13+
Write-Host "Token extracted from auth.toml"
14+
} else {
15+
Write-Host "Token not found in Poetry's auth.toml. Please enter it manually."
16+
$token = Read-Host "Enter your repoforge token (ask EBG/SLF for a token)" -AsSecureString
17+
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($token)
18+
$tokenText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
19+
}
20+
} else {
21+
Write-Host "Existing authentication file not found. Please enter your token manually."
22+
$token = Read-Host "Enter your repoforge token (ask EBG/SLF for a token)" -AsSecureString
23+
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($token)
24+
$tokenText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
25+
}
26+
27+
# Create netrc entry
28+
$netrcEntry = @"
29+
machine api.repoforge.io
30+
login __token__
31+
password $tokenText
32+
"@
33+
34+
# Append to _netrc file
35+
$netrcPath = Join-Path $homePath "_netrc"
36+
# Check for existing entry to _netrc file, add newline if it exists
37+
if (Test-Path $netrcPath) { Add-Content -Path $netrcPath -Value "`n" }
38+
Add-Content -Path $netrcPath -Value $netrcEntry
39+
40+
# Set file as read-only
41+
Set-ItemProperty -Path $netrcPath -Name IsReadOnly -Value $true
42+
43+
Write-Host "Credentials saved to $netrcPath"

src/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def hello_world():
2+
print("Hello from python-template!")
3+
4+
5+
if __name__ == "__main__":
6+
hello_world()

0 commit comments

Comments
 (0)