Skip to content

Commit 37bc2e6

Browse files
authored
Generate README section for Lean configs (#551)
* Initial solution * Update README * Solve review comments * Update readme.py script
1 parent 1894796 commit 37bc2e6

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ A locally-focused workflow (local development, local execution) with the CLI may
6363
4. Run `lean research "Project Name"` to start a Jupyter Lab session to perform research in.
6464
5. Run `lean backtest "Project Name"` to run a backtest whenever there's something to test. This runs your strategy in a Docker container containing the same packages as the ones used on QuantConnect.com, but with your own data.
6565

66+
## CLI Configurations
67+
68+
The following CLI configurations are available. Use the [`lean config list`](#lean-config-list) command to list them at any time.
69+
70+
<!-- configuration table start -->
71+
| Key | Description |
72+
| --- | --- |
73+
| `user-id` | The user id used when making authenticated requests to the QuantConnect API. |
74+
| `api-token` | The API token used when making authenticated requests to the QuantConnect API. |
75+
| `default-language` | The default language used when creating new projects (allowed values: python, csharp). |
76+
| `engine-image` | The Docker image used when running the LEAN engine (quantconnect/lean:latest if not set). |
77+
| `research-image` | The Docker image used when running the research environment (quantconnect/research:latest if not set). |
78+
| `database-update-frequency` | How often the databases are updated. The format is DD.HH:MM:SS. If the frequency is less than a day can just be HH:MM:SS. Update can be disabled by setting this option to a non-date value (-, _, ..., etc.). If unset, default value is 1 day |
79+
<!-- configuration table end -->
80+
6681
## Commands
6782

6883
*Note: the readme only contains the `--help` text of all commands. Visit the [documentation website](https://www.lean.io/docs/v2/lean-cli/key-concepts/getting-started) for more comprehensive documentation.*

scripts/readme.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from lean.commands import lean
2929
from lean.models.pydantic import WrappedBaseModel
3030
from lean.components.util.click_group_default_command import DefaultCommandGroup
31-
31+
from lean.container import container
3232

3333
class NamedCommand(WrappedBaseModel):
3434
name: str
@@ -71,8 +71,33 @@ def get_header_id(name: str) -> str:
7171
name = re.sub(r"[^a-zA-Z0-9-]", "", name)
7272
return name
7373

74+
def get_configurations() -> List[dict]:
75+
"""Returns all available configurations with their keys and descriptions."""
76+
config_manager = container.cli_config_manager
77+
configurations = []
78+
79+
for option in config_manager.all_options:
80+
configurations.append({
81+
"key": option.key,
82+
"description": option.description
83+
})
84+
85+
return configurations
86+
87+
def generate_configurations_table(configurations: List[dict]) -> str:
88+
"""Generates a Markdown table for the given configurations."""
89+
table = ["| Key | Description |", "| --- | --- |"]
90+
91+
for config in configurations:
92+
table.append(f"| `{config['key']}` | {config['description']} |")
93+
94+
return "\n".join(table)
95+
7496

7597
def main() -> None:
98+
configurations = get_configurations()
99+
configurations_table = generate_configurations_table(configurations)
100+
76101
named_commands = get_commands(lean)
77102
named_commands = sorted(named_commands, key=lambda c: c.name)
78103

@@ -96,14 +121,22 @@ def main() -> None:
96121
table_of_contents.append(f"- [`{c.name}`](#{get_header_id(c.name)})")
97122
command_sections.append("\n\n".join(filter(None, section_parts)))
98123

99-
full_text = "\n".join(table_of_contents) + "\n\n" + "\n\n".join(command_sections)
100-
full_text = "\n".join(["<!-- commands start -->", full_text, "<!-- commands end -->"])
124+
125+
configuration_text = "\n".join(["<!-- configuration table start -->", configurations_table, "<!-- configuration table end -->"])
126+
commands_text = "\n".join(table_of_contents) + "\n\n" + "\n\n".join(command_sections)
127+
commands_text = "\n".join(["<!-- commands start -->", commands_text, "<!-- commands end -->"])
101128

102129
readme_path = Path.cwd() / "README.md"
103130
readme_content = readme_path.read_text(encoding="utf-8")
104131

132+
# CLI Configurations
133+
readme_content = re.sub(r"<!-- configuration table start -->.*<!-- configuration table end -->",
134+
configuration_text,
135+
readme_content,
136+
flags=re.DOTALL)
137+
# Commands
105138
readme_content = re.sub(r"<!-- commands start -->.*<!-- commands end -->",
106-
full_text,
139+
commands_text,
107140
readme_content,
108141
flags=re.DOTALL)
109142

@@ -112,3 +145,4 @@ def main() -> None:
112145

113146
if __name__ == "__main__":
114147
main()
148+

0 commit comments

Comments
 (0)