From 0648efd08024264da94d9812754482179bb1a0c6 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 17:39:40 +0200 Subject: [PATCH 01/26] Enable PyCafe dashboards in CI --- .github/workflows/pycafe-dashboards-in-CI.yml | 48 ++++++ tools/pycafe/create_pycafe_links.py | 139 ++++++++++++++++++ vizro-core/examples/scratch_dev/app.py | 2 +- .../examples/scratch_dev/charts/__init__.py | 1 - .../examples/scratch_dev/charts/charts.py | 54 ------- vizro-core/hatch.toml | 3 +- vizro-core/src/vizro/models/_dashboard.py | 2 +- 7 files changed, 191 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/pycafe-dashboards-in-CI.yml create mode 100644 tools/pycafe/create_pycafe_links.py delete mode 100644 vizro-core/examples/scratch_dev/charts/__init__.py delete mode 100644 vizro-core/examples/scratch_dev/charts/charts.py diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml new file mode 100644 index 000000000..3a076d6cd --- /dev/null +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -0,0 +1,48 @@ +name: PyCafe Dashboards in CI + +on: + push: + branches: [main] + pull_request: + branches: + - main + +env: + PYTHON_VERSION: "3.12" + +jobs: + create-links: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r tools/tools_requirements.txt + pip install hatch + - name: "Build vizro core package" + run: | + cd vizro-core + hatch build + - name: "Upload Artifact" + uses: actions/upload-artifact@v4 + with: + name: pip + path: vizro-core/dist/*.whl + retention-days: 14 + + - name: Run Github Tool + env: + GITHUB_TOKEN: ${{ github.token }} + RUN_ID: ${{ github.run_id }} + GITHUB_REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.number }} + GITHUB_OWNER: mckinsey + + run: | + cd vizro-core + hatch run python ../tools/pycafe/create_pycafe_links.py examples/scratch_dev/ examples/dev/ examples/visual-vocabulary/ diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py new file mode 100644 index 000000000..1619aeb46 --- /dev/null +++ b/tools/pycafe/create_pycafe_links.py @@ -0,0 +1,139 @@ +"""Generate PyCafe links for the example dashboards and post them as a comment on the pull request and as status.""" + +import base64 +import datetime +import gzip +import json +import os +import subprocess +import sys +import textwrap +from pathlib import Path +from typing import Optional +from urllib.parse import quote, urlencode + +from github import Auth, Github + +GITHUB_TOKEN = str(os.getenv("GITHUB_TOKEN")) +REPO_NAME = str(os.getenv("GITHUB_REPOSITORY")) +PR_NUMBER = int(os.getenv("PR_NUMBER")) + + +RUN_ID = str(os.getenv("RUN_ID")) +PACKAGE_VERSION = subprocess.check_output(["hatch", "version"]).decode("utf-8").strip() +PYCAFE_URL = "https://py.cafe" + +# Access +auth = Auth.Token(GITHUB_TOKEN) +g = Github(auth=auth) + +# Get PR and commits +repo = g.get_repo(REPO_NAME) +pr = repo.get_pull(PR_NUMBER) +commit_sha = pr.head.sha +commit = repo.get_commit(commit_sha) + + +def generate_link(directory: str, extra_requirements: Optional[list[str]] = None): + base_url = f"https://raw.githubusercontent.com/mckinsey/vizro/{commit_sha}/vizro-core/{directory}" + + # Requirements + if extra_requirements: + extra_requirements_concat: str = "\n".join(extra_requirements) + else: + extra_requirements_concat = "" + requirements = ( + f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/vizro-{PACKAGE_VERSION}-py3-none-any.whl\n""" + + extra_requirements_concat + ) + print(f"Requirements: {requirements}") + + # App file + app_file_path = os.path.join(directory, "app.py") + app_content = Path(app_file_path).read_text() + app_content_split = app_content.split('if __name__ == "__main__":') + app_content = app_content_split[0] + textwrap.dedent(app_content_split[1]) + + # JSON object + json_object = { + "code": str(app_content), + "requirements": requirements, + "files": [], + } + for root, _, files in os.walk("./" + directory): + for file in files: + # print(root, file) + if "app.py" in file: + continue + file_path = os.path.join(root, file) + relative_path = os.path.relpath(file_path, directory) + file_url = f"{base_url}{relative_path.replace(os.sep, '/')}" + json_object["files"].append({"name": relative_path, "url": file_url}) + + # Final JSON object logging + print(f"Final JSON object: {json.dumps(json_object, indent=2)}") + + json_text = json.dumps(json_object) + compressed_json_text = gzip.compress(json_text.encode("utf8")) + base64_text = base64.b64encode(compressed_json_text).decode("utf8") + query = urlencode({"c": base64_text}, quote_via=quote) + return f"{PYCAFE_URL}/snippet/vizro/v1?{query}" + + +def post_comment(urls: list[tuple[str, str]]): + """Post a comment on the pull request with the links to the PyCafe dashboards.""" + # Inspired by https://github.com/snehilvj/dash-mantine-components + + # Find existing comments by the bot + comments = pr.get_issue_comments() + bot_comment = None + for comment in comments: + if comment.body.startswith("View the dashboard live on PyCafe:"): + bot_comment = comment + break + + # Get current UTC datetime + current_utc_time = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") + + # Define the comment body with datetime + dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls) + + comment_body = f"""View the example dashboards of the current commit live on PyCafe:\n +Updated on: {current_utc_time} +Commit: {commit_sha} + +{dashboards} +""" + + # Update the existing comment or create a new one + if bot_comment: + bot_comment.edit(comment_body) + print("Comment updated on the pull request.") + else: + pr.create_issue_comment(comment_body) + print("Comment added to the pull request.") + + +if __name__ == "__main__": + urls = [] + + # Generate links for each directory and create status + for directory in sys.argv[1:]: + if directory == "examples/dev/": + url = generate_link(directory=directory, extra_requirements=["openpyxl"]) + else: + url = generate_link(directory=directory) + urls.append((url, directory)) + + # Define the deployment status + state = "success" # Options: 'error', 'failure', 'pending', 'success' + description = "Test out the app live on PyCafe" + context = f"PyCafe Example ({directory})" + + # Create the status on the commit + commit.create_status(state=state, target_url=url, description=description, context=context) + + # Post the comment with the links + post_comment(urls) + + print("All done!") diff --git a/vizro-core/examples/scratch_dev/app.py b/vizro-core/examples/scratch_dev/app.py index cafe6d7bb..e11904907 100644 --- a/vizro-core/examples/scratch_dev/app.py +++ b/vizro-core/examples/scratch_dev/app.py @@ -28,7 +28,7 @@ page = vm.Page( - title="Diverging bar", + title="Test I", components=[ vm.Graph( figure=px.bar( diff --git a/vizro-core/examples/scratch_dev/charts/__init__.py b/vizro-core/examples/scratch_dev/charts/__init__.py deleted file mode 100644 index 6d7efd871..000000000 --- a/vizro-core/examples/scratch_dev/charts/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .charts import my_custom_aggrid, page2 diff --git a/vizro-core/examples/scratch_dev/charts/charts.py b/vizro-core/examples/scratch_dev/charts/charts.py deleted file mode 100644 index 58677b1c0..000000000 --- a/vizro-core/examples/scratch_dev/charts/charts.py +++ /dev/null @@ -1,54 +0,0 @@ -"""File to simulate imports from other modules.""" - -import vizro.models as vm -import vizro.plotly.express as px -from dash_ag_grid import AgGrid -from vizro.actions import export_data -from vizro.models.types import capture -from vizro.tables import dash_ag_grid - -df = px.data.iris() - - -@capture("ag_grid") -def my_custom_aggrid(chosen_columns, data_frame=None): - """Custom ag_grid.""" - defaults = { - "className": "ag-theme-quartz-dark ag-theme-vizro", - "defaultColDef": { - "resizable": True, - "sortable": True, - "filter": True, - "filterParams": { - "buttons": ["apply", "reset"], - "closeOnApply": True, - }, - "flex": 1, - "minWidth": 70, - }, - "style": {"height": "100%"}, - } - return AgGrid( - columnDefs=[{"field": col} for col in chosen_columns], rowData=data_frame.to_dict("records"), **defaults - ) - - -page2 = vm.Page( - title="Page2", - components=[ - vm.Graph(id="hist_chart2", figure=px.histogram(df, x="sepal_width", color="species")), - vm.AgGrid(figure=my_custom_aggrid(data_frame="iris", chosen_columns=["sepal_width", "sepal_length"])), - vm.AgGrid(figure=dash_ag_grid(data_frame="iris")), - vm.Button( - text="Export data", - actions=[ - vm.Action(function=export_data()), - vm.Action( - function=export_data( - file_format="xlsx", - ) - ), - ], - ), - ], -) diff --git a/vizro-core/hatch.toml b/vizro-core/hatch.toml index 3e64f4fe9..7c002d2f0 100644 --- a/vizro-core/hatch.toml +++ b/vizro-core/hatch.toml @@ -29,7 +29,8 @@ dependencies = [ "pyyaml", "openpyxl", "jupyter", - "pre-commit" + "pre-commit", + "PyGithub" ] installer = "uv" diff --git a/vizro-core/src/vizro/models/_dashboard.py b/vizro-core/src/vizro/models/_dashboard.py index 477dfca3d..6ab4559b1 100644 --- a/vizro-core/src/vizro/models/_dashboard.py +++ b/vizro-core/src/vizro/models/_dashboard.py @@ -22,6 +22,7 @@ html, ) +import vizro from vizro._themes._templates.template_dashboard_overrides import dashboard_overrides try: @@ -31,7 +32,6 @@ from dash.development.base_component import Component -import vizro from vizro._constants import MODULE_PAGE_404, VIZRO_ASSETS_PATH from vizro.actions._action_loop._action_loop import ActionLoop from vizro.models import Navigation, VizroBaseModel From 67aacf972dd979415e56e4d44b5efbce52c68182 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 17:47:46 +0200 Subject: [PATCH 02/26] Changelog --- tools/pycafe/create_pycafe_links.py | 1 + ...7_174654_maximilian_schulz_pycafe_in_ci.md | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 vizro-core/changelog.d/20241017_174654_maximilian_schulz_pycafe_in_ci.md diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 1619aeb46..079697682 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -119,6 +119,7 @@ def post_comment(urls: list[tuple[str, str]]): # Generate links for each directory and create status for directory in sys.argv[1:]: + # Add any extra requirements for specific dev examples if directory == "examples/dev/": url = generate_link(directory=directory, extra_requirements=["openpyxl"]) else: diff --git a/vizro-core/changelog.d/20241017_174654_maximilian_schulz_pycafe_in_ci.md b/vizro-core/changelog.d/20241017_174654_maximilian_schulz_pycafe_in_ci.md new file mode 100644 index 000000000..7c0d58d4f --- /dev/null +++ b/vizro-core/changelog.d/20241017_174654_maximilian_schulz_pycafe_in_ci.md @@ -0,0 +1,48 @@ + + + + + + + + + From 68ff719a0d679d6f114380684cc893dd970c65c1 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 17:51:38 +0200 Subject: [PATCH 03/26] Small fixes --- tools/pycafe/create_pycafe_links.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 079697682..cccf939ce 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -88,12 +88,12 @@ def post_comment(urls: list[tuple[str, str]]): comments = pr.get_issue_comments() bot_comment = None for comment in comments: - if comment.body.startswith("View the dashboard live on PyCafe:"): + if comment.body.startswith("View the dashboards live on PyCafe:"): bot_comment = comment break # Get current UTC datetime - current_utc_time = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") + current_utc_time = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S UTC") # Define the comment body with datetime dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls) From 74c766d566b0299c1762bbea8adc47f2bae7bd89 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 17:54:44 +0200 Subject: [PATCH 04/26] Further small improvements --- tools/pycafe/create_pycafe_links.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index cccf939ce..787a9088b 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -46,7 +46,6 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/vizro-{PACKAGE_VERSION}-py3-none-any.whl\n""" + extra_requirements_concat ) - print(f"Requirements: {requirements}") # App file app_file_path = os.path.join(directory, "app.py") @@ -62,7 +61,6 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None } for root, _, files in os.walk("./" + directory): for file in files: - # print(root, file) if "app.py" in file: continue file_path = os.path.join(root, file) @@ -70,9 +68,6 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None file_url = f"{base_url}{relative_path.replace(os.sep, '/')}" json_object["files"].append({"name": relative_path, "url": file_url}) - # Final JSON object logging - print(f"Final JSON object: {json.dumps(json_object, indent=2)}") - json_text = json.dumps(json_object) compressed_json_text = gzip.compress(json_text.encode("utf8")) base64_text = base64.b64encode(compressed_json_text).decode("utf8") @@ -133,8 +128,7 @@ def post_comment(urls: list[tuple[str, str]]): # Create the status on the commit commit.create_status(state=state, target_url=url, description=description, context=context) + print(f"Status created for {context} with URL: {url}") # Post the comment with the links post_comment(urls) - - print("All done!") From eef298040a9d345699350af1e0b97e5f6e4cac12 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 17:56:33 +0200 Subject: [PATCH 05/26] Make workflow a little nicer --- .github/workflows/pycafe-dashboards-in-CI.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index 3a076d6cd..5fc5cbccf 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -24,18 +24,18 @@ jobs: python -m pip install --upgrade pip pip install -r tools/tools_requirements.txt pip install hatch - - name: "Build vizro core package" + - name: "Build vizro-core package" run: | cd vizro-core hatch build - - name: "Upload Artifact" + - name: "Upload artifact" uses: actions/upload-artifact@v4 with: name: pip path: vizro-core/dist/*.whl retention-days: 14 - - name: Run Github Tool + - name: "Create PyCafe links" env: GITHUB_TOKEN: ${{ github.token }} RUN_ID: ${{ github.run_id }} From a5977ad665f91d4e39bbb7a25c903bccb406d4cc Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 17:59:05 +0200 Subject: [PATCH 06/26] Fix update vs comment check --- tools/pycafe/create_pycafe_links.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 787a9088b..4471aef03 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -83,7 +83,7 @@ def post_comment(urls: list[tuple[str, str]]): comments = pr.get_issue_comments() bot_comment = None for comment in comments: - if comment.body.startswith("View the dashboards live on PyCafe:"): + if comment.body.startswith("View the example dashboards of the current commit live"): bot_comment = comment break From 61d3da831b6e25752c1a4804d4d736fe6bab7fcc Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 17 Oct 2024 18:04:36 +0200 Subject: [PATCH 07/26] Linting --- tools/pycafe/create_pycafe_links.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 4471aef03..a2176a913 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -35,6 +35,7 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None): + """Generate a PyCafe link for the example dashboards.""" base_url = f"https://raw.githubusercontent.com/mckinsey/vizro/{commit_sha}/vizro-core/{directory}" # Requirements @@ -103,10 +104,10 @@ def post_comment(urls: list[tuple[str, str]]): # Update the existing comment or create a new one if bot_comment: bot_comment.edit(comment_body) - print("Comment updated on the pull request.") + print("Comment updated on the pull request.") # noqa else: pr.create_issue_comment(comment_body) - print("Comment added to the pull request.") + print("Comment added to the pull request.") # noqa if __name__ == "__main__": @@ -128,7 +129,7 @@ def post_comment(urls: list[tuple[str, str]]): # Create the status on the commit commit.create_status(state=state, target_url=url, description=description, context=context) - print(f"Status created for {context} with URL: {url}") + print(f"Status created for {context} with URL: {url}") # noqa # Post the comment with the links post_comment(urls) From 4574abcf2b5ee988e5338c7031b3018741678ca0 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Fri, 18 Oct 2024 09:01:19 +0200 Subject: [PATCH 08/26] Some further small refactorings --- .github/workflows/pycafe-dashboards-in-CI.yml | 1 - tools/pycafe/create_pycafe_links.py | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index 5fc5cbccf..b9ff8c364 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -41,7 +41,6 @@ jobs: RUN_ID: ${{ github.run_id }} GITHUB_REPOSITORY: ${{ github.repository }} PR_NUMBER: ${{ github.event.number }} - GITHUB_OWNER: mckinsey run: | cd vizro-core diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index a2176a913..78d4e2884 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -17,8 +17,6 @@ GITHUB_TOKEN = str(os.getenv("GITHUB_TOKEN")) REPO_NAME = str(os.getenv("GITHUB_REPOSITORY")) PR_NUMBER = int(os.getenv("PR_NUMBER")) - - RUN_ID = str(os.getenv("RUN_ID")) PACKAGE_VERSION = subprocess.check_output(["hatch", "version"]).decode("utf-8").strip() PYCAFE_URL = "https://py.cafe" @@ -39,10 +37,7 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None base_url = f"https://raw.githubusercontent.com/mckinsey/vizro/{commit_sha}/vizro-core/{directory}" # Requirements - if extra_requirements: - extra_requirements_concat: str = "\n".join(extra_requirements) - else: - extra_requirements_concat = "" + extra_requirements_concat = "\n".join(extra_requirements) if extra_requirements else "" requirements = ( f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/vizro-{PACKAGE_VERSION}-py3-none-any.whl\n""" + extra_requirements_concat @@ -52,7 +47,8 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None app_file_path = os.path.join(directory, "app.py") app_content = Path(app_file_path).read_text() app_content_split = app_content.split('if __name__ == "__main__":') - app_content = app_content_split[0] + textwrap.dedent(app_content_split[1]) + if len(app_content_split) > 1: + app_content = app_content_split[0] + textwrap.dedent(app_content_split[1]) # JSON object json_object = { From 18c28b6253e8bd63edb0eea857f1ac2a39c32705 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Wed, 23 Oct 2024 13:19:29 +0200 Subject: [PATCH 09/26] PR comments --- .github/workflows/pycafe-dashboards-in-CI.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index b9ff8c364..465b12302 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -1,4 +1,4 @@ -name: PyCafe Dashboards in CI +name: PyCafe Dashboards on: push: @@ -6,6 +6,8 @@ on: pull_request: branches: - main + paths: + - "vizro-core/**" env: PYTHON_VERSION: "3.12" @@ -19,23 +21,20 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r tools/tools_requirements.txt - pip install hatch - - name: "Build vizro-core package" + - name: Install Hatch + run: pip install hatch + - name: Build vizro-core package run: | cd vizro-core - hatch build - - name: "Upload artifact" + hatch build -t wheel + - name: Upload artifact uses: actions/upload-artifact@v4 with: name: pip path: vizro-core/dist/*.whl retention-days: 14 - - name: "Create PyCafe links" + - name: Create PyCafe links env: GITHUB_TOKEN: ${{ github.token }} RUN_ID: ${{ github.run_id }} From 33150e686fb875037444f44f24d78fd17c28f289 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:19:51 +0000 Subject: [PATCH 10/26] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/pycafe-dashboards-in-CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index 465b12302..510a5b3c4 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -6,7 +6,7 @@ on: pull_request: branches: - main - paths: + paths: - "vizro-core/**" env: From a6b75ed5ea64f7357e4ed348eeafdf9d86d5fede Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Wed, 23 Oct 2024 13:40:57 +0200 Subject: [PATCH 11/26] Further PR comments --- tools/pycafe/create_pycafe_links.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 78d4e2884..69ad37c9f 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -44,15 +44,14 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None ) # App file - app_file_path = os.path.join(directory, "app.py") - app_content = Path(app_file_path).read_text() + app_content = Path(directory, "app.py").read_text() app_content_split = app_content.split('if __name__ == "__main__":') if len(app_content_split) > 1: app_content = app_content_split[0] + textwrap.dedent(app_content_split[1]) # JSON object json_object = { - "code": str(app_content), + "code": app_content, "requirements": requirements, "files": [], } @@ -80,7 +79,7 @@ def post_comment(urls: list[tuple[str, str]]): comments = pr.get_issue_comments() bot_comment = None for comment in comments: - if comment.body.startswith("View the example dashboards of the current commit live"): + if comment.body.startswith("## View the example dashboards of the current commit live"): bot_comment = comment break @@ -90,7 +89,7 @@ def post_comment(urls: list[tuple[str, str]]): # Define the comment body with datetime dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls) - comment_body = f"""View the example dashboards of the current commit live on PyCafe:\n + comment_body = f"""## View the example dashboards of the current commit live on PyCafe :coffee: :rocket:\n Updated on: {current_utc_time} Commit: {commit_sha} From 19f65151b41dc54091940e7209378a33acb20ba0 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Wed, 23 Oct 2024 13:54:49 +0200 Subject: [PATCH 12/26] Better template --- tools/pycafe/create_pycafe_links.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 69ad37c9f..9e204ebad 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -21,6 +21,13 @@ PACKAGE_VERSION = subprocess.check_output(["hatch", "version"]).decode("utf-8").strip() PYCAFE_URL = "https://py.cafe" +BOT_COMMENT_TEMPLATE = """## View the example dashboards of the current commit live on PyCafe :coffee: :rocket:\n +Updated on: {current_utc_time} +Commit: {commit_sha} + +{dashboards} +""" + # Access auth = Auth.Token(GITHUB_TOKEN) g = Github(auth=auth) @@ -89,19 +96,16 @@ def post_comment(urls: list[tuple[str, str]]): # Define the comment body with datetime dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls) - comment_body = f"""## View the example dashboards of the current commit live on PyCafe :coffee: :rocket:\n -Updated on: {current_utc_time} -Commit: {commit_sha} - -{dashboards} -""" - # Update the existing comment or create a new one if bot_comment: - bot_comment.edit(comment_body) + bot_comment.edit( + BOT_COMMENT_TEMPLATE.format(current_utc_time=current_utc_time, commit_sha=commit_sha, dashboards=dashboards) + ) print("Comment updated on the pull request.") # noqa else: - pr.create_issue_comment(comment_body) + pr.create_issue_comment( + BOT_COMMENT_TEMPLATE.format(current_utc_time=current_utc_time, commit_sha=commit_sha, dashboards=dashboards) + ) print("Comment added to the pull request.") # noqa From d3d1480415f82a043b1cee62a087f752dadffdd0 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 11:50:57 +0200 Subject: [PATCH 13/26] default working directory --- .github/workflows/pycafe-dashboards-in-CI.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index 510a5b3c4..1c0174ffc 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -9,6 +9,10 @@ on: paths: - "vizro-core/**" +defaults: + run: + working-directory: vizro-core + env: PYTHON_VERSION: "3.12" @@ -25,7 +29,6 @@ jobs: run: pip install hatch - name: Build vizro-core package run: | - cd vizro-core hatch build -t wheel - name: Upload artifact uses: actions/upload-artifact@v4 @@ -42,5 +45,4 @@ jobs: PR_NUMBER: ${{ github.event.number }} run: | - cd vizro-core hatch run python ../tools/pycafe/create_pycafe_links.py examples/scratch_dev/ examples/dev/ examples/visual-vocabulary/ From 88cdc7cdf1f8a9e6b985a4d4055ba699d1c3de5e Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 13:35:05 +0200 Subject: [PATCH 14/26] Refactor script without sys arguments --- .github/workflows/pycafe-dashboards-in-CI.yml | 2 +- tools/pycafe/create_pycafe_links.py | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index 1c0174ffc..ba32ead3a 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -45,4 +45,4 @@ jobs: PR_NUMBER: ${{ github.event.number }} run: | - hatch run python ../tools/pycafe/create_pycafe_links.py examples/scratch_dev/ examples/dev/ examples/visual-vocabulary/ + hatch run python ../tools/pycafe/create_pycafe_links.py diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 9e204ebad..b8fe93987 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -6,7 +6,6 @@ import json import os import subprocess -import sys import textwrap from pathlib import Path from typing import Optional @@ -78,7 +77,7 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None return f"{PYCAFE_URL}/snippet/vizro/v1?{query}" -def post_comment(urls: list[tuple[str, str]]): +def post_comment(urls: dict[str, str]): """Post a comment on the pull request with the links to the PyCafe dashboards.""" # Inspired by https://github.com/snehilvj/dash-mantine-components @@ -94,7 +93,7 @@ def post_comment(urls: list[tuple[str, str]]): current_utc_time = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S UTC") # Define the comment body with datetime - dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls) + dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls.items()) # Update the existing comment or create a new one if bot_comment: @@ -110,17 +109,18 @@ def post_comment(urls: list[tuple[str, str]]): if __name__ == "__main__": - urls = [] - - # Generate links for each directory and create status - for directory in sys.argv[1:]: - # Add any extra requirements for specific dev examples - if directory == "examples/dev/": - url = generate_link(directory=directory, extra_requirements=["openpyxl"]) - else: - url = generate_link(directory=directory) - urls.append((url, directory)) + directories_with_requirements = { + "examples/dev/": ["openpyxl"], + "examples/scratch_dev": None, + "examples/visual-vocabulary/": None, + } + urls = { + directory: generate_link(directory, extra_requirements) + for directory, extra_requirements in directories_with_requirements.items() + } + # Create status + for directory, url in urls.items(): # Define the deployment status state = "success" # Options: 'error', 'failure', 'pending', 'success' description = "Test out the app live on PyCafe" From 4de8e77a5565ef5fa25c8f2c658224fa2eedb407 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 13:49:59 +0200 Subject: [PATCH 15/26] Correct order url and directory --- tools/pycafe/create_pycafe_links.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index b8fe93987..18f9396a7 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -93,7 +93,7 @@ def post_comment(urls: dict[str, str]): current_utc_time = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S UTC") # Define the comment body with datetime - dashboards = "\n\n".join(f"Link: [{directory}]({url})" for url, directory in urls.items()) + dashboards = "\n\n".join(f"Link: [{directory}]({url})" for directory, url in urls.items()) # Update the existing comment or create a new one if bot_comment: From 437e21beb6eae6791f373b34150d82062d752c68 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:08:25 +0200 Subject: [PATCH 16/26] Further PR comments --- tools/pycafe/create_pycafe_links.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 18f9396a7..55d537ab3 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -5,7 +5,6 @@ import gzip import json import os -import subprocess import textwrap from pathlib import Path from typing import Optional @@ -17,8 +16,9 @@ REPO_NAME = str(os.getenv("GITHUB_REPOSITORY")) PR_NUMBER = int(os.getenv("PR_NUMBER")) RUN_ID = str(os.getenv("RUN_ID")) -PACKAGE_VERSION = subprocess.check_output(["hatch", "version"]).decode("utf-8").strip() +WHL_FILE = next(Path("dist").glob("*.whl")).stem PYCAFE_URL = "https://py.cafe" +VIZRO_RAW_URL = "https://raw.githubusercontent.com/mckinsey/vizro" BOT_COMMENT_TEMPLATE = """## View the example dashboards of the current commit live on PyCafe :coffee: :rocket:\n Updated on: {current_utc_time} @@ -40,12 +40,12 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None): """Generate a PyCafe link for the example dashboards.""" - base_url = f"https://raw.githubusercontent.com/mckinsey/vizro/{commit_sha}/vizro-core/{directory}" + base_url = f"{VIZRO_RAW_URL}/{commit_sha}/vizro-core/{directory}" # Requirements extra_requirements_concat = "\n".join(extra_requirements) if extra_requirements else "" requirements = ( - f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/vizro-{PACKAGE_VERSION}-py3-none-any.whl\n""" + f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/{WHL_FILE}\n""" + extra_requirements_concat ) From e7f763f1746f1134fd8bf5685dcded0dfce1c6da Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:13:28 +0200 Subject: [PATCH 17/26] Print out for debugging --- tools/pycafe/create_pycafe_links.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 55d537ab3..233abe9b7 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -48,6 +48,8 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/{WHL_FILE}\n""" + extra_requirements_concat ) + print(WHL_FILE) + print(requirements) # App file app_content = Path(directory, "app.py").read_text() From f247c1320b200f4b98700393a3033e032753bf5d Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:16:42 +0200 Subject: [PATCH 18/26] Include file ending --- tools/pycafe/create_pycafe_links.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 233abe9b7..1cd63c621 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -16,7 +16,7 @@ REPO_NAME = str(os.getenv("GITHUB_REPOSITORY")) PR_NUMBER = int(os.getenv("PR_NUMBER")) RUN_ID = str(os.getenv("RUN_ID")) -WHL_FILE = next(Path("dist").glob("*.whl")).stem +WHL_FILE = next(Path("dist").glob("*.whl")).name PYCAFE_URL = "https://py.cafe" VIZRO_RAW_URL = "https://raw.githubusercontent.com/mckinsey/vizro" @@ -48,8 +48,6 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/{WHL_FILE}\n""" + extra_requirements_concat ) - print(WHL_FILE) - print(requirements) # App file app_content = Path(directory, "app.py").read_text() From bb69b56a654acf24bb2344d56626e124f5f10e0b Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:25:58 +0200 Subject: [PATCH 19/26] Switch to pathlib --- tools/pycafe/create_pycafe_links.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 1cd63c621..1a8fe9771 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -61,14 +61,14 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None "requirements": requirements, "files": [], } - for root, _, files in os.walk("./" + directory): - for file in files: - if "app.py" in file: - continue - file_path = os.path.join(root, file) - relative_path = os.path.relpath(file_path, directory) - file_url = f"{base_url}{relative_path.replace(os.sep, '/')}" - json_object["files"].append({"name": relative_path, "url": file_url}) + + for file_path in Path(directory).rglob('*'): + print(file_path) + if file_path.name == "app.py": + continue + relative_path = file_path.relative_to(directory) + file_url = f"{base_url}/{relative_path.as_posix()}" + json_object["files"].append({"name": str(relative_path), "url": file_url}) json_text = json.dumps(json_object) compressed_json_text = gzip.compress(json_text.encode("utf8")) From 4fc9097ef1138bef2574a836a037407611f50b4f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:26:36 +0000 Subject: [PATCH 20/26] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tools/pycafe/create_pycafe_links.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 1a8fe9771..bc5f86de9 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -61,8 +61,8 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None "requirements": requirements, "files": [], } - - for file_path in Path(directory).rglob('*'): + + for file_path in Path(directory).rglob("*"): print(file_path) if file_path.name == "app.py": continue From 54f325a3df5d19c77fe57823af26d6732d722f80 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:30:12 +0200 Subject: [PATCH 21/26] debugging --- tools/pycafe/create_pycafe_links.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index bc5f86de9..1860ac299 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -69,7 +69,9 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None relative_path = file_path.relative_to(directory) file_url = f"{base_url}/{relative_path.as_posix()}" json_object["files"].append({"name": str(relative_path), "url": file_url}) - + print("---------------------") + print(json_object) + print("=====================") json_text = json.dumps(json_object) compressed_json_text = gzip.compress(json_text.encode("utf8")) base64_text = base64.b64encode(compressed_json_text).decode("utf8") From 28a1eaffecdc61f5e3879a85bf8ace8825ff5e13 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:36:49 +0200 Subject: [PATCH 22/26] Skip directories --- tools/pycafe/create_pycafe_links.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 1860ac299..5b37e26b5 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -63,20 +63,17 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None } for file_path in Path(directory).rglob("*"): - print(file_path) - if file_path.name == "app.py": + if file_path.is_dir() or file_path.name == "app.py": continue relative_path = file_path.relative_to(directory) file_url = f"{base_url}/{relative_path.as_posix()}" json_object["files"].append({"name": str(relative_path), "url": file_url}) - print("---------------------") - print(json_object) - print("=====================") - json_text = json.dumps(json_object) - compressed_json_text = gzip.compress(json_text.encode("utf8")) - base64_text = base64.b64encode(compressed_json_text).decode("utf8") - query = urlencode({"c": base64_text}, quote_via=quote) - return f"{PYCAFE_URL}/snippet/vizro/v1?{query}" + + json_text = json.dumps(json_object) + compressed_json_text = gzip.compress(json_text.encode("utf8")) + base64_text = base64.b64encode(compressed_json_text).decode("utf8") + query = urlencode({"c": base64_text}, quote_via=quote) + return f"{PYCAFE_URL}/snippet/vizro/v1?{query}" def post_comment(urls: dict[str, str]): From dd9ede2e92973accd938fcec9e01c69c96b83899 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:41:21 +0200 Subject: [PATCH 23/26] wrong indent --- tools/pycafe/create_pycafe_links.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 5b37e26b5..79469a999 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -69,11 +69,11 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None file_url = f"{base_url}/{relative_path.as_posix()}" json_object["files"].append({"name": str(relative_path), "url": file_url}) - json_text = json.dumps(json_object) - compressed_json_text = gzip.compress(json_text.encode("utf8")) - base64_text = base64.b64encode(compressed_json_text).decode("utf8") - query = urlencode({"c": base64_text}, quote_via=quote) - return f"{PYCAFE_URL}/snippet/vizro/v1?{query}" + json_text = json.dumps(json_object) + compressed_json_text = gzip.compress(json_text.encode("utf8")) + base64_text = base64.b64encode(compressed_json_text).decode("utf8") + query = urlencode({"c": base64_text}, quote_via=quote) + return f"{PYCAFE_URL}/snippet/vizro/v1?{query}" def post_comment(urls: dict[str, str]): From 12fedf4a0ab66374fa2a2ad9a5a3c54b81eda283 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:45:12 +0200 Subject: [PATCH 24/26] Refactor to make more pythonic --- tools/pycafe/create_pycafe_links.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 79469a999..e7919e396 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -62,12 +62,14 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None "files": [], } - for file_path in Path(directory).rglob("*"): - if file_path.is_dir() or file_path.name == "app.py": - continue - relative_path = file_path.relative_to(directory) - file_url = f"{base_url}/{relative_path.as_posix()}" - json_object["files"].append({"name": str(relative_path), "url": file_url}) + json_object["files"] = [ + { + "name": str(file_path.relative_to(directory)), + "url": f"{base_url}/{file_path.relative_to(directory).as_posix()}", + } + for file_path in Path(directory).rglob("*") + if not file_path.is_dir() and file_path.relative_to(directory) != Path("app.py") + ] json_text = json.dumps(json_object) compressed_json_text = gzip.compress(json_text.encode("utf8")) From b81bbdaaa1337610605503cbd4e7ea706dab9d82 Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:53:38 +0200 Subject: [PATCH 25/26] Improve extra requirements --- tools/pycafe/create_pycafe_links.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index e7919e396..351940021 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -43,10 +43,14 @@ def generate_link(directory: str, extra_requirements: Optional[list[str]] = None base_url = f"{VIZRO_RAW_URL}/{commit_sha}/vizro-core/{directory}" # Requirements - extra_requirements_concat = "\n".join(extra_requirements) if extra_requirements else "" - requirements = ( - f"""{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/{WHL_FILE}\n""" - + extra_requirements_concat + requirements = "\n".join( + filter( + None, + [ + f"{PYCAFE_URL}/gh/artifact/mckinsey/vizro/actions/runs/{RUN_ID}/pip/{WHL_FILE}", + *(extra_requirements or []), + ], + ) ) # App file From 4ef09be85297be9180c88f76b68d2b01cccf873e Mon Sep 17 00:00:00 2001 From: Maximilian Schulz Date: Thu, 24 Oct 2024 14:56:49 +0200 Subject: [PATCH 26/26] Change from env variables --- .github/workflows/pycafe-dashboards-in-CI.yml | 8 +------- tools/pycafe/create_pycafe_links.py | 10 +++++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pycafe-dashboards-in-CI.yml b/.github/workflows/pycafe-dashboards-in-CI.yml index ba32ead3a..a75660ba6 100644 --- a/.github/workflows/pycafe-dashboards-in-CI.yml +++ b/.github/workflows/pycafe-dashboards-in-CI.yml @@ -38,11 +38,5 @@ jobs: retention-days: 14 - name: Create PyCafe links - env: - GITHUB_TOKEN: ${{ github.token }} - RUN_ID: ${{ github.run_id }} - GITHUB_REPOSITORY: ${{ github.repository }} - PR_NUMBER: ${{ github.event.number }} - run: | - hatch run python ../tools/pycafe/create_pycafe_links.py + hatch run python ../tools/pycafe/create_pycafe_links.py ${{ github.token }} ${{ github.repository }} ${{ github.event.number }} ${{ github.run_id }} diff --git a/tools/pycafe/create_pycafe_links.py b/tools/pycafe/create_pycafe_links.py index 351940021..fc93bb8fc 100644 --- a/tools/pycafe/create_pycafe_links.py +++ b/tools/pycafe/create_pycafe_links.py @@ -4,7 +4,7 @@ import datetime import gzip import json -import os +import sys import textwrap from pathlib import Path from typing import Optional @@ -12,10 +12,10 @@ from github import Auth, Github -GITHUB_TOKEN = str(os.getenv("GITHUB_TOKEN")) -REPO_NAME = str(os.getenv("GITHUB_REPOSITORY")) -PR_NUMBER = int(os.getenv("PR_NUMBER")) -RUN_ID = str(os.getenv("RUN_ID")) +GITHUB_TOKEN = sys.argv[1] +REPO_NAME = sys.argv[2] +PR_NUMBER = int(sys.argv[3]) +RUN_ID = sys.argv[4] WHL_FILE = next(Path("dist").glob("*.whl")).name PYCAFE_URL = "https://py.cafe" VIZRO_RAW_URL = "https://raw.githubusercontent.com/mckinsey/vizro"