Skip to content

Commit

Permalink
chore: change variable name (#2638)
Browse files Browse the repository at this point in the history
In this PR:
- Change input parameter's name in `entry_point.py`.
  • Loading branch information
JoeWang1127 authored Apr 15, 2024
1 parent b7ef449 commit 2c93542
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 90 deletions.
4 changes: 2 additions & 2 deletions library_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ python -m pip install library_generation/

```bash
python library_generation/entry_point.py generate \
--baseline-generation-config=/path/to/baseline_config_file \
--current-generation-config=/path/to/current_config_file \
--baseline-generation-config-path=/path/to/baseline_config_file \
--current-generation-config-path=/path/to/current_config_file \
--repository-path=path/to/repository
```
If you run `entry_point.py` with the example [configuration](#an-example-of-generation-configuration)
Expand Down
39 changes: 21 additions & 18 deletions library_generation/cli/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main(ctx):

@main.command()
@click.option(
"--baseline-generation-config",
"--baseline-generation-config-path",
required=False,
default=None,
type=str,
Expand All @@ -40,7 +40,7 @@ def main(ctx):
""",
)
@click.option(
"--current-generation-config",
"--current-generation-config-path",
required=False,
default=None,
type=str,
Expand All @@ -62,8 +62,8 @@ def main(ctx):
""",
)
def generate(
baseline_generation_config: str,
current_generation_config: str,
baseline_generation_config_path: str,
current_generation_config_path: str,
repository_path: str,
):
"""
Expand All @@ -87,47 +87,50 @@ def generate(
The commit history, if generated, will be available in
repository_path/pr_description.txt.
"""
default_generation_config = f"{os.getcwd()}/generation_config.yaml"
default_generation_config_path = f"{os.getcwd()}/generation_config.yaml"

if baseline_generation_config is None and current_generation_config is None:
if not os.path.isfile(default_generation_config):
if (
baseline_generation_config_path is None
and current_generation_config_path is None
):
if not os.path.isfile(default_generation_config_path):
raise FileNotFoundError(
f"{default_generation_config} does not exist. "
f"{default_generation_config_path} does not exist. "
"A valid generation config has to be passed in as "
"current_generation_config or exist in the current working "
"directory."
)
current_generation_config = default_generation_config
elif current_generation_config is None:
current_generation_config_path = default_generation_config_path
elif current_generation_config_path is None:
raise FileNotFoundError(
"current_generation_config is not specified when "
"baseline_generation_config is specified. "
"current_generation_config should be the source of truth of "
"library generation."
)

current_generation_config = os.path.abspath(current_generation_config)
current_generation_config_path = os.path.abspath(current_generation_config_path)
repository_path = os.path.abspath(repository_path)
if not baseline_generation_config:
if not baseline_generation_config_path:
# Execute full generation based on current_generation_config if
# baseline_generation_config is not specified.
# Do not generate pull request description.
generate_from_yaml(
config_path=current_generation_config,
config=from_yaml(current_generation_config),
config_path=current_generation_config_path,
config=from_yaml(current_generation_config_path),
repository_path=repository_path,
)
return

# Compare two generation configs and only generate changed libraries.
# Generate pull request description.
baseline_generation_config = os.path.abspath(baseline_generation_config)
baseline_generation_config_path = os.path.abspath(baseline_generation_config_path)
config_change = compare_config(
baseline_config=from_yaml(baseline_generation_config),
current_config=from_yaml(current_generation_config),
baseline_config=from_yaml(baseline_generation_config_path),
current_config=from_yaml(current_generation_config_path),
)
generate_from_yaml(
config_path=current_generation_config,
config_path=current_generation_config_path,
config=config_change.current_config,
repository_path=repository_path,
target_library_names=config_change.get_changed_libraries(),
Expand Down
5 changes: 4 additions & 1 deletion library_generation/test/cli/entry_point_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def test_entry_point_with_baseline_without_current_raise_file_exception(self):
# noinspection PyTypeChecker
result = runner.invoke(
generate,
["--baseline-generation-config=path/to/config.yaml", "--repository-path=."],
[
"--baseline-generation-config-path=path/to/config.yaml",
"--repository-path=.",
],
)
self.assertEqual(1, result.exit_code)
self.assertEqual(FileNotFoundError, result.exc_info[0])
Expand Down
4 changes: 2 additions & 2 deletions library_generation/test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def __run_entry_point_in_docker_container(
"python",
"/src/cli/entry_point.py",
"generate",
f"--baseline-generation-config=/workspace/config-{repo}/{baseline_config}",
f"--current-generation-config=/workspace/config-{repo}/{current_config}",
f"--baseline-generation-config-path=/workspace/config-{repo}/{baseline_config}",
f"--current-generation-config-path=/workspace/config-{repo}/{current_config}",
f"--repository-path=/workspace/{repo}",
]
)
Expand Down
Loading

0 comments on commit 2c93542

Please sign in to comment.