Skip to content

Commit 1ad88d2

Browse files
authored
🔨 Updates settings and removes config files: storage service (ITISFoundation#2369)
* Updates settings and removes config files * ❤️ emoticon prefix * linter and adds json-schema flag in CLI * Removing Dict configs * constants are not settings * And of course, renaming * adds typer as CLI * Updates testing dependencies and adds python-dotenv * Updates CLI and fixes entrypoints * GitHK review: adds a test to enforce settings config * @GitHK review: using attrs from new settings * @GitHK review: test refactor * @GitHK review: using attrs instead of keys
1 parent 92e6120 commit 1ad88d2

37 files changed

+410
-496
lines changed

.env-devel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#
22
# - Keep it alfphabetical order and grouped by prefix [see vscode cmd: Sort Lines Ascending]
3-
# - To expose: export $(grep -v '^#' .env | xargs -0)
3+
# - To expose:
4+
# set -o allexport
5+
# source .env
6+
# set +o allexport
7+
# or
8+
# export $(grep -v '^#' .env | xargs)
9+
# unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)
410
#
511

612
API_SERVER_DEV_FEATURES_ENABLED=0

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<!-- Common title prefixes/annotations:
22
3-
WIP:
4-
bugfix:
5-
🏗️ maintenance:
3+
WIP: work in progress
64
7-
(⚠️ devops) = changes in devops config required before deploying
5+
Consider prefix your PR message with an emoticon
6+
🐛 bugfix
7+
✨ new feature
8+
🔨 refactoring
9+
🏗️ maintenance
10+
📚 documentation
11+
12+
and append (⚠️ devops) if changes in devops configuration required before deploying
13+
14+
SEE https://github.com/dannyfritz/commit-message-emoji
15+
SEE https://emojipedia.org
816
-->
917

1018
## What do these changes do?
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from contextlib import suppress
2+
from typing import List, Tuple
3+
4+
from pydantic import BaseSettings, Extra, SecretStr, ValidationError
5+
6+
7+
class BaseCustomSettings(BaseSettings):
8+
class Config:
9+
case_sensitive = False
10+
extra = Extra.forbid
11+
allow_mutation = False
12+
frozen = True
13+
validate_all = True
14+
json_encoders = {SecretStr: lambda v: v.get_secret_value()}
15+
16+
@classmethod
17+
def set_defaults_with_default_constructors(
18+
cls, default_fields: List[Tuple[str, "BaseCustomSettings"]]
19+
):
20+
# This funcion can set defaults on fields that are BaseSettings as well
21+
# It is used in control construction of defaults.
22+
# Pydantic offers a defaults_factory but it is executed upon creation of the Settings **class**
23+
# which is too early for our purpose. Instead, we want to create the defaults just
24+
# before the settings instance is constructed
25+
26+
assert issubclass(cls, BaseCustomSettings)
27+
28+
# Builds defaults at this point
29+
for name, default_cls in default_fields:
30+
with suppress(ValidationError):
31+
default = default_cls()
32+
field_obj = cls.__fields__[name]
33+
field_obj.default = default
34+
field_obj.field_info.default = default
35+
field_obj.required = False

packages/service-library/src/servicelib/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def shutdown_info(app: web.Application):
1717
def create_safe_application(config: Optional[Dict] = None) -> web.Application:
1818
app = web.Application()
1919

20-
# Enxures config entry
20+
# Ensures config entry
2121
app[APP_CONFIG_KEY] = config or {}
2222

2323
app.on_startup.append(startup_info)

packages/service-library/src/servicelib/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def setup_tracing(
17-
app: web.Application, app_name: str, host: str, port: str, config: Dict
17+
app: web.Application, app_name: str, host: str, port: int, config: Dict
1818
) -> bool:
1919
zipkin_address = f"{config['zipkin_endpoint']}/api/v2/spans"
2020
endpoint = az.create_endpoint(app_name, ipv4=host, port=port)

services/storage/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ openapi-specs: ## updates and validates openapi specifications
1313
.PHONY: tests
1414
tests: ## runs unit tests
1515
# running unit tests
16-
@pytest -vv --exitfirst --failed-first --durations=10 --pdb $(CURDIR)/tests
16+
@pytest -vv --failed-first --durations=10 --pdb $(CURDIR)/tests
1717

1818

1919
# DEVELOPMENT ########

services/storage/docker/boot.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,20 @@ if [ "${SC_BUILD_TARGET}" = "development" ]; then
2424
echo "$INFO" "PIP :"
2525
pip list | sed 's/^/ /'
2626

27-
APP_CONFIG=docker-dev-config.yaml
2827
echo "$INFO" "Setting entrypoint to use watchmedo autorestart..."
2928
entrypoint='watchmedo auto-restart --recursive --pattern="*.py" --'
3029

3130
elif [ "${SC_BUILD_TARGET}" = "production" ]; then
32-
APP_CONFIG=docker-prod-config.yaml
3331
entrypoint=""
3432
fi
3533

3634
# RUNNING application ----------------------------------------
37-
echo "$INFO" "Selected config $APP_CONFIG"
38-
35+
echo "$INFO" "Selected config ${SC_BUILD_TARGET}"
3936
if [ "${SC_BOOT_MODE}" = "debug-ptvsd" ]; then
4037
# NOTE: needs ptvsd installed
41-
echo "$INFO" "PTVSD Debugger initializing in port 3000 with ${APP_CONFIG}"
38+
echo "$INFO" "PTVSD Debugger initializing in port 3000 with ${SC_BUILD_TARGET}"
4239
eval "$entrypoint" python3 -m ptvsd --host 0.0.0.0 --port 3000 -m \
43-
simcore_service_storage --config $APP_CONFIG
40+
simcore_service_storage run
4441
else
45-
exec simcore-service-storage --config $APP_CONFIG
42+
exec simcore-service-storage run
4643
fi

services/storage/requirements/_base.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ aiopg[sa]
2020

2121
tenacity
2222
semantic_version
23-
click
23+
typer
2424
minio
2525
urllib3
2626

services/storage/requirements/_base.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ chardet==4.0.0
6262
# aiohttp
6363
# requests
6464
click==7.1.2
65-
# via -r requirements/_base.in
65+
# via typer
6666
configparser==5.0.2
6767
# via blackfynn
6868
dataclasses==0.8
@@ -208,6 +208,8 @@ tenacity==7.0.0
208208
# -r requirements/_base.in
209209
trafaret==2.1.0
210210
# via -r requirements/../../../packages/service-library/requirements/_base.in
211+
typer==0.3.2
212+
# via -r requirements/_base.in
211213
typing-extensions==3.10.0.0
212214
# via
213215
# aiohttp

services/storage/requirements/_test.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pytest-mock
1717
pytest-runner
1818
pytest-sugar
1919
pylint
20+
python-dotenv
2021

2122
# test coverage
2223
coverage

0 commit comments

Comments
 (0)