Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ddd10dc

Browse files
Modernize project structure.
1 parent 99fc69f commit ddd10dc

File tree

20 files changed

+944
-415
lines changed

20 files changed

+944
-415
lines changed

‎.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ dmypy.json
131131
# OSX
132132
.DS_Store
133133

134-
# PyCharm
135-
.idea
134+
# Idea
135+
.idea/
136136

137137
# Etc
138138
ignoreme.py

‎Makefile

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
PROJECT_NAME := $(shell basename $CURDIR)
2+
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
3+
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3
4+
5+
define HELP
6+
Manage $(PROJECT_NAME). Usage:
7+
8+
make run - Run $(PROJECT_NAME) locally.
9+
make install - Create local virtualenv & install dependencies.
10+
make deploy - Set up project & run locally.
11+
make update - Update dependencies via Poetry and output resulting `requirements.txt`.
12+
make format - Run Python code formatter & sort dependencies.
13+
make lint - Check code formatting with flake8.
14+
make clean - Remove extraneous compiled files, caches, logs, etc.
15+
16+
endef
17+
export HELP
18+
19+
20+
.PHONY: run restart install update format test lint clean help
21+
22+
23+
all help:
24+
@echo "$$HELP"
25+
26+
env: .venv/bin/activate
27+
28+
.PHONY: run
29+
run: env
30+
$(LOCAL_PYTHON) -m main
31+
32+
33+
.PHONY: install
34+
install:
35+
if [ ! -d "./.venv" ]; then python3 -m venv $(VIRTUAL_ENVIRONMENT); fi
36+
$(shell . .venv/bin/activate)
37+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel
38+
$(LOCAL_PYTHON) -m pip install -r requirements.txt
39+
40+
41+
.PHONY: deploy
42+
deploy:
43+
make clean
44+
make install
45+
make run
46+
47+
48+
.PHONY: update
49+
update:
50+
if [ ! -d "./.venv" ]; then python3 -m venv $(VIRTUAL_ENVIRONMENT); fi
51+
.venv/bin/python3 -m pip install --upgrade pip setuptools wheel
52+
poetry update
53+
poetry export -f requirements.txt --output requirements.txt --without-hashes
54+
55+
56+
.PHONY: test
57+
test: env
58+
$(LOCAL_PYTHON) -m \
59+
coverage run -m pytest -v \
60+
--disable-pytest-warnings \
61+
&& coverage html --title='Coverage Report' -d .reports \
62+
&& open .reports/index.html
63+
64+
65+
.PHONY: format
66+
format: env
67+
isort --multi-line=3 .
68+
black .
69+
70+
71+
.PHONY: lint
72+
lint:
73+
$(LOCAL_PYTHON) -m flake8 . --count \
74+
--select=E9,F63,F7,F82 \
75+
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
76+
--show-source \
77+
--statistics
78+
79+
80+
.PHONY: clean
81+
clean:
82+
find . -name '**/*.pyc' -delete
83+
find . -name '__pycache__' -delete
84+
find . -name 'poetry.lock' -delete
85+
find . -name 'Pipefile.lock' -delete
86+
find . -name '*.log' -delete
87+
find . -name '.coverage' -delete
88+
find . -wholename 'logs/*.json' -delete
89+
find . -type d -name '.pytest_cache' -exec rm -rf {} +
90+
find . -type d -name '**/.pytest_cache' -exec rm -rf {} +
91+
find . -type d -name './logs' -exec rm -rf {} +
92+
find . -type d -name './.reports' -exec rm -rf {} +
93+

‎Pipfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎Pipfile.lock

Lines changed: 0 additions & 117 deletions
This file was deleted.

‎README.md

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,27 @@
11
# Redis Python Tutorial
22

