Skip to content

Commit 3a5e29a

Browse files
authored
Merge pull request #32 from pritam001/feature-personalization
Feature personalization
2 parents f6aecf7 + 68fee1c commit 3a5e29a

34 files changed

+689
-149
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.8]
11+
python-version: [3.7, 3.8]
1212

1313
steps:
1414
- uses: actions/checkout@v2
@@ -19,9 +19,10 @@ jobs:
1919
- name: Install pip
2020
run: |
2121
python -m pip install --upgrade pip
22-
- name: Setup project
22+
- name: Install dependencies
2323
run: |
24-
make setup
24+
pip3 install pip-tools
25+
pip-sync requirements/requirements.txt requirements/dev-requirements.txt
2526
- name: Lint
2627
run: |
2728
pip install flake8

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ venv/
109109
ENV/
110110
env.bak/
111111
venv.bak/
112+
pyflask-base-env/
112113

113114
# Spyder project settings
114115
.spyderproject

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/ambv/black
5-
rev: stable
4+
- repo: https://github.com/psf/black
5+
rev: 20.8b1
66
hooks:
77
- id: black
8+
# pyflask_config: python_version
89
language_version: python3.8
910
- repo: https://gitlab.com/pycqa/flake8
10-
rev: 3.8.3
11+
rev: 3.8.4
1112
hooks:
1213
- id: flake8
1314
- repo: https://github.com/pre-commit/mirrors-isort
14-
rev: v5.3.2
15+
rev: v5.7.0
1516
hooks:
1617
- id: isort

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# pyflask_config: python_version
2+
FROM tiangolo/uwsgi-nginx:python3.8
3+
4+
# pyflask_config: docker_maintainer_details
5+
LABEL maintainer="User <[email protected]>"
6+
7+
#RUN make setup
8+
#
9+
## Move the base entrypoint to reuse it
10+
#RUN mv /entrypoint.sh /uwsgi-nginx-entrypoint.sh
11+
## Copy the entrypoint that will generate Nginx additional configs
12+
#COPY entrypoint.sh /entrypoint.sh
13+
#RUN chmod +x /entrypoint.sh
14+
#
15+
#ENTRYPOINT ["/entrypoint.sh"]
16+
17+
# Run the start script provided by the parent image tiangolo/uwsgi-nginx.
18+
# It will check for an /app/prestart.sh script (e.g. for migrations)
19+
# And then will start Supervisor, which in turn will start Nginx and uWSGI
20+
#CMD ["/prestart.sh"]

Makefile

Lines changed: 101 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
CONDA_ENV_NAME=pyflask-base
2-
APP_NAME=pyflask-service
1+
# pyflask_config: python_env_name
2+
PYTHON_ENV_NAME=pyflask-base-env
3+
# pyflask_config: service_name
4+
APPLICATION_NAME=pyflask-microservice
5+
36
APP_DIR=src
47
TEST_DIR=test
8+
SCRIPTS_DIR=scripts
59
HOME_DIR_PY_FILES=*.py
610

