Skip to content

Commit

Permalink
✨ feat: Configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
raxhvl committed Oct 16, 2024
1 parent e8cde51 commit c201625
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 15 deletions.
34 changes: 25 additions & 9 deletions docs/dev/environment.md → docs/dev/configurations.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -38,10 +44,20 @@ remote_nodes:
client-secret: <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'
```
2 changes: 1 addition & 1 deletion docs/dev/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions docs/gen_test_case_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion docs/library/cli/env_init.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions src/config/app.py
Original file line number Diff line number Diff line change
@@ -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."""
20 changes: 20 additions & 0 deletions src/config/docs.py
Original file line number Diff line number Diff line change
@@ -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."""
2 changes: 1 addition & 1 deletion src/config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<secret>"}


Expand Down

0 comments on commit c201625

Please sign in to comment.