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

pydantic2 #244

Merged
merged 9 commits into from
Dec 11, 2023
Merged

pydantic2 #244

merged 9 commits into from
Dec 11, 2023

Conversation

khoroshevskyi
Copy link
Member

Updated models to pydantic 2

Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 815876f
Status: ✅  Deploy successful!
Preview URL: https://56920556.pephub.pages.dev
Branch Preview URL: https://243-pydantic2.pephub.pages.dev

View logs

Copy link
Member

@nleroy917 nleroy917 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - thanks for this.

Comment on lines -15 to -113
from pephub.exceptions import PepHubException

from ._version import __version__ as v
from .const import DEFAULT_PORT, PKG_NAME


def build_parser():
"""
Building argument parser
:return argparse.ArgumentParser
"""
banner = "%(prog)s - PEP web server"
additional_description = (
"For subcommand-specific options, type: '%(prog)s <subcommand> -h'"
)
additional_description += "\nhttps://github.com/pepkit/pepserver"

parser = VersionInHelpParser(
prog=PKG_NAME, description=banner, epilog=additional_description
)

parser.add_argument(
"-V", "--version", action="version", version="%(prog)s {v}".format(v=v)
)

msg_by_cmd = {"serve": "run the server"}

subparsers = parser.add_subparsers(dest="command")

def add_subparser(cmd, description):
return subparsers.add_parser(cmd, description=description, help=description)

sps = {}
# add arguments that are common for both subparsers
for cmd, desc in msg_by_cmd.items():
sps[cmd] = add_subparser(cmd, desc)
sps[cmd].add_argument(
"-c",
"--config",
required=False,
dest="config",
help="A path to the pepserver config file",
)

sps["serve"].add_argument(
"-p",
"--port",
dest="port",
type=int,
help="The port the webserver should be run on.",
default=DEFAULT_PORT,
)

sps["serve"].add_argument(
"-r",
"--reload",
dest="reload",
type=bool,
help="Run the server in reload configuration",
default=False,
)

sps["serve"].add_argument(
"--log-level",
dest="log_level",
type=str,
help="The level of logging to use",
default="INFO",
)

sps["serve"].add_argument(
"--uvicorn-log-level",
dest="uvicorn_log_level",
type=str,
help="The level of logging to use for uvicorn",
default="info",
)

return parser


def read_server_configuration(path: str) -> dict:
"""Read in a server configuration file at a specified path"""
if not exists(path):
raise FileNotFoundError(f"Configuration file at {path} could not be found.")
with open(path, "r") as f:
cfg = safe_load(f)
if cfg.get("data") is None:
raise PepHubException(
"'data' section is required in the configuration file."
)
if cfg["data"].get("path") is None:
raise PepHubException(
"No path to PEPs was specified in the configuration file."
)

return {
"data": {"path": cfg["data"]["path"], "index": cfg["data"].get("index")}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@khoroshevskyi khoroshevskyi merged commit 5b576b6 into dev Dec 11, 2023
2 checks passed
@khoroshevskyi khoroshevskyi deleted the 243_pydantic2 branch December 11, 2023 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants