Skip to content

Commit f036408

Browse files
committed
Bumped Python version to 3.10; bumped dependencies.
1 parent 31e25ad commit f036408

File tree

12 files changed

+477
-548
lines changed

12 files changed

+477
-548
lines changed

Diff for: Makefile

+59-39
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,91 @@
1-
SRCPATH := $(shell pwd)
2-
PROJECTNAME := $(shell basename $(CURDIR))
3-
ENTRYPOINT := $(PROJECTNAME).ini
1+
PROJECT_NAME := $(shell basename $CURDIR)
2+
VIRTUAL_ENV := $(CURDIR)/.venv
3+
LOCAL_PYTHON := $(VIRTUAL_ENV)/bin/python3
44

55
define HELP
6-
Manage $(PROJECTNAME). Usage:
7-
8-
make run - Run $(PROJECTNAME).
9-
make deploy - Pull latest build and deploy to production.
10-
make update - Update pip dependencies via Python Poetry.
11-
make format - Format code with Python's `Black` library.
12-
make lint - Check code formatting with flake8
13-
make clean - Remove cached files and lock files.
14-
endef
15-
export HELP
16-
6+
Manage $(PROJECT_NAME). Usage:
177

18-
.PHONY: run restart deploy update format lint clean help
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.
1915

20-
requirements: .requirements.txt
21-
env: ./.venv/bin/activate
16+
endef
17+
export HELP
2218

23-
.requirements.txt: requirements.txt
24-
$(shell . .venv/bin/activate && pip install -r requirements.txt)
2519

20+
.PHONY: run install deploy update format lint clean help
2621

2722
all help:
2823
@echo "$$HELP"
2924

25+
env: $(VIRTUAL_ENV)
26+
27+
$(VIRTUAL_ENV):
28+
if [ ! -d $(VIRTUAL_ENV) ]; then \
29+
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
30+
python3 -m venv $(VIRTUAL_ENV); \
31+
fi
32+
33+
.PHONY: dev
34+
dev: env
35+
$(LOCAL_PYTHON) -m main --reload
3036

3137
.PHONY: run
3238
run: env
33-
python main.py
39+
$(LOCAL_PYTHON) -m main
3440

41+
.PHONY: install
42+
install: env
43+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
44+
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
45+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
3546

3647
.PHONY: deploy
3748
deploy:
38-
make clean
39-
$(shell . ./deploy.sh)
49+
make install && \
50+
make run
4051

52+
.PHONY: test
53+
test: env
54+
$(LOCAL_PYTHON) -m \
55+
coverage run -m pytest -vv \
56+
--disable-pytest-warnings && \
57+
coverage html --title='Coverage Report' -d .reports && \
58+
open .reports/index.html
4159

4260
.PHONY: update
4361
update: env
44-
.venv/bin/python3 -m pip install --upgrade pip setuptools wheel
45-
poetry update
46-
poetry export -f requirements.txt --output requirements.txt --without-hashes
47-
62+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
63+
poetry update && \
64+
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
65+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4866

4967
.PHONY: format
5068
format: env
51-
$(shell . .venv/bin/activate && isort ./)
52-
$(shell . .venv/bin/activate && black ./)
53-
69+
$(LOCAL_PYTHON) -m isort --multi-line=3 . && \
70+
$(LOCAL_PYTHON) -m black .
5471

5572
.PHONY: lint
56-
lint:
57-
flake8 . --count \
73+
lint: env
74+
$(LOCAL_PYTHON) -m flake8 . --count \
5875
--select=E9,F63,F7,F82 \
59-
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
76+
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
6077
--show-source \
6178
--statistics
6279

63-
6480
.PHONY: clean
6581
clean:
66-
find . -name '*.pyc' -delete
67-
find . -name '__pycache__' -delete
68-
find . -name 'poetry.lock' -delete
69-
find . -name 'Pipefile.lock' -delete
70-
find . -name 'logs/*' -delete
71-
find . -name '.pytest_cache' -delete
82+
find . -name 'poetry.lock' -delete && \
83+
find . -name '.coverage' -delete && \
84+
find . -name '.Pipfile.lock' -delete && \
85+
find . -wholename '**/*.pyc' -delete && \
86+
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
87+
find . -type d -wholename './.venv' -exec rm -rf {} + && \
88+
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
89+
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + && \
90+
find . -type d -wholename './logs/*.log' -exec rm -rf {} + && \
91+
find . -type d -wholename './.reports/*' -exec rm -rf {} +

Diff for: database/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .connect import engine, session
1+
from .db import engine, session

Diff for: database/connect.py renamed to database/db.py

File renamed without changes.

Diff for: deploy.sh

-12
This file was deleted.

Diff for: mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[mypy]
2-
python_version = 3.8
2+
python_version = 3.10
33
warn_return_any = True
44
warn_unused_configs = True

Diff for: poetry.lock

+374-469
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ keywords = [
1818
]
1919

2020
[tool.poetry.dependencies]
21-
python = "^3.8"
21+
python = "^3.10, <4.0"
2222
sqlalchemy = "*"
2323
pymysql = "*"
2424
python-dotenv = "*"
25-
loguru = "^0.5.3"
26-
27-
[tool.poetry.dev-dependencies]
25+
loguru = "*"
2826
pytest = "*"
2927
mock = "*"
3028
mypy = "*"
31-
black = "^20.8b1"
32-
isort = "^5.6.4"
33-
flake8 = "^3.8.4"
29+
black = "*"
30+
isort = "*"
31+
flake8 = "*"
3432

