From c5e1c864c38ce64036663adb4070a9656d3c1446 Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Mon, 14 Apr 2025 14:30:47 +0100 Subject: [PATCH 1/5] CHIPFLOW_API_KEY and CHIPFLOW_API_KEY_SECRET' can now be used to submit. CHIPFLOW_API_KEY_SECRET will be eventually depriciated' --- chipflow_lib/steps/silicon.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/chipflow_lib/steps/silicon.py b/chipflow_lib/steps/silicon.py index 63a7f4e7..2c78c78e 100644 --- a/chipflow_lib/steps/silicon.py +++ b/chipflow_lib/steps/silicon.py @@ -84,11 +84,17 @@ def run_cli(self, args): raise ChipFlowError( "Key `chipflow.project_id` is not defined in chipflow.toml; " "see https://chipflow.io/beta for details on how to join the beta") - if ("CHIPFLOW_API_KEY_ID" not in os.environ or - "CHIPFLOW_API_KEY_SECRET" not in os.environ): + # Check for CHIPFLOW_API_KEY_SECRET or CHIPFLOW_API_KEY + if not os.environ.get("CHIPFLOW_API_KEY") and not os.environ.get("CHIPFLOW_API_KEY_SECRET"): raise ChipFlowError( - "Environment variables `CHIPFLOW_API_KEY_ID` and `CHIPFLOW_API_KEY_SECRET` " - "must be set in order to submit a design") + "Environment variable `CHIPFLOW_API_KEY` must be set to submit a design." + ) + # Log a deprecation warning if CHIPFLOW_API_KEY_SECRET is used + if os.environ.get("CHIPFLOW_API_KEY_SECRET"): + logger.warning( + "Environment variable `CHIPFLOW_API_KEY_SECRET` is deprecated. " + "Please migrate to using `CHIPFLOW_API_KEY` instead." + ) rtlil_path = self.prepare() # always prepare before submission if args.action == "submit": @@ -104,6 +110,11 @@ def prepare(self): def submit(self, rtlil_path, *, dry_run=False, wait=False): """Submit the design to the ChipFlow cloud builder. """ + chipflow_api_key = os.environ.get("CHIPFLOW_API_KEY") or os.environ.get("CHIPFLOW_API_KEY_SECRET") + if chipflow_api_key is None: + raise ChipFlowError( + "Environment variable `CHIPFLOW_API_KEY` is empty." + ) git_head = subprocess.check_output( ["git", "-C", os.environ["CHIPFLOW_ROOT"], "rev-parse", "--short", "HEAD"], @@ -160,7 +171,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): build_submit_url, # TODO: This needs to be reworked to accept only one key, auth accepts user and pass # TODO: but we want to submit a single key - auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]), + auth=(None, chipflow_api_key), data=data, files={ "rtlil": open(rtlil_path, "rb"), @@ -191,7 +202,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): logger.info("Polling build status...") status_resp = requests.get( build_status_url, - auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]) + auth=(None, chipflow_api_key) ) if status_resp.status_code != 200: logger.error(f"Failed to fetch build status: {status_resp.text}") @@ -219,7 +230,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): stream_event_counter += 1 with requests.get( log_stream_url, - auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]), + auth=(None, chipflow_api_key), stream=True ) as log_resp: if log_resp.status_code == 200: From e04cd36aa0c449ea1f738ba69ccae7b52b80455b Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Mon, 14 Apr 2025 14:36:32 +0100 Subject: [PATCH 2/5] moved all submit env var checking to submit function --- chipflow_lib/steps/silicon.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/chipflow_lib/steps/silicon.py b/chipflow_lib/steps/silicon.py index 2c78c78e..0ede8f98 100644 --- a/chipflow_lib/steps/silicon.py +++ b/chipflow_lib/steps/silicon.py @@ -84,17 +84,6 @@ def run_cli(self, args): raise ChipFlowError( "Key `chipflow.project_id` is not defined in chipflow.toml; " "see https://chipflow.io/beta for details on how to join the beta") - # Check for CHIPFLOW_API_KEY_SECRET or CHIPFLOW_API_KEY - if not os.environ.get("CHIPFLOW_API_KEY") and not os.environ.get("CHIPFLOW_API_KEY_SECRET"): - raise ChipFlowError( - "Environment variable `CHIPFLOW_API_KEY` must be set to submit a design." - ) - # Log a deprecation warning if CHIPFLOW_API_KEY_SECRET is used - if os.environ.get("CHIPFLOW_API_KEY_SECRET"): - logger.warning( - "Environment variable `CHIPFLOW_API_KEY_SECRET` is deprecated. " - "Please migrate to using `CHIPFLOW_API_KEY` instead." - ) rtlil_path = self.prepare() # always prepare before submission if args.action == "submit": @@ -110,6 +99,17 @@ def prepare(self): def submit(self, rtlil_path, *, dry_run=False, wait=False): """Submit the design to the ChipFlow cloud builder. """ + # Check for CHIPFLOW_API_KEY_SECRET or CHIPFLOW_API_KEY + if not os.environ.get("CHIPFLOW_API_KEY") and not os.environ.get("CHIPFLOW_API_KEY_SECRET"): + raise ChipFlowError( + "Environment variable `CHIPFLOW_API_KEY` must be set to submit a design." + ) + # Log a deprecation warning if CHIPFLOW_API_KEY_SECRET is used + if os.environ.get("CHIPFLOW_API_KEY_SECRET"): + logger.warning( + "Environment variable `CHIPFLOW_API_KEY_SECRET` is deprecated. " + "Please migrate to using `CHIPFLOW_API_KEY` instead." + ) chipflow_api_key = os.environ.get("CHIPFLOW_API_KEY") or os.environ.get("CHIPFLOW_API_KEY_SECRET") if chipflow_api_key is None: raise ChipFlowError( From 1ae8aad5dfd2af6926aafb1972653a44ba058096 Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Mon, 14 Apr 2025 14:39:02 +0100 Subject: [PATCH 3/5] moved all submit env var checking to submit function --- tests/test_steps_silicon.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_steps_silicon.py b/tests/test_steps_silicon.py index 76fe8175..3f9e7683 100644 --- a/tests/test_steps_silicon.py +++ b/tests/test_steps_silicon.py @@ -269,8 +269,7 @@ def test_run_cli_submit_missing_api_keys(self, mock_load_dotenv, mock_prepare): step.run_cli(args) # Verify error message - self.assertIn("CHIPFLOW_API_KEY_ID", str(cm.exception)) - self.assertIn("CHIPFLOW_API_KEY_SECRET", str(cm.exception)) + self.assertIn("CHIPFLOW_API_KEY", str(cm.exception)) # Verify dotenv was loaded mock_load_dotenv.assert_called_once() From 197fc6671935f10f03bfc986a2297ecd0bf4f042 Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Mon, 14 Apr 2025 14:50:54 +0100 Subject: [PATCH 4/5] if not dry_run --- chipflow_lib/steps/silicon.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/chipflow_lib/steps/silicon.py b/chipflow_lib/steps/silicon.py index 0ede8f98..cff96a2a 100644 --- a/chipflow_lib/steps/silicon.py +++ b/chipflow_lib/steps/silicon.py @@ -99,22 +99,25 @@ def prepare(self): def submit(self, rtlil_path, *, dry_run=False, wait=False): """Submit the design to the ChipFlow cloud builder. """ - # Check for CHIPFLOW_API_KEY_SECRET or CHIPFLOW_API_KEY - if not os.environ.get("CHIPFLOW_API_KEY") and not os.environ.get("CHIPFLOW_API_KEY_SECRET"): - raise ChipFlowError( - "Environment variable `CHIPFLOW_API_KEY` must be set to submit a design." - ) - # Log a deprecation warning if CHIPFLOW_API_KEY_SECRET is used - if os.environ.get("CHIPFLOW_API_KEY_SECRET"): - logger.warning( - "Environment variable `CHIPFLOW_API_KEY_SECRET` is deprecated. " - "Please migrate to using `CHIPFLOW_API_KEY` instead." - ) - chipflow_api_key = os.environ.get("CHIPFLOW_API_KEY") or os.environ.get("CHIPFLOW_API_KEY_SECRET") - if chipflow_api_key is None: - raise ChipFlowError( - "Environment variable `CHIPFLOW_API_KEY` is empty." - ) + if not dry_run: + # Check for CHIPFLOW_API_KEY_SECRET or CHIPFLOW_API_KEY + if not os.environ.get("CHIPFLOW_API_KEY") and not os.environ.get("CHIPFLOW_API_KEY_SECRET"): + raise ChipFlowError( + "Environment variable `CHIPFLOW_API_KEY` must be set to submit a design." + ) + # Log a deprecation warning if CHIPFLOW_API_KEY_SECRET is used + if os.environ.get("CHIPFLOW_API_KEY_SECRET"): + logger.warning( + "Environment variable `CHIPFLOW_API_KEY_SECRET` is deprecated. " + "Please migrate to using `CHIPFLOW_API_KEY` instead." + ) + chipflow_api_key = os.environ.get("CHIPFLOW_API_KEY") or os.environ.get("CHIPFLOW_API_KEY_SECRET") + if chipflow_api_key is None: + raise ChipFlowError( + "Environment variable `CHIPFLOW_API_KEY` is empty." + ) + + git_head = subprocess.check_output( ["git", "-C", os.environ["CHIPFLOW_ROOT"], "rev-parse", "--short", "HEAD"], From cda4fc1e17e74df0f230b9006f1a0db26c503946 Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Mon, 14 Apr 2025 14:52:55 +0100 Subject: [PATCH 5/5] remove whitespaces --- chipflow_lib/steps/silicon.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chipflow_lib/steps/silicon.py b/chipflow_lib/steps/silicon.py index cff96a2a..73a302c9 100644 --- a/chipflow_lib/steps/silicon.py +++ b/chipflow_lib/steps/silicon.py @@ -116,8 +116,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): raise ChipFlowError( "Environment variable `CHIPFLOW_API_KEY` is empty." ) - - + git_head = subprocess.check_output( ["git", "-C", os.environ["CHIPFLOW_ROOT"], "rev-parse", "--short", "HEAD"],