Skip to content

Commit 88b6c64

Browse files
committed
install and config lint, pytest, mypy
1 parent 198b37b commit 88b6c64

File tree

18 files changed

+120
-20
lines changed

18 files changed

+120
-20
lines changed

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
ignore = E501, E265, F811, PT001, DJ05, SIM113, SIM102, AAA01
3+
max-line-length = 160
4+
exclude =
5+
.git,
6+
__pycache__

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
lint:
2+
flake8 src
3+
mypy src
4+
5+
test:
6+
cd src && pytest

requirements.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
fastapi[all]
22
pytest
33
pip-tools
4+
45
pytest-httpx
56
pytest-mock
7+
pytest-env
8+
flake8
9+
mypy

requirements.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ exceptiongroup==1.0.4
2929
# via pytest
3030
fastapi[all]==0.87.0
3131
# via -r requirements.in
32+
flake8==6.0.0
33+
# via -r requirements.in
3234
h11==0.14.0
3335
# via
3436
# httpcore
@@ -54,6 +56,12 @@ jinja2==3.1.2
5456
# via fastapi
5557
markupsafe==2.1.1
5658
# via jinja2
59+
mccabe==0.7.0
60+
# via flake8
61+
mypy==0.991
62+
# via -r requirements.in
63+
mypy-extensions==0.4.3
64+
# via mypy
5765
orjson==3.8.2
5866
# via fastapi
5967
packaging==21.3
@@ -66,15 +74,22 @@ pip-tools==6.10.0
6674
# via -r requirements.in
6775
pluggy==1.0.0
6876
# via pytest
77+
pycodestyle==2.10.0
78+
# via flake8
6979
pydantic==1.10.2
7080
# via fastapi
81+
pyflakes==3.0.1
82+
# via flake8
7183
pyparsing==3.0.9
7284
# via packaging
7385
pytest==7.2.0
7486
# via
7587
# -r requirements.in
88+
# pytest-env
7689
# pytest-httpx
7790
# pytest-mock
91+
pytest-env==0.8.1
92+
# via -r requirements.in
7893
pytest-httpx==0.21.2
7994
# via -r requirements.in
8095
pytest-mock==3.10.0
@@ -101,10 +116,13 @@ starlette==0.21.0
101116
tomli==2.0.1
102117
# via
103118
# build
119+
# mypy
104120
# pep517
105121
# pytest
106122
typing-extensions==4.4.0
107-
# via pydantic
123+
# via
124+
# mypy
125+
# pydantic
108126
ujson==5.5.0
109127
# via fastapi
110128
uvicorn[standard]==0.20.0

src/basecamp/campfire_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import httpx
22
from httpx._models import Response
33

4-
from config import get_settings
4+
from src.config import get_settings
55

66
settings = get_settings()
77

src/basecamp/tests/test_campfire_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from basecamp.campfire_bot import CampfireBot
3+
from src.basecamp.campfire_bot import CampfireBot
44
from httpx._exceptions import HTTPStatusError
55

66

src/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
2-
from distutils.util import strtobool
32
from functools import lru_cache
43

54
from pydantic import BaseSettings
65

6+
from src.helpers import str_to_bool
7+
78

89
class Settings(BaseSettings):
9-
DEBUG: bool = bool(strtobool(os.getenv('DEBUG', 'False')))
10+
DEBUG: bool = bool(str_to_bool(os.getenv('DEBUG', 'False')))
1011

1112
BASECAMP_ACCOUNT_ID: str = 'bc-acc-id'
1213
BASECAMP_CHATBOT_KEY: str = 'bc-bot-key'
@@ -18,5 +19,5 @@ class Config:
1819

1920

2021
@lru_cache()
21-
def get_settings():
22+
def get_settings() -> Settings:
2223
return Settings()

src/conftest.py

Whitespace-only changes.

src/helpers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def str_to_bool(val: str) -> bool:
2+
"""
3+
Convert a string representation of truth to true (1) or false (0).
4+
5+
distutils.strtobool is deprecated in python 3.10.
6+
7+
>>> str_to_bool('true')
8+
True
9+
>>> str_to_bool('On')
10+
True
11+
>>> str_to_bool('1')
12+
True
13+
14+
>>> str_to_bool('false')
15+
False
16+
>>> str_to_bool('Off')
17+
False
18+
>>> str_to_bool('0')
19+
False
20+
>>> str_to_bool('xyz')
21+
Traceback (most recent call last):
22+
...
23+
ValueError: invalid truth value 'xyz'
24+
25+
"""
26+
val = val.lower()
27+
if val in ('y', 'yes', 't', 'true', 'on', '1'):
28+
return True
29+
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
30+
return False
31+
else:
32+
raise ValueError("invalid truth value %r" % (val,))

src/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import FastAPI
22

3-
from config import get_settings
4-
from sentry.api import api_router
3+
from src.config import get_settings
4+
from src.sentry.api import api_router
55

66

77
settings = get_settings()

0 commit comments

Comments
 (0)