Skip to content

Commit 8fb2c35

Browse files
authored
Dev/86 better readme (#87)
* Update readme * Bump project version * Update Makefile
1 parent b00b6cd commit 8fb2c35

File tree

3 files changed

+74
-39
lines changed

3 files changed

+74
-39
lines changed

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ install_venv:
55
install_pre_commit:
66
poetry run pre-commit install
77

8-
install_dev: install_venv install_pre_commit
9-
108
# Dev tools
119
isort:
1210
poetry run isort src
@@ -21,8 +19,6 @@ flake8:
2119
ruff:
2220
poetry run ruff check src
2321

24-
format: isort black
25-
2622
mypy:
2723
poetry run mypy --incremental --no-install-types --show-error-codes --pretty src
2824

@@ -41,7 +37,13 @@ test_cov:
4137
compile_env:
4238
poetry lock --no-update
4339

44-
build: pre_commit ruff flake8 mypy test
40+
install_dev: install_venv install_pre_commit
41+
42+
format: isort black
43+
44+
lint: pre_commit ruff flake8 mypy
45+
46+
build: pre_commit mypy test
4547

4648
# Misc
4749
jupyter:

README.md

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,81 @@
99
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
1010
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
1111

12-
This is a template repository dedicated to ML projects in python. It provides some basic tools and configs necessary to kickstart the development.
12+
Are you tired of dealing with messy code, debugging errors, and fixing bugs that could have been prevented with proper tools and practices? Do you want to improve the overall quality of your projects while saving time in the long run? Then this template is perfect for you!
13+
14+
This is a template repository dedicated to ML projects in `Python`. It provides some basic tools and configs necessary to kickstart the development. It includes linting, type checking, package management, testing and CI.
15+
16+
## Prerequisites
17+
18+
In order to use this template, you need to have both `poetry` and `make` installed.
19+
20+
### Poetry
21+
22+
`poetry` is a package manager we're using. You can check the installation instructions [here](https://python-poetry.org/docs/#installing-with-the-official-installer). You should avoid installing `poetry` through `pip` as it is a system-level tool, separated from the `Python` runtime you're currently using. It enables us to treat `Python` as any other dependency and pin its version in `pyproject.toml`.
23+
24+
```sh
25+
curl -sSL https://install.python-poetry.org | python3 -
26+
```
27+
28+
### make
29+
30+
`make` is a utility tool that enables us to create aliases for commands we type in the console to run programs. It's much more efficient to use `make` so you don't have to memorize console commands. You can also expose your project's CLI via `Makefile`.
31+
32+
`make` should be available on most Linux distributions.
33+
34+
If you're using Windows, I would get [choco](https://chocolatey.org/install) first, then get `make` from `choco` package gallery.
35+
36+
```sh
37+
choco install make
38+
```
39+
40+
Mac users can pull it using `Homebrew`.
41+
42+
```sh
43+
brew install make
44+
```
45+
46+
## Getting started
47+
48+
To start your work, you need to set up your local environment and hooks.
49+
50+
```sh
51+
make install_dev
52+
```
53+
54+
Later you will define aliases for your CLI here. `Makefile` already contains calls to build tools and checks. Use `build` to run them all.
55+
56+
```Makefile
57+
build: pre_commit mypy test
58+
```
59+
60+
Please note that `build` does not encompass the coverage and dependencies updates. These need to be run separately. Coverage may not always be necessary and you're gonna be running `build` often while working locally. Updating dependencies should be approached with the utmost care, no reason to bump the versions all the time when code does the work it's intended for. Better use some automation tool like [dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file).
61+
62+
To quickly format your repo while coding run:
63+
64+
```sh
65+
make format # isort black flake8
66+
```
67+
68+
Before you commit, always run a full check. It's much faster to run it locally than to wait for CI build.
69+
70+
```sh
71+
make build # pre_commit mypy test
72+
```
1373

1474
## Structure
1575

1676
- `.github` - CI/CD pipelines, usually named after repository host (`.github`, `.azure`, `.gitlab`, etc)
1777
- `data` - if you need any data to be present locally, store it here
18-
- `notebooks` - notebooks are particularly _meh_, but this is the directory to put them
78+
- `notebooks` - notebooks are kinda _meh_, but this is the directory to put them
1979
- `src` - here goes your project's code
2080
- `src/cli` - project's entry points should be wrapped with CLI and exposed via Makefile, good idea to store them separately
2181
- `.codespell` - whitelist for project-related terms
2282
- `.coveragearc` - coverage config, usually you don't want to report coverage on CLI, tests and some expressions
83+
- `.env.example` - here you should state any environment variables your project uses
2384
- `.pre-commit-config.yaml` - pre-commit pipeline configuration
2485
- `Makefile` - tasks definitions, much simpler to call `make` than writing whole commands in the terminal; it's also easy to check what project-specific functialities you're exposing
25-
- `mypy.ini` - `mypy` config, usually some of your dependencies won't be hinted so you gonna ignore them here
86+
- `mypy.ini` - `mypy` config, usually some of your dependencies won't be hinted so you're gonna ignore them here
2687
- `poetry.lock` - compiled dependencies
2788
- `poetry.toml` - `poetry` config, as you shouldn't enforce other devs where to put their virtual environment this is must be a separate config file
2889
- `pyproject.toml` - repo config
@@ -40,34 +101,6 @@ When developing a project there's a need to automate some tedious stuff that hel
40101
- [mypy](https://github.com/python/mypy)
41102
- [coverage](https://github.com/nedbat/coveragepy)
42103

43-
## [Makefile](Makefile)
44-
45-
To start your work, you need to set up your local environment and hooks.
46-
47-
```sh
48-
make install_dev
49-
```
50-
51-
You gonna put your CLI here later. It already contains calls to build tools and checks. Use `build` to run them all (`isort`, `black`, `pre_commit`, `flake8`, `mypy`, `test`).
52-
53-
```sh
54-
make build
55-
```
56-
57-
Please note that `build` does not encompass the coverage and dependencies updates. These need to be run separately. Coverage may not always be necessary and you're gonna be running `build` often while working locally. Updating dependencies should be approached with the utmost care, no reason to bump the versions all the time when code does the work it's intended for. Better use some automation tool like [dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file).
58-
59-
To quickly format your repo while coding run:
60-
61-
```sh
62-
make format
63-
```
64-
65-
Before you commit, always run a full check. It's much more faster to run it locally, than to wait for CI build.
66-
67-
```sh
68-
make build
69-
```
70-
71104
## [pre-commit](.github/hooks/.pre-commit-config.yml)
72105

73106
This hook is here to prevent you from committing any nasty code to your repository.
@@ -80,8 +113,8 @@ This hook is here to prevent you from committing any nasty code to your reposito
80113
- autoformatting [black](https://github.com/psf/black)
81114
- finally some linter to be sure [flake8](https://gitlab.com/pycqa/flake8)
82115

83-
Why are we using local environment to run pre-commit for us? This is rather unusual isn't it? Yes - it is. You want to use the same versions of libs (`flake8`, `black`) and have them specified in a single file. Otherwise you need to keep track of precommit dependencies as well. If you want truly separate environment for the pre-commit - use dependency groups in your package manager.
116+
Why are we using the local environment to run pre-commit for us? This is rather unusual, isn't it? Yes - it is. You want to use the same versions of libs (`flake8`, `black`) and have them specified in a single file. Otherwise, you need to keep track of `pre-commit` dependencies as well. If you want a truly separate environment for the `pre-commit` - use dependency groups in your package manager.
84117

85118
## Closing remarks
86119

87-
Hopefully, this template helps you jump off your project. If any of these tools are unfamiliar to you, follow the links for more info on them. Feel free to customize it, this is a template after all. The point I often make while doing workshops is you being able to make your toolset. This is but an example. Personally, I often look up how my favourite libraries are developed and take what I like. Just try not to overdo it. Don't use tools which are not necessary in your project. The main idea is to spend time actually coding, soliving problems, not thinking about code quality whatsoever.
120+
Hopefully, this template helps you jump off your project. If any of these tools are unfamiliar to you, follow the links for more info on them. Feel free to customize it, this is a template after all. The point I often make while doing workshops is you being able to make your toolset. This is but an example. I often look up how my favorite libraries are developed and take what I like. Just try not to overdo it. Don't use tools that are not necessary in for project. The main idea is to spend time actually coding, solving problems, and not thinking about code quality whatsoever.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-template"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
description = "Python template repository for ML projects"
55
authors = ["peepo-dev-family"]
66

0 commit comments

Comments
 (0)