3-
![Python](https://img.shields.io/badge/Python-v3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4-
![Redis](https://img.shields.io/badge/Redis-v3.2.1-red.svg?longCache=true&style=flat-square&logo=redis&logoColor=white&colorA=4c566a&colorB=bf616a)
5-
![Loguru](https://img.shields.io/badge/Loguru-v0.4.1-blue.svg?longCache=true&logo=python&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-v3.9-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4+
![Redis](https://img.shields.io/badge/Redis-v4.2.2-red.svg?longCache=true&style=flat-square&logo=redis&logoColor=white&colorA=4c566a&colorB=bf616a)
5+
![Loguru](https://img.shields.io/badge/Loguru-v0.6.0-blue.svg?longCache=true&logo=python&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)
77
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/redis-python-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/redis-python-tutorial/issues)
88
[![GitHub Stars](https://img.shields.io/github/stars/hackersandslackers/redis-python-tutorial.svg?style=flat-square8&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/redis-python-tutorial/stargazers)
99
[![GitHub Forks](https://img.shields.io/github/forks/hackersandslackers/redis-python-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/redis-python-tutorial/network)
1010

1111
![Redis Python](https://res.cloudinary.com/hackers/image/upload/v1580673187/2020/02/redis%402x.jpg)
1212

13-
Source code for the accompanying tutorial found here: https://hackersandslackers.com/redis-py-python/
13+
Leverage in-memory data storage to cache data, handle user sessions, and avoid database transactions to keep your Python app snappy.
1414

15-
## Installation
15+
***Tutorial**: https://hackersandslackers.com/redis-py-python/
1616

17-
**Installation via `requirements.txt`**:
17+
## Getting Started
1818

19-
```shell
20-
$ git clone https://github.com/hackersandslackers/redis-python-tutorial.git
21-
$ cd redis-python-tutorial
22-
$ python3 -m venv myenv
23-
$ source myenv/bin/activate
24-
$ pip3 install -r requirements.txt
25-
$ python3 main.py
26-
```
27-
28-
**Installation via [Pipenv](https://pipenv-fork.readthedocs.io/en/latest/)**:
29-
30-
```shell
31-
$ git clone https://github.com/hackersandslackers/redis-python-tutorial.git
32-
$ cd redis-python-tutorial
33-
$ pipenv shell
34-
$ pipenv update
35-
$ python3 main.py
36-
```
37-
38-
**Installation via [Poetry](https://python-poetry.org/)**:
19+
### Installation
3920

4021
```shell
4122
$ git clone https://github.com/hackersandslackers/redis-python-tutorial.git
4223
$ cd redis-python-tutorial
43-
$ poetry shell
44-
$ poetry update
45-
$ poetry run
24+
$ make deploy
4625
```
4726

4827
-----

‎config.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
"""Construct Redis connection URI."""
2-
from os import environ
3-
from dotenv import load_dotenv
2+
from os import getenv, path
43

4+
from dotenv import load_dotenv
55

66
# Load environment variables
7-
basedir = path.abspath(path.dirname(__file__))
8-
load_dotenv(path.join(basedir, '.env'))
7+
BASE_DIR = path.abspath(path.dirname(__file__))
8+
load_dotenv(path.join(BASE_DIR, ".env"))
9+
10+
# Redis config
11+
REDIS_HOST = getenv("REDIS_HOST")
12+
REDIS_USERNAME = getenv("REDIS_USERNAME")
13+
REDIS_PASSWORD = getenv("REDIS_PASSWORD")
14+
REDIS_PORT = getenv("REDIS_PORT")
15+
REDIS_DB = getenv("REDIS_DB")
16+
REDIS_URI = f"redis://:{REDIS_HOST}@{REDIS_USERNAME}:{REDIS_PORT}/{REDIS_DB}"
917

10-
redis_host = environ.get('REDIS_HOST')
11-
redis_password = environ.get('REDIS_PASSWORD')
12-
redis_port = environ.get('REDIS_PORT')
13-
redis_db = environ.get('REDIS_DATABASE')
14-
redis_uri = f'redis://:{redis_host}@{redis_password}:{redis_port}/{redis_db}'
18+
REDIS_EXPIRATION = 604800
1519

16-
redis_expiration = 604800
20+
# Logging
21+
PERSIST_LOG_FILES = True

‎main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""Entry point."""
1+
"""Application entry point."""
22
from redis_python_tutorial import init_app
33

4-
app = init_app()
5-
64
if __name__ == "__main__":
7-
app
5+
init_app()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /