Skip to content

Commit 31cf8f7

Browse files
committed
Fix lint/format
1 parent 232faf8 commit 31cf8f7

File tree

10 files changed

+42
-27
lines changed

10 files changed

+42
-27
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@ jobs:
1616
- uses: actions/checkout@v2
1717

1818
- name: set up python
19-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v3
2020
with:
2121
python-version: 3.9
22+
cache: 'pip'
2223

2324
- name: install
2425
run: |
2526
make install-linting
2627
pip freeze
2728
28-
- name: lint
29-
run: make lint
30-
31-
- name: mypy
32-
run: make mypy
29+
- name: run linters
30+
uses: wearerequired/lint-action@v1
31+
with:
32+
black: true
33+
flake8: true
34+
mypy: true
3335

3436
test-linux:
3537
name: test py${{ matrix.python-version }} on linux

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DEFAULT_GOAL := all
22
isort = isort pydantic_ssm_settings tests
3-
black = black -S -l 120 --target-version py38 pydantic_ssm_settings tests
3+
black = black --target-version py38 pydantic_ssm_settings tests
44

55
.PHONY: install-linting
66
install-linting: install-pydantic_ssm_settings
@@ -46,17 +46,14 @@ lint:
4646
flake8 pydantic_ssm_settings/ tests/
4747
$(isort) --check-only --df
4848
$(black) --check --diff
49+
mypy
4950

5051
# .PHONY: check-dist
5152
# check-dist:
5253
# python setup.py check -ms
5354
# SKIP_CYTHON=1 python setup.py sdist
5455
# twine check dist/*
5556

56-
.PHONY: mypy
57-
mypy:
58-
mypy pydantic_ssm_settings
59-
6057
.PHONY: test
6158
test:
6259
pytest --cov=pydantic_ssm_settings

pydantic_ssm_settings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .settings import AwsSsmSourceConfig
22

3-
__all__ = ('AwsSsmSourceConfig',)
3+
__all__ = ("AwsSsmSourceConfig",)

pydantic_ssm_settings/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import logging
22
from typing import Tuple
33

4-
from pydantic.env_settings import EnvSettingsSource, InitSettingsSource, SecretsSettingsSource, SettingsSourceCallable
4+
from pydantic.env_settings import (
5+
EnvSettingsSource,
6+
InitSettingsSource,
7+
SecretsSettingsSource,
8+
SettingsSourceCallable,
9+
)
510

611
from .source import AwsSsmSettingsSource
712

pydantic_ssm_settings/source.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
import logging
22
from pathlib import Path
3-
from typing import Any, Dict, Optional, Union
3+
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
44

55
import boto3
6-
from pydantic import BaseSettings
6+
7+
from pydantic import BaseSettings, typing
8+
9+
if TYPE_CHECKING:
10+
from mypy_boto3_ssm.client import SSMClient
11+
712

813
logger = logging.getLogger(__name__)
914

1015

1116
class AwsSsmSettingsSource:
1217
__slots__ = ("ssm_prefix",)
1318

14-
def __init__(self, ssm_prefix: Union[Path, str, None]):
15-
self.ssm_prefix: Union[Path, str, None] = ssm_prefix
19+
def __init__(self, ssm_prefix: Union[typing.StrPath, None]):
20+
self.ssm_prefix: Union[typing.StrPath, None] = ssm_prefix
1621

1722
@property
18-
def client(self):
23+
def client(self) -> "SSMClient":
1924
return boto3.client("ssm")
2025

2126
def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
2227
"""
2328
Returns lazy SSM values for all settings.
2429
"""
2530
secrets: Dict[str, Optional[Any]] = {}
26-
31+
2732
if self.ssm_prefix is None:
2833
return secrets
2934

@@ -34,10 +39,13 @@ def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
3439

3540
logger.debug(f"Building SSM settings with prefix of {secrets_path=}")
3641

37-
params = self.client.get_parameters_by_path(Path=str(secrets_path), WithDecryption=True)['Parameters']
42+
params = self.client.get_parameters_by_path(
43+
Path=str(secrets_path), WithDecryption=True
44+
)["Parameters"]
3845

3946
return {
40-
str(Path(param['Name']).relative_to(secrets_path)): param['Value'] for param in params
47+
str(Path(param["Name"]).relative_to(secrets_path)): param["Value"]
48+
for param in params
4149
}
4250

4351
def __repr__(self) -> str:

setup.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ filterwarnings =
1010
ignore:The distutils.sysconfig module is deprecated, use sysconfig instead:DeprecationWarning
1111

1212
[flake8]
13-
max-line-length = 120
13+
max-line-length = 90
1414
max-complexity = 14
1515
inline-quotes = single
1616
multiline-quotes = double
@@ -41,14 +41,16 @@ source =
4141
D:\a\pydantic\pydantic\pydantic
4242

4343
[isort]
44-
line_length=120
44+
line_length=90
4545
known_first_party=pydantic
4646
multi_line_output=3
4747
include_trailing_comma=True
4848
force_grid_wrap=0
4949
combine_as_imports=True
5050

5151
[mypy]
52+
files=pydantic_ssm_settings
53+
exclude=tests,setup.py
5254
python_version = 3.9
5355
show_error_codes = True
5456
follow_imports = silent

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"License :: OSI Approved :: MIT License",
1818
],
1919
keywords="Pydantic AWS SSM Parameter Store",
20-
author=u"Anthony Lukach",
20+
author="Anthony Lukach",
2121
author_email="[email protected]",
2222
url="https://github.com/stac-utils/stac-fastapi",
2323
license="MIT",

tests/requirements-linting.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
black==21.8b0
1+
black==22.3.0
22
flake8==3.9.2
33
isort==5.9.3
44
mypy==0.910

tests/requirements-testing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
coverage==5.5
22
pytest==6.2.5
33
pytest-cov==2.12.1
4-
moto[all]==2.2.6
4+
moto[all]==2.2.19

tests/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ def test_lookup_from_ssm(ssm):
3535
assert settings.foo == "xyz123"
3636

3737

38-
def test_prefer_provided():
38+
def test_prefer_provided(ssm):
3939
settings = SimpleSettings(_secrets_dir="/asdf", foo="manually set")
4040
assert settings.foo == "manually set"
4141

4242

4343
def test_casting(ssm):
44+
ssm.put_parameter(Name="/asdf/foo", Value="xyz123")
4445
ssm.put_parameter(Name="/asdf/bar", Value="99")
4546
settings = IntSettings(_secrets_dir="/asdf")
4647
assert settings.bar == 99

0 commit comments

Comments
 (0)