3533
[tool.poetry.scripts]
3634
run = "main:init_script"

Diff for: requirements.txt

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
colorama==0.4.4; python_version >= "3.5" and python_full_version < "3.0.0" and sys_platform == "win32" or sys_platform == "win32" and python_version >= "3.5" and python_full_version >= "3.5.0"
2-
greenlet==1.0.0; python_version >= "3" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3"
3-
loguru==0.5.3; python_version >= "3.5"
4-
pymysql==1.0.2; python_version >= "3.6"
5-
python-dotenv==0.16.0
6-
sqlalchemy==1.4.3; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.6.0")
7-
win32-setctime==1.0.3; sys_platform == "win32" and python_version >= "3.5"
1+
black==23.7.0 ; python_version >= "3.10" and python_version < "4.0"
2+
click==8.1.7 ; python_version >= "3.10" and python_version < "4.0"
3+
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
4+
exceptiongroup==1.1.3 ; python_version >= "3.10" and python_version < "3.11"
5+
flake8==6.1.0 ; python_version >= "3.10" and python_version < "4.0"
6+
greenlet==2.0.2 ; python_version >= "3.10" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
7+
iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "4.0"
8+
isort==5.12.0 ; python_version >= "3.10" and python_version < "4.0"
9+
loguru==0.7.0 ; python_version >= "3.10" and python_version < "4.0"
10+
mccabe==0.7.0 ; python_version >= "3.10" and python_version < "4.0"
11+
mock==5.1.0 ; python_version >= "3.10" and python_version < "4.0"
12+
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
13+
mypy==1.5.1 ; python_version >= "3.10" and python_version < "4.0"
14+
packaging==23.1 ; python_version >= "3.10" and python_version < "4.0"
15+
pathspec==0.11.2 ; python_version >= "3.10" and python_version < "4.0"
16+
platformdirs==3.10.0 ; python_version >= "3.10" and python_version < "4.0"
17+
pluggy==1.3.0 ; python_version >= "3.10" and python_version < "4.0"
18+
pycodestyle==2.11.0 ; python_version >= "3.10" and python_version < "4.0"
19+
pyflakes==3.1.0 ; python_version >= "3.10" and python_version < "4.0"
20+
pymysql==1.1.0 ; python_version >= "3.10" and python_version < "4.0"
21+
pytest==7.4.0 ; python_version >= "3.10" and python_version < "4.0"
22+
python-dotenv==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
23+
sqlalchemy==2.0.20 ; python_version >= "3.10" and python_version < "4.0"
24+
tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
25+
typing-extensions==4.7.1 ; python_version >= "3.10" and python_version < "4.0"
26+
win32-setctime==1.1.0 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32"

Diff for: sqlalchemy_tutorial/cleanup.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
def cleanup_data():
10+
"""Purge test database of all data."""
1011
try:
1112
session.execute(text("SET FOREIGN_KEY_CHECKS=0;"))
1213
session.commit()
@@ -20,8 +21,9 @@ def cleanup_data():
2021
session.commit()
2122
LOGGER.success("Successfully reset all data.")
2223
except IntegrityError as e:
23-
LOGGER.error(e.orig)
24-
raise e.orig
24+
LOGGER.error(f"Integrity error when resetting data: {e}")
2525
except SQLAlchemyError as e:
26+
LOGGER.error(f"SQLAlchemyError error when resetting data: {e}")
27+
except Exception as e:
2628
LOGGER.error(f"Unexpected error when resetting data: {e}")
27-
raise e
29+

Diff for: sqlalchemy_tutorial/part2_orm/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Create and delete SQL records using SQLAlchemy's ORM."""
12
from database import session
23
from sqlalchemy_tutorial.part2_orm.models import User
34

Diff for: sqlalchemy_tutorial/part2_orm/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class User(Base):
2727
updated_at = Column(DateTime, onupdate=func.now())
2828

2929
def __repr__(self):
30-
return "<User %r>" % self.username
30+
return f"<User id={self.id}, username={self.username}, email={self.email}>"
3131

3232

3333
Base.metadata.create_all(engine)

Diff for: sqlalchemy_tutorial/part2_orm/orm.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ def orm_create_user(session: Session, user: User) -> User:
1010
"""
1111
Create a new instance of our `User` model.
1212
13-
:param session: SQLAlchemy database session.
14-
:type session: Session
15-
:param user: User data model for creation.
16-
:type user: User
13+
:param Session session: SQLAlchemy database session.
14+
:param User user: User data model for creation.
1715
1816
:return: User
1917
"""
@@ -34,10 +32,8 @@ def orm_delete_user(session: Session, user: User):
3432
"""
3533
Delete a user if it exists.
3634
37-
:param session: SQLAlchemy database session.
38-
:type session: Session
39-
:param user: User to be deleted.
40-
:type user: User
35+
:param Session session: SQLAlchemy database session.
36+
:param User user: User to be deleted.
4137
4238
:return: None
4339
"""

0 commit comments

Comments
 (0)