Skip to content

Commit bdca1cd

Browse files
authored
Merge pull request #1 from code-yeongyu/feature/setup-project
Setup Python Project
2 parents bd43255 + 3ee1ef2 commit bdca1cd

File tree

16 files changed

+2112
-3
lines changed

16 files changed

+2112
-3
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Context
2+
-
3+
4+
## Changes
5+
-

.github/workflows/check_code.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Check Code
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
static-analysis:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
with:
11+
fetch-depth: 0
12+
- name: Set up Python 3.9
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.9
16+
17+
- uses: snok/[email protected]
18+
with:
19+
virtualenvs-create: true
20+
virtualenvs-in-project: true
21+
22+
- name: Cache Dependencies
23+
uses: actions/cache@v2
24+
id: cache-dependencies
25+
with:
26+
path: .venv
27+
key: venv-${{ runner.os }}-${{ hashFiles('./poetry.lock') }}
28+
29+
- name: Install Dependencies if cache doesn't hit
30+
if: steps.cache-dependencies.cache-hit != 'true'
31+
run: poetry install
32+
33+
- name: Check Code Styles
34+
run: poetry run invoke check-code-style
35+
36+
- name: Check Types
37+
run: poetry run invoke check-types

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release Package to PyPI
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
with:
11+
fetch-depth: 0
12+
- name: Set up Python 3.9
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.9
16+
17+
- uses: snok/[email protected]
18+
with:
19+
virtualenvs-create: true
20+
virtualenvs-in-project: true
21+
22+
- name: Cache Dependencies
23+
uses: actions/cache@v2
24+
id: cache-dependencies
25+
with:
26+
path: .venv
27+
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
28+
29+
- name: Install Dependencies if cache doesn't hit
30+
if: steps.cache-dependencies.cache-hit != 'true'
31+
run: poetry install
32+
33+
- name: Publish to PyPI
34+
run:
35+
poetry config http-basic.pypi ${{ secrets.PYPI_USERNAME }} ${{ secrets.PYPI_PASSWORD }};
36+
poetry run invoke release ${{ github.event.release.name }}

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- name: Set up Python 3.9
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: 3.9
19+
20+
- uses: snok/[email protected]
21+
with:
22+
virtualenvs-create: true
23+
virtualenvs-in-project: true
24+
25+
- name: Cache Dependencies
26+
uses: actions/cache@v2
27+
id: cache-dependencies
28+
with:
29+
path: .venv
30+
key: venv-${{ runner.os }}-${{ hashFiles('./poetry.lock') }}
31+
32+
- name: Install Dependencies if cache doesn't hit
33+
if: steps.cache-dependencies.cache-hit != 'true'
34+
run: poetry install
35+
36+
- name: Run test
37+
run: poetry run pytest --cov=. --cov-report=xml
38+
39+
- name: Upload Code Coverage
40+
run: bash <(curl -s https://codecov.io/bash)
41+
env:
42+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/git,python,visualstudiocode
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=git,python,visualstudiocode
3+
4+
### Git ###
5+
# Created by git for backups. To disable backups in Git:
6+
# $ git config --global mergetool.keepBackup false
7+
*.orig
8+
9+
# Created by git when using merge tools for conflicts
10+
*.BACKUP.*
11+
*.BASE.*
12+
*.LOCAL.*
13+
*.REMOTE.*
14+
*_BACKUP_*.txt
15+
*_BASE_*.txt
16+
*_LOCAL_*.txt
17+
*_REMOTE_*.txt
18+
19+
### Python ###
120
# Byte-compiled / optimized / DLL files
221
__pycache__/
322
*.py[cod]
@@ -20,7 +39,6 @@ parts/
2039
sdist/
2140
var/
2241
wheels/
23-
pip-wheel-metadata/
2442
share/python-wheels/
2543
*.egg-info/
2644
.installed.cfg
@@ -50,6 +68,7 @@ coverage.xml
5068
*.py,cover
5169
.hypothesis/
5270
.pytest_cache/
71+
cover/
5372

5473
# Translations
5574
*.mo
@@ -72,6 +91,7 @@ instance/
7291
docs/_build/
7392

7493
# PyBuilder
94+
.pybuilder/
7595
target/
7696

7797
# Jupyter Notebook
@@ -82,7 +102,9 @@ profile_default/
82102
ipython_config.py
83103

84104
# pyenv
85-
.python-version
105+
# For a library or package, you might want to ignore these files since the code is
106+
# intended to run in multiple environments; otherwise, check them in:
107+
# .python-version
86108

87109
# pipenv
88110
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -91,7 +113,22 @@ ipython_config.py
91113
# install all needed dependencies.
92114
#Pipfile.lock
93115

94-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
116+
# poetry
117+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
118+
# This is especially recommended for binary packages to ensure reproducibility, and is more
119+
# commonly ignored for libraries.
120+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
121+
#poetry.lock
122+
123+
# pdm
124+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
125+
#pdm.lock
126+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
127+
# in version control.
128+
# https://pdm.fming.dev/#use-with-ide
129+
.pdm.toml
130+
131+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
95132
__pypackages__/
96133

97134
# Celery stuff
@@ -127,3 +164,42 @@ dmypy.json
127164

128165
# Pyre type checker
129166
.pyre/
167+
168+
# pytype static type analyzer
169+
.pytype/
170+
171+
# Cython debug symbols
172+
cython_debug/
173+
174+
# PyCharm
175+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177+
# and can be added to the global gitignore or merged into this file. For a more nuclear
178+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
179+
#.idea/
180+
181+
### Python Patch ###
182+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
183+
# poetry.toml
184+
185+
186+
### VisualStudioCode ###
187+
.vscode/*
188+
!.vscode/settings.json
189+
!.vscode/tasks.json
190+
!.vscode/launch.json
191+
!.vscode/extensions.json
192+
!.vscode/*.code-snippets
193+
194+
# Local History for Visual Studio Code
195+
.history/
196+
197+
# Built Visual Studio Code Extensions
198+
*.vsix
199+
200+
### VisualStudioCode Patch ###
201+
# Ignore all local history of files
202+
.history
203+
.ionide
204+
205+
# End of https://www.toptal.com/developers/gitignore/api/git,python,visualstudiocode

.type_stubs/.gitkeep

Whitespace-only changes.

.vscode/settings.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"[python]": {
3+
"editor.insertSpaces": true,
4+
"editor.tabSize": 4,
5+
"editor.rulers": [
6+
119
7+
],
8+
"editor.codeActionsOnSave": {
9+
"source.organizeImports": true,
10+
"source.fixAll": true
11+
}
12+
},
13+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python3",
14+
"python.envFile": "${workspaceFolder}/.venv",
15+
"python.languageServer": "Pylance",
16+
"python.formatting.provider": "yapf",
17+
"python.formatting.yapfPath": "${workspaceFolder}/.venv/bin/yapf",
18+
"python.linting.enabled": true,
19+
"python.linting.pylintEnabled": true,
20+
"python.linting.pylintPath": "${workspaceFolder}/.venv/bin/pylint",
21+
"python.linting.mypyEnabled": true,
22+
"python.linting.mypyArgs": [
23+
"--config-file ${workspaceFolder}/pyproject.toml"
24+
],
25+
"python.testing.pytestEnabled": true,
26+
"python.testing.pytestArgs": [
27+
"."
28+
],
29+
"[toml]": {
30+
"editor.defaultFormatter": "tamasfe.even-better-toml"
31+
},
32+
"python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy"
33+
}

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Python Poetry Template
2+
3+
This template is designed to make it easy to set up a Python project that is well-structured, organized, and easy to maintain. It comes pre-configured with several tools that will help you develop your project more efficiently, including:
4+
5+
- Visual Studio Code integration: with the `RunOnSave`, `even-better-toml` and `ruff` extensions installed, you can format, lint, and type-check your code automatically every time you save a file.
6+
- Type checking: this template is configured to use `mypy` and `pyright` to automatically infer types when possible, without imposing strict typing requirements on your code.
7+
- Linting: `ruff`, an extremely fast Python linter, written in Rust is configured well to help you catch and fix code style issues.
8+
- Formatting: `yapf`, `ruff`, and `unify` are configured to help you keep your code clean and well-organized.
9+
- Testing: `pytest` is configured to make it easy to run tests, and `pytest-cov` is configured to help you measure code coverage.
10+
- Dependency management: `poetry` is configured to help you manage your project's dependencies.
11+
- Toolkits: `invoke` is configured to provide a range of useful tasks, such as running your code, running tests, formatting your code, and checking your code style and types. These tasks are fully configurable in the [tasks.py](tasks.py) file.
12+
13+
## Installation
14+
15+
To install this template, simply follow these steps:
16+
17+
```sh
18+
git clone [email protected]:code-yeongyu/Python-Poetry-Template.git
19+
cd Python-Poetry-Template
20+
poetry install
21+
code --install-extension emeraldwalk.RunOnSave
22+
code --install-extension tamasfe.even-better-toml
23+
code --install-extension charliermarsh.ruff
24+
```
25+
26+
## Usage
27+
28+
To use this template, you can follow these steps:
29+
30+
### Open Shell
31+
32+
To open a shell in the project directory, use the following command:
33+
34+
```sh
35+
poetry shell
36+
```
37+
38+
### Name your project
39+
40+
```sh
41+
invoke rename-project <your-project-name>
42+
```
43+
44+
### Run Code
45+
46+
To run your code, use the following command:
47+
48+
```sh
49+
poetry run invoke run
50+
```
51+
52+
### Run Tests
53+
54+
To run your tests, use the following command:
55+
56+
```sh
57+
poetry run invoke test
58+
```
59+
60+
### Run Formatters
61+
62+
To run the code formatters, use the following command:
63+
64+
```sh
65+
poetry run invoke format_code
66+
```
67+
68+
### Run Checking Code Style & Type hint
69+
70+
To check your code style and type hints, use the following command:
71+
72+
```sh
73+
poetry run invoke check
74+
```

0 commit comments

Comments
 (0)