Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ __pycache__/
# uv
.venv

# ctt
# testing ctt and mkdocs build
.ctt
ctt.toml
test
10 changes: 3 additions & 7 deletions constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ md_project_setup:
```
{%- endif %}
Navigate to the project directory and install all dependencies:
```bash
./just.sh install
```
uv sync --all-groups --all-extras
```
This command will also create a virtual environment for the project.
To make sure that pre-commits are enabled run:
```
uv run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit
```
This will also enable pre-commit hooks.
{%- if use_dvc %}
And make sure that you have all the necessary data available.
```
Expand Down
10 changes: 10 additions & 0 deletions ctt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[defaults]
project_name = "A new Project"
project_description = "Not much."
author = "Excidion"
author_email = "36995046+Excidion@users.noreply.github.com"
ci = ""

[output.".ctt/test"]
python_version = "3.10"
use_dvc = false
16 changes: 16 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
install:
uv sync --all-groups --all-extras
uv run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit

hooks:
uv run pre-commit run --all-files

docs:
uv run mkdocs build --strict --site-dir test
rm -rf test

test:
uv run ctt
rm -rf .ctt

check: install hooks docs test
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"mkdocs-literate-nav>=0.6.1",
"mkdocs-material>=9.5.35",
"mkdocstrings[python]>=0.26.1",
"rust-just>=1.46.0",
]

[dependency-groups]
Expand Down
2 changes: 1 addition & 1 deletion reproML/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ For more details take look at the [documentation](#look-at-the-documentation)
For more detailed information about the project check out the documentation.
Use the following command to run the documentation webserver.
```
uv run mkdocs serve
just docs
```
27 changes: 13 additions & 14 deletions reproML/docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,13 @@ def main():
model = 42
save_model(model, "model")


if __name__ == "__main__":
main()

```
Using this will automatically log the start and end of every function you decorate with it.
Depening on the log level, you'll even be able to trace arguments and return values.
```bash
$ uv run src/model/train.py
# 2038-01-19 03:14:08,000 INFO __main__.main START
# 2038-01-19 03:14:08,001 DEBUG __main__.main INPUTS:
just run src/model/train.py
# 2038-01-19 03:14:08,000 INFO train.py.main START
# 2038-01-19 03:14:08,001 DEBUG train.py.main INPUTS:
# 2038-01-19 03:14:08,002 INFO src.model.io.save_model START
# 2038-01-19 03:14:08,003 DEBUG src.model.io.save_model INPUTS: model=42, model_name='model'
# 2038-01-19 03:14:08,004 INFO src.model.io.get_path START
Expand All @@ -355,8 +351,8 @@ $ uv run src/model/train.py
# 2038-01-19 03:14:08,007 DEBUG src.model.io.get_path OUTPUT: 'models/model.cldpkl'
# 2038-01-19 03:14:08,008 INFO src.model.io.save_model END
# 2038-01-19 03:14:08,009 DEBUG src.model.io.save_model OUTPUT: None
# 2038-01-19 03:14:08,010 INFO __main__.main END
# 2038-01-19 03:14:08,011 DEBUG __main__.main OUTPUT: None
# 2038-01-19 03:14:08,010 INFO train.py.main END
# 2038-01-19 03:14:08,011 DEBUG train.py.main OUTPUT: None
```
Forcing yourself to only log via decorators can have some positive side effects:
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.
Expand All @@ -370,24 +366,27 @@ All of these parameters should be handed to the code via environment variables.

> 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]

That is why this template comes with [`python-dotenv`](https://pypi.org/project/python-dotenv/) pre-installed.
Simply create a file named `.env` in the project root folder and enter your configration parameters:
To store your secrets create a file named `.env` in the project root folder and enter your configration parameters:
```ini
DATABASE_URL=postgres://localhost:1337/dbname
DATBASE_USER=myusername
DATABASE_PASSWORD=topsneaky
```
Scripts run via [`just`](https://github.com/casey/just) automatically load these entries as environment variables.
```bash
just run src/script.py
```
In your code you can access these screts like this:
```python
# src/script.py
import os
from dotenv import load_dotenv

load_dotenv()

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

Alternatively you can also use [`python-dotenv`](https://pypi.org/project/python-dotenv/) to load secrets from `.env` files.

## First steps

### Installing a package
Expand Down
2 changes: 2 additions & 0 deletions reproML/just.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
uv run just $@
23 changes: 23 additions & 0 deletions reproML/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set dotenv-load

# shows this list
default:
uv run just --list

# runs a python script's main method
run SCRIPT *ARGS:
uv run typer {{SCRIPT}} run {{ARGS}}

# installs all dependecies and pre-commit hooks
install:
uv sync --all-groups --all-extras
uv run pre-commit install --hook-type pre-push --hook-type post-checkout --hook-type pre-commit

# runs quality checks on all files
check:
uv run pre-commit run --all-files

# starts the documentation server
docs:
-uv run interrogate
-uv run mkdocs serve
3 changes: 2 additions & 1 deletion reproML/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ dependencies = [
{%- if use_dvc %}
"dvc[{{ remote_type }}]>=3.55.2",
{%- endif %}
"python-dotenv>=1.0.1",
"rust-just>=1.46.0",
"typer>=0.24.1",
]

[dependency-groups]
Expand Down
4 changes: 0 additions & 4 deletions reproML/src/model/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ def main():
model = load_model("model")
print(model.__class__.__name__)
# TODO implement prediction


if __name__ == "__main__":
main()
4 changes: 0 additions & 4 deletions reproML/src/model/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ def main():
"""Builds a model and saves it to the file system."""
model = None # TODO implement training
save_model(model, "model")


if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.