Skip to content

Commit 6237a49

Browse files
authored
Merge pull request #46 from Excidion/task-runner
Justfile for task definitions
2 parents 48e7047 + ee2a0f5 commit 6237a49

14 files changed

Lines changed: 101 additions & 33 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ __pycache__/
2626
# uv
2727
.venv
2828

29-
# ctt
29+
# testing ctt and mkdocs build
3030
.ctt
31-
ctt.toml
31+
test

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Depending on your choices, it will generate a structure that looks something lik
5353
│
5454
├── pyproject.toml <- Project configuration and dependencies.
5555
│
56+
├── justfile <- Useful commands
57+
│
5658
└── README.md <- The top-level README for developers using this project.
5759
```
5860
For more details check out the [documentation](https://excidion.github.io/reproML/structure/).

‎constants.yml‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ md_project_setup:
2020
```
2121
{%- endif %}
2222
Navigate to the project directory and install all dependencies:
23+
```bash
24+
./just.sh install
2325
```
24-
uv sync --all-groups --all-extras
25-
```
26-
This command will also create a virtual environment for the project.
27-
To make sure that pre-commits are enabled run:
28-
```
29-
uv run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit
30-
```
26+
This will also enable pre-commit hooks.
3127
{%- if use_dvc %}
3228
And make sure that you have all the necessary data available.
3329
```

‎ctt.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[defaults]
2+
project_name = "A new Project"
3+
project_description = "Not much."
4+
author = "Excidion"
5+
author_email = "36995046+Excidion@users.noreply.github.com"
6+
ci = ""
7+
8+
[output.".ctt/test"]
9+
python_version = "3.10"
10+
use_dvc = false

‎justfile‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
install:
2+
uv sync --all-groups --all-extras
3+
uv run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit
4+
5+
hooks:
6+
uv run pre-commit run --all-files
7+
8+
docs:
9+
uv run mkdocs build --strict --site-dir test
10+
rm -rf test
11+
12+
test:
13+
uv run ctt
14+
rm -rf .ctt
15+
16+
check: install hooks docs test

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"mkdocs-literate-nav>=0.6.1",
1717
"mkdocs-material>=9.5.35",
1818
"mkdocstrings[python]>=0.26.1",
19+
"rust-just>=1.46.0",
1920
]
2021

2122
[dependency-groups]

‎reproML/README.md.jinja‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ For more details take look at the [documentation](#look-at-the-documentation)
1111
For more detailed information about the project check out the documentation.
1212
Use the following command to run the documentation webserver.
1313
```
14-
uv run mkdocs serve
14+
just docs
1515
```

‎reproML/docs/structure.md‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ This is your first overview how to find your way around this project.
134134
├── pyproject.toml <- Project configuration and dependencies.
135135
├── uv.lock <- Full dependency list. Managed by uv, do not touch.
136136
│
137+
├── justfile <- Useful commands
138+
│
137139
└── README.md <- The top-level README for developers using this project.
138140
```
139141
All folders marked with `<dvc>` are versioned via dvc and so are their subfolders.
@@ -334,17 +336,13 @@ def main():
334336
model = 42
335337
save_model(model, "model")
336338

337-
338-
if __name__ == "__main__":
339-
main()
340-
341339
```
342340
Using this will automatically log the start and end of every function you decorate with it.
343341
Depening on the log level, you'll even be able to trace arguments and return values.
344342
```bash
345-
$ uv run src/model/train.py
346-
# 2038-01-19 03:14:08,000 INFO __main__.main START
347-
# 2038-01-19 03:14:08,001 DEBUG __main__.main INPUTS:
343+
just run src/model/train.py
344+
# 2038-01-19 03:14:08,000 INFO train.py.main START
345+
# 2038-01-19 03:14:08,001 DEBUG train.py.main INPUTS:
348346
# 2038-01-19 03:14:08,002 INFO src.model.io.save_model START
349347
# 2038-01-19 03:14:08,003 DEBUG src.model.io.save_model INPUTS: model=42, model_name='model'
350348
# 2038-01-19 03:14:08,004 INFO src.model.io.get_path START
@@ -353,8 +351,8 @@ $ uv run src/model/train.py
353351
# 2038-01-19 03:14:08,007 DEBUG src.model.io.get_path OUTPUT: 'models/model.cldpkl'
354352
# 2038-01-19 03:14:08,008 INFO src.model.io.save_model END
355353
# 2038-01-19 03:14:08,009 DEBUG src.model.io.save_model OUTPUT: None
356-
# 2038-01-19 03:14:08,010 INFO __main__.main END
357-
# 2038-01-19 03:14:08,011 DEBUG __main__.main OUTPUT: None
354+
# 2038-01-19 03:14:08,010 INFO train.py.main END
355+
# 2038-01-19 03:14:08,011 DEBUG train.py.main OUTPUT: None
358356
```
359357
Forcing yourself to only log via decorators can have some positive side effects:
360358
If you feel like you would like to add some logging within a function, this can be an indicator that the code block in question is a candidate to be refactored into a separate function.
@@ -368,24 +366,27 @@ All of these parameters should be handed to the code via environment variables.
368366

369367
> A litmus test for whether an app has all config correctly factored out of the code is whether the codebase could be made open source at any moment, without compromising any credentials.[^6]
370368
371-
That is why this template comes with [`python-dotenv`](https://pypi.org/project/python-dotenv/) pre-installed.
372-
Simply create a file named `.env` in the project root folder and enter your configration parameters:
369+
To store your secrets create a file named `.env` in the project root folder and enter your configration parameters:
373370
```ini
374371
DATABASE_URL=postgres://localhost:1337/dbname
375372
DATBASE_USER=myusername
376373
DATABASE_PASSWORD=topsneaky
377374
```
375+
Scripts run via [`just`](https://github.com/casey/just) automatically load these entries as environment variables.
376+
```bash
377+
just run src/script.py
378+
```
378379
In your code you can access these screts like this:
379380
```python
381+
# src/script.py
380382
import os
381-
from dotenv import load_dotenv
382-
383-
load_dotenv()
384383

385384
database_url = os.getenv("DATABASE_URL")
386385
```
387386
Thanks to the `.gitignore`, the `.env` file will not get committed into the git repository.
388387

388+
Alternatively you can also use [`python-dotenv`](https://pypi.org/project/python-dotenv/) to load secrets from `.env` files.
389+
389390
## First steps
390391

391392
### Installing a package

‎reproML/just.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
uv run just $@

‎reproML/justfile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
set dotenv-load
2+
3+
# shows this list
4+
default:
5+
uv run just --list
6+
7+
# runs a python script's main method
8+
run SCRIPT *ARGS:
9+
uv run typer {{SCRIPT}} run {{ARGS}}
10+
11+
# installs all dependecies and pre-commit hooks
12+
install:
13+
uv sync --all-groups --all-extras
14+
uv run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit
15+
16+
# runs quality checks on all files
17+
check:
18+
uv run pre-commit run --all-files
19+
20+
# starts the documentation server
21+
docs:
22+
-uv run interrogate
23+
-uv run mkdocs serve

0 commit comments

Comments
 (0)