-
Notifications
You must be signed in to change notification settings - Fork 143
Enhancement: Small Improvement for Interactively Overriding Local Testing Harness Env Vars #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
99a7af2
introduce an interactive harness overwrite mode
174815c
temporary changes so that can test go-algorand PR #4951 in CI
0737f54
fix missing env vars from overwrite
cd21240
Update harness_overwrite.py
tzaffi a667e85
Update test-harness.sh
tzaffi ef4be1a
Update harness_overwrite.py
tzaffi c5f9e98
lint
85d2fa7
Update harness_overwrite.py
tzaffi f230423
better printout
a3c38eb
Update .test-env
tzaffi b4564d7
kick off CI against latest improve-goal-errors commit
tzaffi d40f8d8
add 3.11 testing on CI
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,47 @@ REMOVE_LOCAL_FEATURES=0 | |
|
|
||
| # WARNING: Be careful when turning on the next variable. | ||
| # In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env` | ||
| OVERWRITE_TESTING_ENVIRONMENT=0 | ||
| OVERWRITE_TESTING_ENVIRONMENT=1 | ||
|
|
||
| # WARNING: THE FOLLOWING IS FOR LOCAL DEVELOPMENT ONLY | ||
| # IF SET TO 1 AND PUSHED TO C.I., THE TEST WILL HANG AND FAIL. | ||
| # | ||
| # What can ease some of the pain above is to overwrite interactively: | ||
| INTERACTIVE_TESTING_ENVIRONMENT=0 | ||
|
|
||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ## --- FOR OVERWRITE PURPOSES! DELETE ALL THE BELOW!!!! | ||
|
|
||
| # Used to determine sandbox build type: | ||
| TYPE=source # (previously `"channel"`) # OR "source" | ||
|
|
||
|
|
||
| # Used when TYPE==channel: | ||
| ALGOD_CHANNEL="nightly" | ||
|
|
||
| # Used when TYPE==source: | ||
| ALGOD_URL=https://github.com/tzaffi/go-algorand # (previously `"https://github.com/algorand/go-algorand"`) | ||
| ALGOD_BRANCH=improve-some-goal-errors # (previously `"master"`) | ||
| ALGOD_SHA="" | ||
|
|
||
| # Used regardless of TYPE: | ||
| NETWORK_TEMPLATE="images/algod/DevModeNetwork.json" # refers to the ./images directory in the sandbox repo | ||
| NETWORK_NUM_ROUNDS=30000 | ||
| INDEXER_URL="https://github.com/algorand/indexer" | ||
| NODE_ARCHIVAL="False" | ||
| INDEXER_BRANCH="develop" | ||
| INDEXER_SHA="" | ||
|
|
||
| # Sandbox configuration: | ||
| SANDBOX_URL="https://github.com/algorand/sandbox" | ||
| SANDBOX_BRANCH="master" | ||
| LOCAL_SANDBOX_DIR=".sandbox" | ||
|
|
||
| # replacement values for Sandbox's docker-compose: | ||
| ALGOD_CONTAINER=sdk-harness-algod | ||
| KMD_PORT=60001 | ||
| ALGOD_PORT=60000 | ||
| INDEXER_CONTAINER=sdk-harness-indexer | ||
| INDEXER_PORT=59999 | ||
| POSTGRES_CONTAINER=sdk-harness-postgres | ||
| POSTGRES_PORT=65432 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import sys | ||
| from typing import Dict, Optional, Tuple | ||
|
|
||
|
|
||
| def get_env(line: str) -> Optional[Tuple[str, str, str]]: | ||
| if line and line[0] not in (" ", "#") and "=" in line: | ||
| key, others = line.split("=", maxsplit=1) | ||
| key = key.strip() | ||
| if "#" in others: | ||
| val, extra = others.split("#", maxsplit=1) | ||
| val = val.strip() | ||
| else: | ||
| val, extra = others.strip(), "" | ||
| return key, val, extra | ||
|
|
||
|
|
||
| def manualy_parse(env_file: str) -> Dict[str, str]: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "manually" as opposed with using |
||
| env = {} | ||
| with open(env_file) as f: | ||
| for line in f.readlines(): | ||
| if e := get_env(line): | ||
| key, val, _ = e | ||
| env[key] = val | ||
| return env | ||
|
|
||
|
|
||
| def overwrite(env_file: str, new_env: Dict[str, str]) -> None: | ||
| with open(env_file, "r+") as f: | ||
| lines = f.readlines() | ||
| for i, line in enumerate(lines): | ||
| if e := get_env(line): | ||
| key, old_val, extra = e | ||
| if key in new_env and (val := new_env[key]) != old_val: | ||
| lines[i] = ( | ||
| f"{key}={val} # (previously `{old_val}`)" | ||
| + (f" # {extra}" if extra else "") | ||
| + "\n" | ||
| ) | ||
|
|
||
| f.seek(0) | ||
| f.writelines(lines) | ||
| f.truncate() | ||
|
|
||
|
|
||
| def get_rewrites( | ||
| env: Dict[str, str], key_filter: Optional[str] = None | ||
| ) -> Dict[str, str]: | ||
| keys = key_filter.split(",") if key_filter else None | ||
| return { | ||
| k: w | ||
| for k, v in env.items() | ||
| if (not keys or k in keys) | ||
| and (w := input(f"{k} (default `{v}`):").strip()) | ||
| and w != v | ||
| } | ||
|
|
||
|
|
||
| def get_keys(env: Dict[str, str]) -> Optional[str]: | ||
| print( | ||
| f"""Which of the following env vars do you want to modify? | ||
|
|
||
| {",".join(env.keys())} | ||
|
|
||
| (skip for ALL, or provide comma separated) | ||
|
|
||
| A typical choice is: | ||
| TYPE,ALGOD_URL,ALGOD_BRANCH | ||
| """ | ||
| ) | ||
| return input("CHOICES:\n").strip() | ||
|
|
||
|
|
||
| def go(): | ||
| env_file = sys.argv[1] | ||
| env = manualy_parse(env_file) | ||
| print("_" * 50) | ||
| keys = get_keys(env) | ||
| print("_" * 50) | ||
| print("Please provide env variable overrides (skip to keep defaults)") | ||
| new_env = get_rewrites(env, key_filter=keys) | ||
|
|
||
| print("_" * 50) | ||
| print("OVERWRITING") | ||
| for k, v in new_env.items(): | ||
| print(f"new_env[{k}]={v} (PREVIOUS: env[{k}]={env[k]})") | ||
|
|
||
| overwrite(env_file, new_env) | ||
|
tzaffi marked this conversation as resolved.
|
||
| print("_" * 50) | ||
|
|
||
|
|
||
| go() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.