From c20162533db789a91de34006c49c2e7111f2017a Mon Sep 17 00:00:00 2001 From: rahul Date: Wed, 16 Oct 2024 07:00:56 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Configurations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/{environment.md => configurations.md} | 34 ++++++++++++++----- docs/dev/index.md | 2 +- docs/gen_test_case_reference.py | 6 ++-- docs/library/cli/env_init.md | 2 +- src/config/__init__.py | 4 ++- src/config/app.py | 17 ++++++++++ src/config/docs.py | 20 +++++++++++ src/config/env.py | 2 +- 8 files changed, 72 insertions(+), 15 deletions(-) rename docs/dev/{environment.md => configurations.md} (69%) create mode 100644 src/config/app.py create mode 100644 src/config/docs.py diff --git a/docs/dev/environment.md b/docs/dev/configurations.md similarity index 69% rename from docs/dev/environment.md rename to docs/dev/configurations.md index 3b02e1bc28..37e4daf572 100644 --- a/docs/dev/environment.md +++ b/docs/dev/configurations.md @@ -1,23 +1,29 @@ -# Setting up your environment +# Managing Configurations -Application-wide [environment configuration](https://www.12factor.net/config), which varies across staging, production, and development environments are read from `env.yaml` in the project root. - -This file will not be tracked by git, making it safe for storing local secrets. - -To get started, run the command [env_init](../library/cli/env_init.md) cli to initialize your environment configuration. +Configurations are managed by the `config` package. It provides both environment and application configurations. ```console . ├── src │ └── 📁 config [Application wide environment and configurations] │ ├── 📄 __init__.py +│ ├── 📄 app.py [Configurations for application framework] +│ ├── 📄 docs.py [Configurations for documentation] │ └── 📄 env.py [Exposes `env.yaml` to the application] └── 📄 env.yaml [Environment file (git ignored)] ``` -## Usage +## Environment Configurations -### 1. Generate env file +Application-wide [environment configuration](https://www.12factor.net/config), which varies across staging, production, and development environments are read from `env.yaml` in the project root. + +This file will not be tracked by git, making it safe for storing local secrets. + +To get started, run the command [env_init](../library/cli/env_init.md) cli to initialize your environment configuration. + +### Usage + +#### 1. Generate env file Run the [`env_init`](../library/cli/env_init.md) cli tool. @@ -38,10 +44,20 @@ remote_nodes: client-secret: ``` -### 2. Import `EnvConfig` +#### 2. Import `EnvConfig` ```console from config import EnvConfig EnvConfig().remote_nodes[0].name 'mainnet_archive' ``` + +## Application configuration + +Application configuration are pydantic classes. + +```console +from config import DocsConfig +DocsConfig().TARGET_FORK +'Prague' +``` diff --git a/docs/dev/index.md b/docs/dev/index.md index a86e81d99a..9bc3b83bc1 100644 --- a/docs/dev/index.md +++ b/docs/dev/index.md @@ -2,7 +2,7 @@ This documentation is aimed at maintainers of `execution-spec-tests` but may be helpful during test case development: -- [Setting up your environment](./environment.md) +- [Managing configurations](./configurations.md) - [Generating documentation](./docs.md) - [Coding style](./coding_style.md) - [Enabling pre-commit checks](./precommit.md) diff --git a/docs/gen_test_case_reference.py b/docs/gen_test_case_reference.py index 10c354dd16..856a9c122e 100644 --- a/docs/gen_test_case_reference.py +++ b/docs/gen_test_case_reference.py @@ -5,6 +5,7 @@ can't take command-line arguments. The main logic is implemented in src/pytest_plugins/filler/gen_test_doc.py. """ + import importlib import logging import sys @@ -14,11 +15,12 @@ import pytest_plugins.filler.gen_test_doc.gen_test_doc as gen_test_doc from cli.pytest_commands.fill import fill +from config import DocsConfig importlib.reload(gen_test_doc) # get changes in plugin to trigger an update for `mkdocs serve` -TARGET_FORK = "Prague" -GENERATE_UNTIL_FORK = "Osaka" +TARGET_FORK = DocsConfig().TARGET_FORK +GENERATE_UNTIL_FORK = DocsConfig().GENERATE_UNTIL_FORK logger = logging.getLogger("mkdocs") diff --git a/docs/library/cli/env_init.md b/docs/library/cli/env_init.md index ae9c1b1ecf..7f2e31b526 100644 --- a/docs/library/cli/env_init.md +++ b/docs/library/cli/env_init.md @@ -1,6 +1,6 @@ # The `env_init` CLI -Generate an example `env.yaml` [environment](../../dev/environment.md) config file if it doesn't exist. +Generate an example `env.yaml` [environment](../../dev/configurations.md) config file if it doesn't exist. ```console ➜ uv run env_init http EnvConfig diff --git a/src/config/__init__.py b/src/config/__init__.py index 4ce9f07fd6..5a3b0febfd 100644 --- a/src/config/__init__.py +++ b/src/config/__init__.py @@ -6,5 +6,7 @@ """ # This import is done to facilitate cleaner imports in the project -# `from config import env` instead of `from config.env import EnvConfig` +# `from config import AppConfig` instead of `from config.app import AppConfig` +from .app import AppConfig # noqa: 401 +from .docs import DocsConfig # noqa: 401 from .env import EnvConfig # noqa: 401 diff --git a/src/config/app.py b/src/config/app.py new file mode 100644 index 0000000000..c8bd8591bd --- /dev/null +++ b/src/config/app.py @@ -0,0 +1,17 @@ +""" +A module for managing application configurations. + +Classes: +- AppConfig: Holds configurations for the application framework. +""" + +from pydantic import BaseModel + + +class AppConfig(BaseModel): + """ + A class for accessing documentation-related configurations. + """ + + version: str = "3.0.0" + """The version of the application framework.""" diff --git a/src/config/docs.py b/src/config/docs.py new file mode 100644 index 0000000000..d1896f3684 --- /dev/null +++ b/src/config/docs.py @@ -0,0 +1,20 @@ +""" +A module for managing documentation-related configurations. + +Classes: +- DocsConfig: Holds configurations for documentation generation. +""" + +from pydantic import BaseModel + + +class DocsConfig(BaseModel): + """ + A class for accessing documentation-related configurations. + """ + + TARGET_FORK: str = "Prague" + """The target fork for the documentation.""" + + GENERATE_UNTIL_FORK: str = "Osaka" + """The fork until which documentation should be generated.""" diff --git a/src/config/env.py b/src/config/env.py index 9ec2013060..b1d1331afb 100644 --- a/src/config/env.py +++ b/src/config/env.py @@ -39,7 +39,7 @@ class RemoteNode(BaseModel): """ name: str = "mainnet_archive" - node_url: HttpUrl = "http://example.com" + node_url: HttpUrl = HttpUrl("http://example.com") rpc_headers: Dict[str, str] = {"client-secret": ""}