711
# echo _FormatCode_ guide:
812
# 0 Reset all styles
913
# 1 Bold
14+
# 31 Red
1015
# 32 Green
1116
# 34 Blue
1217
# 35 Magenta
1318
# 36 Cyan
1419
RESET_STYLES=\033[0m
20+
BOLD_RED=\033[1m\033[31m
21+
BOLD_GREEN=\033[1m\033[32m
1522
BOLD_BLUE=\033[1m\033[34m
23+
BOLD_MAGENTA=\033[1m\033[35m
1624
BOLD_CYAN=\033[1m\033[36m
1725

1826
# Signifies our desired python version
@@ -21,7 +29,7 @@ PYTHON = python3
2129

2230
# .PHONY defines parts of the makefile that are not dependant on any specific file
2331
# This is most often used to store functions
24-
.PHONY = all help setup format lint format-n-lint test-n-cover pre-commit clean
32+
.PHONY = all help init setup upgrade format lint format-n-lint test-n-cover pre-commit debug-run dev-run prod-run docker-build docker-run clean wipe clean-n-wipe
2533

2634
# Defining an array variable
2735
IGNORED_FILES_AND_FOLDERS = .mypy_cache/ .pytest_cache/ htmlcov/ logs/ .coverage
@@ -34,91 +42,144 @@ IGNORED_FILES_AND_FOLDERS = .mypy_cache/ .pytest_cache/ htmlcov/ logs/ .coverage
3442
# The @ makes sure that the command itself isn't echoed in the terminal
3543
help:
3644
@echo "$(BOLD_BLUE)-----------------------------MAKE GUIDE----------------------------$(RESET_STYLES)"
37-
@echo "$(BOLD_CYAN)make setup$(RESET_STYLES) : Setup pyflask-service"
38-
@echo "$(BOLD_CYAN)make format$(RESET_STYLES) : Format and fix python code in pyflask-service"
39-
@echo "$(BOLD_CYAN)make lint$(RESET_STYLES) : Lint pyflask-service"
40-
@echo "$(BOLD_CYAN)make format-n-lint$(RESET_STYLES) : Format and lint python code in pyflask-service"
41-
@echo "$(BOLD_CYAN)make test-n-cover$(RESET_STYLES) : Test and code coverage pyflask-service"
42-
@echo "$(BOLD_CYAN)make pre-commit$(RESET_STYLES) : Run pre-commit checks for pyflask-service"
43-
@echo "$(BOLD_CYAN)make debug$(RESET_STYLES) : Debug pyflask-service"
44-
@echo "$(BOLD_CYAN)make clean$(RESET_STYLES) : Clean pyflask-service"
45-
@echo "$(BOLD_CYAN)make dev-run$(RESET_STYLES) : Run pyflask-service in environment=development"
46-
@echo "$(BOLD_CYAN)make prod-run$(RESET_STYLES) : Run pyflask-service in environment=prod"
45+
@echo "$(BOLD_CYAN)make init$(RESET_STYLES) : Initialize pyflask-microservice"
46+
@echo "$(BOLD_CYAN)make setup$(RESET_STYLES) : Setup pyflask-microservice"
47+
@echo "$(BOLD_CYAN)make upgrade$(RESET_STYLES) : Upgrade dependencies of pyflask-microservice"
48+
@echo "$(BOLD_CYAN)make format$(RESET_STYLES) : Format and fix python code in pyflask-microservice"
49+
@echo "$(BOLD_CYAN)make lint$(RESET_STYLES) : Lint pyflask-microservice"
50+
@echo "$(BOLD_CYAN)make format-n-lint$(RESET_STYLES) : Format and lint python code in pyflask-microservice"
51+
@echo "$(BOLD_CYAN)make test-n-cover$(RESET_STYLES) : Test and code coverage pyflask-microservice"
52+
@echo "$(BOLD_CYAN)make pre-commit$(RESET_STYLES) : Run pre-commit checks for pyflask-microservice"
53+
@echo "$(BOLD_CYAN)make debug-run$(RESET_STYLES) : Debug pyflask-microservice"
54+
@echo "$(BOLD_CYAN)make dev-run$(RESET_STYLES) : Run pyflask-microservice in environment=development"
55+
@echo "$(BOLD_CYAN)make prod-run$(RESET_STYLES) : Run pyflask-microservice in environment=prod"
56+
@echo "$(BOLD_CYAN)make docker-build$(RESET_STYLES) : Build docker image for pyflask-microservice"
57+
@echo "$(BOLD_CYAN)make docker-run$(RESET_STYLES) : Run docker image for pyflask-microservice"
58+
@echo "$(BOLD_CYAN)make clean$(RESET_STYLES) : Clean pyflask-microservice"
59+
@echo "$(BOLD_CYAN)make wipe$(RESET_STYLES) : Wipe pyflask-microservice"
60+
@echo "$(BOLD_CYAN)make clean-n-wipe$(RESET_STYLES) : Clean and wipe pyflask-microservice"
4761
@echo "$(BOLD_BLUE)-------------------------------------------------------------------$(RESET_STYLES)"
4862

4963

64+
init: #: Initialize and personalize python environment
65+
@echo "\n$(BOLD_BLUE)Initialize pyflask-microservice$(RESET_STYLES)"
66+
sh scripts/dev/service_init.sh
67+
68+
5069
setup: #: Use pip-tools, pip-compile, pip install
51-
@echo "\n$(BOLD_CYAN)Setting up pyflask base$(RESET_STYLES)"
52-
# Check for venv, conda else exit
70+
@echo "\n$(BOLD_BLUE)Setting up pyflask-microservice$(RESET_STYLES)"
71+
@echo "\n$(BOLD_CYAN)Activating python environment . . .$(RESET_STYLES)"
72+
sh scripts/dev/activate_python_env.sh
73+
sh scripts/dev/check_python_env.sh
74+
@echo "\n$(BOLD_CYAN)Checking dependencies . . .$(RESET_STYLES)"
75+
sh scripts/dev/check_env_manager.sh
76+
sh scripts/dev/check_python_version.sh
5377
@echo "\n$(BOLD_CYAN)Installing pip-tools . . .$(RESET_STYLES)"
54-
pip install pip-tools
78+
pip3 install pip-tools
5579
@echo "\n$(BOLD_CYAN)Generating requirements$(RESET_STYLES)"
5680
pip-compile -q --build-isolation --output-file=requirements/requirements.txt requirements/requirements.in
5781
@echo "\n$(BOLD_CYAN)Generating dev requirements$(RESET_STYLES)"
5882
pip-compile -q --build-isolation --output-file=requirements/dev-requirements.txt requirements/dev-requirements.in
5983
@echo "\n$(BOLD_CYAN)Syncing requirements$(RESET_STYLES)"
60-
pip-sync -q requirements/requirements.txt requirements/dev-requirements.txt
61-
@echo "\n$(BOLD_CYAN)Installing requirements$(RESET_STYLES)"
62-
pip install -r requirements/requirements.txt
63-
@echo "\n$(BOLD_CYAN)Installing dev requirements$(RESET_STYLES)"
64-
pip install -r requirements/dev-requirements.txt
84+
pip-sync requirements/requirements.txt requirements/dev-requirements.txt
6585
@echo "\n$(BOLD_CYAN)Adding pre-commit hooks$(RESET_STYLES)"
6686
pre-commit install
87+
@echo "\n$(BOLD_GREEN)Setup complete$(RESET_STYLES)"
88+
89+
90+
upgrade: #: upgrade requirements to latest versions
91+
@echo "\n$(BOLD_BLUE)Upgrading dependencies of pyflask-microservice$(RESET_STYLES)"
92+
python3 -m pip install --upgrade pip
93+
pip-compile --upgrade requirements/requirements.in --output-file requirements/requirements.txt
94+
pip-compile --upgrade requirements/dev-requirements.in --output-file requirements/dev-requirements.txt
95+
@echo "\n$(BOLD_GREEN)Upgrade complete$(RESET_STYLES)"
6796

6897

6998
format: #: Format and fix python code with black, isort, autoflake
70-
@echo "\n$(BOLD_CYAN)Blackifying$(RESET_STYLES) 🍳"
99+
@echo "\n$(BOLD_BLUE)Blackifying$(RESET_STYLES) 🍳"
71100
black --version
72-
black $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
101+
black $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) $(SCRIPTS_DIR)
73102
@echo "\n$(BOLD_CYAN)ISorting$(RESET_STYLES) 〽️️"
74-
isort --recursive $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
103+
isort $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) $(SCRIPTS_DIR)
75104
@echo "\n$(BOLD_CYAN)Flaking$(RESET_STYLES) ❄️"
76105
flake8 --version
77-
autoflake --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --ignore-init-module-imports -i -r $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
78-
@echo "\n$(BOLD_CYAN)Running pre-commit hooks$(RESET_STYLES) 🏁️️️"
79-
pre-commit run --all-files
80-
@echo "\n$(BOLD_CYAN)All checks passed$(RESET_STYLES) 🏳️️️️"
81-
@echo "\n"
106+
autoflake --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --ignore-init-module-imports -i -r $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) $(SCRIPTS_DIR)
82107

83108

84109
lint: #: Run static analysis with flake8, radon, mypy and bandit
85110
@echo "\n$(BOLD_CYAN)Linting with flake8$(RESET_STYLES) ❄️"
86111
flake8 --version
87-
flake8 $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
112+
flake8 $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) $(SCRIPTS_DIR)
88113
@echo "\n$(BOLD_CYAN)Checking cyclomatic complexity with radon$(RESET_STYLES) 💫️"
89114
radon --version
90-
radon cc $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) --total-average -nc
115+
radon cc $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) $(SCRIPTS_DIR) --total-average -nc
91116
@echo "\n$(BOLD_CYAN)Static typing with mypy$(RESET_STYLES) ⌨️"
92117
mypy --version
93118
mypy $(APP_DIR) $(HOME_DIR_PY_FILES)
94119
@echo "\n$(BOLD_CYAN)Securing with bandit$(RESET_STYLES) 🕵️️"
95120
bandit --version
96-
bandit -l -i -r . --format=custom -c .bandit.yml -x ./$(TEST_DIR)
121+
bandit -l -i -r . --format=custom -c .bandit.yml -x ./$(TEST_DIR),./$(PYTHON_ENV_NAME)
97122
@echo "\n"
98123

99124

100125
format-n-lint: #: Format and lint
101-
make format
102-
make lint
126+
make --no-print-directory format
127+
make --no-print-directory lint
103128
@echo "\n"
104129

105130

106131
test-n-cover: #: Test with pytest, Code coverage with pytest-cov plugin
107-
@echo "\n$(BOLD_CYAN)Testing with pytest$(RESET_STYLES) 📊️"
132+
@echo "\n$(BOLD_BLUE)Testing with pytest$(RESET_STYLES) 📊️"
108133
pytest --version
109134
pytest
110135
@echo "\n"
111136

112137

113138
pre-commit: #: Run pre-commit checks : format, lint, test, cover
114-
make format-n-lint
115-
make test-n-cover
116-
@echo "\n$(BOLD_CYAN)Pre commit jobs completed$(RESET_STYLES) 👍"
117-
@echo "\n"
139+
@echo "\n$(BOLD_BLUE)Starting pre-commit jobs . . .$(RESET_STYLES)"
140+
make --no-print-directory format-n-lint
141+
@echo "\n$(BOLD_CYAN)Running pre-commit hooks$(RESET_STYLES) 🏁️️️"
142+
pre-commit run --all-files
143+
@echo "\n$(BOLD_GREEN)All checks passed$(RESET_STYLES) 🏳️️️️"
144+
make --no-print-directory test-n-cover
145+
@echo "\n$(BOLD_GREEN)Pre-commit jobs completed$(RESET_STYLES) 👍"
146+
147+
148+
debug-run: #: Run application in debug mode
149+
@echo "\n$(BOLD_BLUE)Starting application in debug mode . . .$(RESET_STYLES)"
150+
FLASK_ENV=development python3 service_master.py
151+
152+
153+
dev-run: #: Run application in dev mode
154+
@echo "\n$(BOLD_BLUE)Starting application in dev mode . . .$(RESET_STYLES)"
155+
FLASK_ENV=development python3 service_master.py
156+
157+
158+
prod-run: #: Run application in prod mode
159+
@echo "\n$(BOLD_BLUE)Starting application in prod mode . . .$(RESET_STYLES)"
160+
FLASK_ENV=prod python3 service_master.py
161+
162+
163+
docker-build: #: Build docker image for the application
164+
@echo "\n$(BOLD_BLUE)Building docker image . . .$(RESET_STYLES)"
165+
166+
167+
docker-start: #: Start docker image for the application
168+
@echo "\n$(BOLD_BLUE)Starting dockerized application . . .$(RESET_STYLES)"
118169

119170

120171
clean: #: Clean unnecessary files
121172
@echo "\n$(BOLD_CYAN)Cleaning unnecessary files$(RESET_STYLES) 🚿"
122173
rm -rf $(IGNORED_FILES_AND_FOLDERS)
123-
@echo "\n"
174+
175+
176+
wipe: #: Wipe python environment
177+
@echo "\n$(BOLD_CYAN)Wiping environment$(RESET_STYLES) 🚿"
178+
sh scripts/dev/service_wipe.sh
179+
180+
181+
clean-n-wipe: #: Clean project and wipe environment
182+
@echo "\n$(BOLD_BLUE)Cleaning up project and wiping environment$(RESET_STYLES)"
183+
make --no-print-directory clean
184+
make --no-print-directory wipe
124185

README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[//]: <> (pyflask_config: service_name)
12
pyflask-microservice-base
23
------------------------------------------------------------------------------
34
An "optionally opinionated and structured" flask boilerplate microservice for jump-starting development
@@ -17,7 +18,8 @@ Project status
1718

1819
Tools
1920
------------------------------------------------------------------------------
20-
[![Min Python Version 3.8+](https://img.shields.io/badge/python-3.8+-3776AB.svg?style=flat)](https://www.python.org/download/releases/3.8.0/)
21+
[![Min Python Version 3.7](https://img.shields.io/badge/python-3.7+-3776AB.svg?style=flat)](https://www.python.org/download/releases/3.8.0/)
22+
[![Min GNU Make Version 4.3](https://img.shields.io/badge/make-4.3+-222222.svg?style=flat)](https://www.gnu.org/software/make/manual/make.html)
2123
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat)](https://github.com/psf/black)
2224
[![Static Analysis: flake8](https://img.shields.io/badge/static%20analysis-flake8-cccccc.svg?style=flat)](https://github.com/PyCQA/flake8/)
2325
[![Cyclomatic Complexity: radon](https://img.shields.io/badge/cyclomatic%20complexity-radon-ff5252.svg?style=flat)](https://github.com/rubik/radon)
@@ -40,10 +42,11 @@ This is a template project hosted on GitHub which can be used to create new repo
4042
1. Create a new repository named "my-pyflask-project" using this template repository *+
4143
1. `git clone https://www.github.com/username/my-pyflask-project.git`
4244
1. `cd my-pyflask-project`
43-
1. Create and activate conda environment
44-
`conda init my-conda-venv`
45-
`conda activate my-conda-venv` *^
46-
1. `make setup` : Use pip-tools, pip-compile, pip install to setup python packages
45+
1. `make init` : Initialize and personalize project
46+
1. `make setup` : Use pip-tools, pip-compile, pip install to set up python packages
47+
1. `make upgrade` : Upgrade dependencies to latest version
48+
1. `make pre-commit` : Run format, lint, test and cover
49+
1. Run `git add .` and `git commit -m "Personalize service"`
4750

4851
*+ [GitHub Guide: Creating a repository from a template](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template)
4952
<br>
@@ -71,44 +74,35 @@ Type `make pre-commit` before committing your changes to run formatters, linters
7174

7275

7376
### Documentation
74-
Flasgger docs can be found at http://0.0.0.0:8420/api/v1/pyflask-service/swagger
77+
[//]: <> (pyflask_config: service_name)
78+
Flasgger docs can be found at http://0.0.0.0:8420/api/v1/pyflask-microservice/swagger
7579

76-
API specs can be found at http://0.0.0.0:8420/api/v1/pyflask-service/swagger_spec
80+
[//]: <> (pyflask_config: service_name)
81+
API specs can be found at http://0.0.0.0:8420/api/v1/pyflask-microservice/swagger_spec
7782

7883
Flasgger UI version: v2 | OpenAPI version: 2
7984

8085
<p align="center"><img src="documentation/assets/flasgger_intro.png" /></p>
8186

8287

83-
Development Setup
84-
------------------------------------------------------------------------------
85-
To be updated
86-
87-
8888
Contributing
8989
------------------------------------------------------------------------------
9090
1. Stargaze this repository
9191
1. Fork this repository
92+
1. Add this project as `upstream`
9293
1. Commit your changes
93-
1. Create pull request to `development` branch
94-
95-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/0)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/0)
96-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/1)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/1)
97-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/2)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/2)
98-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/3)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/3)
99-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/4)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/4)
100-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/5)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/5)
101-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/6)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/6)
102-
[![](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/images/7)](https://sourcerer.io/fame/pritam001/pritam001/pyflask-microservice-base/links/7)
103-
94+
1. Create pull request to `upstream/development` branch
10495

105-
TODO
96+
Roadmap
10697
-----------------------------------------------------------------------------
10798
- [x] Swagger support
108-
- [ ] Update linting documentation
10999
- [x] Introduction of testing tools
110-
- [ ] Testing tools documentation
111100
- [x] Code coverage
112-
- [ ] Version handling by tbump
101+
- [x] Version handling by tbump
102+
- [ ] Personalization script
103+
- [ ] Docker support
104+
- [ ] uwsgi server
113105
- [ ] Add CoC, Contribution guidelines, PR and issue templates
106+
- [ ] Update linting documentation
107+
- [ ] Testing tools documentation
114108

docker_build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# pyflask_config: service_name
4+
app="docker.image.pyflask-microservice"
5+
docker build -t ${app} .
6+
docker run -d -p 56733:80 --name=${app} -v "$PWD":/app ${app}

0 commit comments

Comments
 (0)