Skip to content

Commit c1eeddb

Browse files
raxhvldanceratopz
andauthored
♻️ refactor(eest): migrate env_init to eest make env (#996)
Co-authored-by: danceratopz <[email protected]>
1 parent 7f01630 commit c1eeddb

File tree

9 files changed

+63
-52
lines changed

9 files changed

+63
-52
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Test fixtures for use by clients are available for each release on the [Github r
5858
- ✨ Add the `eest make test` command, an interactive CLI that helps users create a new test module and function ([#950](https://github.com/ethereum/execution-spec-tests/pull/950)).
5959
- ✨ Add the `eest clean` command that helps delete generated files and directories from the repository ([#980](https://github.com/ethereum/execution-spec-tests/pull/980)).
6060
- ✨ Add framework changes for EIP-7742, required for Prague devnet-5 ([#931](https://github.com/ethereum/execution-spec-tests/pull/931)).
61+
- ✨ Add the `eest make env` command that generates a default env file (`env.yaml`)([#996](https://github.com/ethereum/execution-spec-tests/pull/996)).
6162

6263
### 🔧 EVM Tools
6364

docs/dev/configurations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ Application-wide [environment configuration](https://www.12factor.net/config), w
1919

2020
This file will not be tracked by git, making it safe for storing local secrets.
2121

22-
To get started, run the command [env_init](../library/cli/env_init.md) cli to initialize your environment configuration.
22+
To get started, run the command [eest make env](../library/cli/eest.md) cli to initialize your environment configuration.
2323

2424
### Usage
2525

2626
#### 1. Generate env file
2727

28-
Run the [`env_init`](../library/cli/env_init.md) cli tool.
28+
Run the [`eest make env`](../library/cli/eest.md) cli tool.
2929

3030
```console
31-
uv run env_init
32-
Env file created: execution-spec-tests/env.yaml
31+
uv run eest make env
32+
🎉 Success! Config file created at: <path>/env.yaml
3333
```
3434

3535
which should generate an `env.yaml` in the project root.

docs/library/cli/env_init.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/library/cli/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
- [`eest`](eest.md) - A CLI tool that helps with routine tasks in ethereum/execution-spec-tests.
44
- [`evm_bytes`](evm_bytes.md) - Convert the given EVM bytes from a binary file or a hex string to EEST's python opcodes.
5-
- [`env_init`](env_init.md) - Generate an example `env.yaml` [environment](../../dev/configurations.md) config file if it doesn't exist.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ markdownlintcli2_soft_fail = "cli.tox_helpers:markdownlint"
107107
order_fixtures = "cli.order_fixtures:order_fixtures"
108108
evm_bytes = "cli.evm_bytes:evm_bytes"
109109
hasher = "cli.hasher:main"
110-
env_init = "config.env:create_default_config"
111110
eest = "cli.eest.cli:eest"
112111

113112
[tool.setuptools.packages.find]

src/cli/eest/make/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import click
1212

13+
from cli.eest.make.commands import create_default_env
14+
1315
from .commands import test
1416

1517

@@ -32,3 +34,4 @@ def make():
3234
https://click.palletsprojects.com/en/8.0.x/commands/#nested-handling-and-contexts
3335
"""
3436
make.add_command(test)
37+
make.add_command(create_default_env)

src/cli/eest/make/commands/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
`cli.py`.
55
"""
66

7+
from .env import create_default_env
78
from .test import test
89

9-
__all__ = ["test"]
10+
__all__ = ["test", "create_default_env"]

src/cli/eest/make/commands/env.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
CLI commands for managing the environment file.
3+
"""
4+
5+
import click
6+
from jinja2 import Environment, PackageLoader
7+
8+
from cli.eest.quotes import get_quote
9+
from config.env import ENV_PATH, Config
10+
11+
12+
@click.command(short_help="Generate the default environment file (env.yaml).", name="env")
13+
def create_default_env():
14+
"""
15+
A CLI command to generate the default environment file (env.yaml).
16+
17+
If an `env.yaml` already exists, this command will NOT override it.
18+
In that case, it is recommended to manually make changes.
19+
20+
_Easter egg: Shows a random quote after creating the environment file._
21+
22+
Example:
23+
24+
uv run eest make env
25+
26+
Output:
27+
28+
🎉 Success! Environment file created at: <path>/env.yaml
29+
30+
🚀 Well begun is half done. - Aristotle
31+
"""
32+
# Check if the env file already exists
33+
if ENV_PATH.exists():
34+
click.echo(
35+
click.style(
36+
f"🚧 The env file '{ENV_PATH}' already exists. "
37+
"Please update it manually if needed.",
38+
fg="red",
39+
)
40+
)
41+
exit(1)
42+
43+
template_environment = Environment(
44+
loader=PackageLoader("config"), trim_blocks=True, lstrip_blocks=True
45+
)
46+
template = template_environment.get_template("env.yaml.j2")
47+
48+
env_yaml = template.render(config=Config())
49+
50+
with ENV_PATH.open("w") as file:
51+
file.write(env_yaml)
52+
click.echo(click.style(f"🎉 Success! Environment file created at: {ENV_PATH}", fg="green"))
53+
click.echo(get_quote())

src/config/env.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from typing import Dict, List
2323

2424
import yaml
25-
from jinja2 import Environment, PackageLoader
2625
from pydantic import BaseModel, HttpUrl, ValidationError
2726

2827
ENV_PATH = Path(__file__).resolve().parent.parent.parent / "env.yaml"
@@ -75,30 +74,3 @@ def __init__(self):
7574
super().__init__(**config_data)
7675
except ValidationError as e:
7776
raise ValueError(f"Invalid configuration: {e}")
78-
79-
80-
def create_default_config():
81-
"""
82-
Creates a default configuration file `env.yaml` from the Jinja2 template.
83-
84-
Raises:
85-
IOError: If there is an error writing to the `env.yaml` file.
86-
"""
87-
# Check if the config file already exists
88-
if ENV_PATH.exists():
89-
print(
90-
f"🚧 The configuration file '{ENV_PATH}' already exists. "
91-
"Please update it manually if needed."
92-
)
93-
exit(1)
94-
95-
template_environment = Environment(
96-
loader=PackageLoader("config"), trim_blocks=True, lstrip_blocks=True
97-
)
98-
template = template_environment.get_template("env.yaml.j2")
99-
100-
env_yaml = template.render(config=Config())
101-
102-
with ENV_PATH.open("w") as file:
103-
file.write(env_yaml)
104-
print(f"Env file created: {ENV_PATH}")

0 commit comments

Comments
 (0)