Skip to content

Commit 99097f3

Browse files
initial commit
1 parent 797befd commit 99097f3

File tree

7 files changed

+147
-2
lines changed

7 files changed

+147
-2
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test WorkFlow
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: [3.7, 3.8, 3.9]
13+
14+
steps:
15+
- name: 🛎️ Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
ref: ${{ github.head_ref }}
19+
- name: 🐍 Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: 🦾 Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install ".[dev]"
27+
- name: 🧹 Lint with flake8
28+
run: |
29+
make check_code_quality
30+
- name: 🧪 Test
31+
run: "python -m pytest ./test"

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: style check_code_quality
2+
3+
export PYTHONPATH = .
4+
check_dirs := src
5+
6+
style:
7+
black $(check_dirs)
8+
isort --profile black $(check_dirs)
9+
10+
check_code_quality:
11+
black --check $(check_dirs)
12+
isort --check-only --profile black $(check_dirs)
13+
# stop the build if there are Python syntax errors or undefined names
14+
flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics
15+
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators
16+
flake8 $(check_dirs) --count --max-line-length=88 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics
17+

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
1-
# template-python
2-
A template repo holding our common setup for a python project
1+
# Python Template 🐍
2+
A template repo holding our common setup for a python project.
3+
4+
## Installation
5+
6+
You can install the package using pip
7+
8+
```
9+
pip install -e .
10+
```
11+
12+
or for development
13+
14+
```
15+
pip install -e ".[dev]"
16+
```
17+
18+
## Structure
19+
20+
The project has the following structure
21+
22+
```
23+
├── .github
24+
│ └── workflows
25+
│ └── test.yml # holds our github action config
26+
├── .gitignore
27+
├── Makefile
28+
├── README.md
29+
├── setup.py
30+
├── src
31+
│ ├── __init__.py
32+
│ ├── hello.py
33+
└── test
34+
└── test_hello.py
35+
```
36+
37+
### Code Quality 🧹
38+
39+
We provide two handy commands inside the `Makefile`, namely:
40+
41+
- `make style` to format the code
42+
- `make check_code_quality` to check code quality (PEP8 basically)
43+
44+
So far, **there is no linting with mypy`. See [issue](link)
45+
46+
### Tests 🧪
47+
48+
[`pytests`](https://docs.pytest.org/en/7.1.x/) is used to run our tests.
49+
50+
### CI/CD
51+
52+
We use [GitHub actions](https://github.com/features/actions) to automatically run tests and check code quality when a new PR is done on `main`.
53+
54+
55+
# Q&A
56+
57+
## Why no cookiecutter?
58+
This is a template repo, it's meant to be used inside GitHub upon repo creation.
59+
60+
## Why reinvent the wheel?
61+
62+
There are several very good templates on GitHub, I prefer to use code we wrote instead of blinding taking the most starred template and having features we don't need. From experience, it's better to keep it simple and general enough for our specific use cases.

setup.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import setuptools
2+
from setuptools import find_packages
3+
4+
with open("README.md", "r") as fh:
5+
long_description = fh.read()
6+
7+
setuptools.setup(
8+
name="template-python", # Replace with your own username
9+
version="0.0.1",
10+
author="Roboflow",
11+
author_email="[email protected]",
12+
description="<INSERT_DESCRIPTION>",
13+
long_description=long_description,
14+
long_description_content_type="text/markdown",
15+
url="<INSERT_URL>",
16+
install_requires=[
17+
# list your requires
18+
],
19+
packages=find_packages(exclude=("tests",)),
20+
extras_require={
21+
"dev": ["flake8", "black==22.3.0", "isort"],
22+
},
23+
classifiers=[
24+
"Programming Language :: Python :: 3",
25+
"License :: OSI Approved :: MIT License",
26+
"Operating System :: OS Independent",
27+
],
28+
python_requires=">=3.7",
29+
)

src/__init__.py

Whitespace-only changes.

src/hello.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello() -> str:
2+
return "World"

test/test_hello.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from src.hello import hello
2+
3+
4+
def test_hello():
5+
res = hello()
6+
assert res == "World"

0 commit comments

Comments
 (0)