Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydantic v2 #117

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def generate_sub_process_result(requirement_file) -> dict:
for entry in check_required:
entry = entry.lower()
if entry not in sub_process_result:

command = ["pip", "show", entry]
print("Collect Req. PIP Infos for package:", entry)
result = run(
Expand Down Expand Up @@ -164,7 +163,6 @@ def generate_code_reference_documentation(
nav = mkdocs_gen_files.Nav()

for path in sorted(Path(source_path).rglob(source_file_type_filter)):

module_path = path.relative_to(source_path).with_suffix("")
doc_path = path.relative_to(source_path).with_suffix(md_file_type)
full_doc_path = Path(virtual_ref_nav_path, doc_path)
Expand Down Expand Up @@ -209,7 +207,6 @@ def generate_code_reference_documentation(
with open(requirement_file, "r") as req_file:
req_txt = req_file.read()
if req_txt and len(req_txt) > 0:

with mkdocs_gen_files.open(req_md_file, "w") as fd:
fd.write(f"# {source_path.replace('_', ' ')} - Included Libraries\n***\n\n")
# Python 3.x only
Expand Down
8 changes: 7 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# msaBase Release Notes
## Possible future features:

# 0.0.110

- added supporting pydantic v2
- update msaDocModels
- added env for sentry

# 0.0.109

- add Input and DTO models for Spellcheck
Expand All @@ -9,7 +15,7 @@

- added enviroments for sentry

## 0.0.107
# 0.0.107

- fix algorithm to DocClassifier Input

Expand Down
Binary file modified docs/saved_req_package_pip_info.pkl
Binary file not shown.
2 changes: 1 addition & 1 deletion msaBase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob
from os.path import basename, dirname, isfile, join

version = "0.0.109"
version = "0.0.110"
__author__ = "Stefan Welcker"
__copyright__ = "Copyright 2022, U2D.ai"
__license__ = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions msaBase/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def save_config(self) -> None:
"""
Saves config to a JSON file
"""
sa = self.copy(deep=True)
sa = self.model_copy(deep=True)
with open("config.json", "w") as fp:
json.dump(sa.dict(), fp, sort_keys=True, indent=4)
json.dump(sa.model_dump(), fp, sort_keys=True, indent=4)

@staticmethod
def load_config():
Expand Down
13 changes: 5 additions & 8 deletions msaBase/configurate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from fastapi.exception_handlers import http_exception_handler
from fastapi.exceptions import RequestValidationError
from fastapi.responses import ORJSONResponse
from fastapi_restful.timing import add_timing_middleware
from fs.base import FS
from grpc._channel import _InactiveRpcError
from loguru import logger as logger_gruru
Expand Down Expand Up @@ -105,11 +106,11 @@ async def load_config(url: str) -> None:
if resp.status == 200:
config = MSAServiceDefinition.parse_obj(await resp.json())
new_config = get_msa_app_settings()
if new_config.dict(exclude={"version"}) == config.dict(exclude={"version"}):
if new_config.model_dump(exclude={"version"}) == config.model_dump(exclude={"version"}):
return

with open("config.json", "w") as json_file:
json.dump(config.dict(), json_file, sort_keys=True, indent=4)
json.dump(config.model_dump(), json_file, sort_keys=True, indent=4)

logger_gruru.info("New config saved to config.json")
else:
Expand Down Expand Up @@ -223,7 +224,7 @@ async def read_config(received_config: ConfigInput) -> None:
if reload_needed:
self.logger.info("New config needs reload.")
with open("config.json", "w") as json_file:
json.dump(received_config.data.dict(), json_file)
json.dump(received_config.data.model_dump(), json_file)

self.logger.info("New config saved to config.json")

Expand Down Expand Up @@ -432,7 +433,6 @@ def get_services_settings(self, request: Request) -> ORJSONResponse:

def try_get_json():
try:

return jsonable_encoder(self.settings)

except Exception as e:
Expand All @@ -458,7 +458,6 @@ def get_services_openapi_schema(self, request: Request) -> ORJSONResponse:

def try_get_json():
try:

return jsonable_encoder(self.openapi())

except Exception as e:
Expand Down Expand Up @@ -647,7 +646,6 @@ def update_settings(self, new_config: MSAServiceDefinition, one_time=False) -> b
if (current_functionality is not None and new_functionality is not None) and (
current_functionality != new_functionality
):

if reload_needed:
return True

Expand Down Expand Up @@ -905,7 +903,6 @@ def configure_cors_middleware(self) -> None:
def configure_timing_middleware(self) -> None:
"""Add Middleware Timing"""
self.logger.info("Add Middleware Timing")
from fastapi_utils.timing import add_timing_middleware

add_timing_middleware(self, record=self.logger.info, prefix="app", exclude="untimed")

Expand Down Expand Up @@ -964,7 +961,7 @@ def init_sentry(self, sentry_dsn: str) -> None:
sentry_sdk.init(
dsn=sentry_dsn,
traces_sample_rate=1.0,
environment=os.getenv("STAGE_ENV","local"),
environment=os.getenv("STAGE_ENV", "local"),
)


Expand Down
9 changes: 0 additions & 9 deletions msaBase/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,18 @@ def init_logging():
```
"""

# disable handlers for specific uvicorn loggers
# to redirect their output to the default uvicorn logger
# works with uvicorn==0.11.6
# print("Logger", [name for name in logging.root.manager.loggerDict])

for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)

loggers = (logging.getLogger(name) for name in logging.root.manager.loggerDict if name.startswith("uvicorn."))

# change handler for default uvicorn logger
intercept_handler = InterceptHandler()

for uvicorn_logger in loggers:
try:
uvicorn_logger.handlers = [intercept_handler]
except:
pass
# logging.getLogger().handlers = [intercept_handler]
logging.getLogger("uvicorn").handlers = []
logging.getLogger("rocketry").handlers = []

# set logs output, level and format
logger.configure(handlers=[{"sink": sys.stdout, "level": logging.INFO, "format": format_record}])
2 changes: 1 addition & 1 deletion msaBase/models/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi_utils.api_settings import APISettings
from fastapi_restful.api_settings import APISettings
from pydantic.config import Extra


Expand Down
Loading