Skip to content

Commit ad4148e

Browse files
committed
Support cookiecutter
1 parent 63ba324 commit ad4148e

File tree

21 files changed

+234
-51
lines changed

21 files changed

+234
-51
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@ jobs:
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install flake8 pytest mypy
29+
pip install cookiecutter flake8 pytest mypy
3030
pip install .
31-
- name: Lint
31+
- name: CI
3232
run: |
33-
make lint
34-
- name: Test
35-
run: |
36-
make test
37-
- name: Type checking
38-
run: |
39-
make typecheck
33+
make create-project-no-input && make ci

Makefile

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
11

2-
##### docker
3-
IMAGE_NAME := python-api-template
4-
CONTAINER_NAME := ${IMAGE_NAME}-container
5-
SRC_PORT := 4600
6-
DST_PORT := 9876
2+
PROJECT_NAME := manaysh_api
3+
DESCRIPTION := hoge
74

8-
build-image:
9-
docker build -t ${IMAGE_NAME} ./
5+
##### cookiecutter
6+
create-project:
7+
cookiecutter ./
108

11-
run-container:
12-
docker run -it -d \
13-
--name ${CONTAINER_NAME} \
14-
-p ${SRC_PORT}:${DST_PORT} \
15-
${IMAGE_NAME}
9+
create-project-no-input:
10+
cookiecutter --no-input ./ \
11+
project_slug=${PROJECT_NAME} \
12+
description=${DESCRIPTION}
1613

17-
##### ci
18-
ci: typecheck test lint
14+
ci:
15+
cd ${PROJECT_NAME} && make ci
1916

20-
typecheck:
21-
@echo check types
22-
mypy ./python_api_template
23-
24-
lint:
25-
@echo check style
26-
flake8 --show-source --statistics
27-
28-
test:
29-
@echo testing
30-
pytest -rf --cov=./python_api_template
31-
32-
33-
##### application
34-
GUNICORN_CONFIG_PATH := config/gunicorn.py
35-
36-
launch:
37-
gunicorn app:app -c ${GUNICORN_CONFIG_PATH}
38-
39-
launch-develop:
40-
python app.py
17+
clean:
18+
rm -rf ${PROJECT_NAME}

cookiecutter.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"project_slug": "python_api_template",
3+
"description": "hoge"
4+
}
File renamed without changes.
File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{% raw -%}
2+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
3+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
4+
5+
name: Python package
6+
7+
on:
8+
push:
9+
branches: [ master ]
10+
pull_request:
11+
branches: [ master ]
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: [3.7, 3.8]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v1
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install flake8 pytest mypy
31+
pip install .
32+
- name: Lint
33+
run: |
34+
make lint
35+
- name: Test
36+
run: |
37+
make test
38+
- name: Type checking
39+
run: |
40+
make typecheck
41+
{%- endraw %}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

Dockerfile renamed to {{ cookiecutter.project_slug }}/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ COPY . /app
1313

1414
WORKDIR /app
1515

16-
# update to avoid 'setup.py' not found error
17-
# RUN pip3 install -U pip
1816
RUN pip3 install .
1917

2018
RUN rm -rf /var/lib/apt/lists/*
File renamed without changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
##### docker
2+
IMAGE_NAME := {{ cookiecutter.project_slug }}
3+
CONTAINER_NAME := ${IMAGE_NAME}-container
4+
SRC_PORT := 4600
5+
DST_PORT := 9876
6+
7+
build-image:
8+
docker build -t ${IMAGE_NAME} ./
9+
10+
run-container:
11+
docker run -it -d \
12+
--name ${CONTAINER_NAME} \
13+
-p ${SRC_PORT}:${DST_PORT} \
14+
${IMAGE_NAME}
15+
16+
##### ci
17+
ci: typecheck test lint
18+
19+
typecheck:
20+
@echo check types
21+
mypy ./{{ cookiecutter.project_slug }}
22+
23+
lint:
24+
@echo check style
25+
flake8 --show-source --statistics
26+
27+
test:
28+
@echo testing
29+
pytest -rf --cov=./{{ cookiecutter.project_slug }}
30+
31+
32+
##### application
33+
GUNICORN_CONFIG_PATH := config/gunicorn.py
34+
35+
launch:
36+
gunicorn app:app -c ${GUNICORN_CONFIG_PATH}
37+
38+
launch-develop:
39+
python app.py

0 commit comments

Comments
 (0)