From 5c7c8efa516d88727e9ff153f75eeb73385d4f05 Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Fri, 24 May 2024 14:36:33 -0500 Subject: [PATCH 1/4] Specify title for first script Specifies the title for the first script to align with the title from the second version of it later in the document. --- docs/getting-started/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index f221d59fcb37..96380a27d524 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -22,7 +22,7 @@ Let's get started! Here's a basic script that fetches statistics about the [main Prefect GitHub repository](https://github.com/PrefectHQ/prefect). -```python +```python title="my_gh_workflow.py" import httpx def get_repo_info(): From 31b9ece3b2b412f79e047e4f83e2570b111393de Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Fri, 24 May 2024 14:45:30 -0500 Subject: [PATCH 2/4] Align the first and second scripts The first iteration of the script varied a bit from the second iteration, but the highlighted lines in the second iteration suggested only two lines had changed. This isn't quite true - for example, the function signature of 'get_repo_info' changed to include two new arguments. When following along with the quickstart, this makes it look like a "patch", but after applying the same changes to my code, I obviously got a different result. This change aligns the first version with the second. A drawback is this makes this initial script longer, but: - It's still not a very long script anyway. - The "copy" button is still there, which I suspect most people use anyway. - Those following along can now actually just change 4 lines now and get the new result. --- docs/getting-started/quickstart.md | 43 +++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 96380a27d524..a44084daa480 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -23,17 +23,42 @@ Let's get started! Here's a basic script that fetches statistics about the [main Prefect GitHub repository](https://github.com/PrefectHQ/prefect). ```python title="my_gh_workflow.py" -import httpx +import httpx # an HTTP client library and dependency of Prefect +from prefect import flow, task + + +def get_repo_info(repo_owner: str, repo_name: str): + """Get info about a repo""" + url = f"https://api.github.com/repos/{repo_owner}/{repo_name}" + api_response = httpx.get(url) + api_response.raise_for_status() + repo_info = api_response.json() + return repo_info + + +def get_contributors(repo_info: dict): + """Get contributors for a repo""" + contributors_url = repo_info["contributors_url"] + response = httpx.get(contributors_url) + response.raise_for_status() + contributors = response.json() + return contributors + + +def repo_info(repo_owner: str = "PrefectHQ", repo_name: str = "prefect"): + """ + Given a GitHub repository, logs the number of stargazers + and contributors for that repo. + """ + repo_info = get_repo_info(repo_owner, repo_name) + print(f"Stars 🌠 : {repo_info['stargazers_count']}") + + contributors = get_contributors(repo_info) + print(f"Number of contributors 👷: {len(contributors)}") -def get_repo_info(): - url = "https://api.github.com/repos/PrefectHQ/prefect" - response = httpx.get(url) - repo = response.json() - print("PrefectHQ/prefect repository statistics 🤓:") - print(f"Stars 🌠 : {repo['stargazers_count']}") if __name__ == "__main__": - get_repo_info() + repo_info() ``` Let's make this script schedulable, observable, resilient, and capable of running anywhere. @@ -76,7 +101,7 @@ If you have any issues with browser-based authentication, see the [Prefect Cloud The fastest way to get started with Prefect is to add a `@flow` decorator to your Python function. [Flows](/concepts/flows/) are the core observable, deployable units in Prefect and are the primary entrypoint to orchestrated work. -```python hl_lines="2 5" title="my_gh_workflow.py" +```python hl_lines="2 5 15 25" title="my_gh_workflow.py" import httpx # an HTTP client library and dependency of Prefect from prefect import flow, task From 2cb50557811b2f8e2fb703108ff2653894ad186d Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Fri, 24 May 2024 14:51:32 -0500 Subject: [PATCH 3/4] Update "Remove" to "Pause" for the schedule I didn't see a "Remove" button. I suspect this has changed, so I updated the instructions to toggle the button that disables the schedule. --- docs/getting-started/quickstart.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index a44084daa480..3fa29de6eef0 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -284,8 +284,8 @@ After a minute or so, you should see the flow run graph and logs on the Flow Run ![Managed flow run graph and logs](/img/ui/qs-flow-run.png) -!!! warning "Remove the schedule" - Click the **Remove** button in the top right of the **Deployment** page so that the workflow is no longer scheduled to run once per day. +!!! warning "Pause the schedule" + Toggle the button under **Schedules** in the top right of the **Deployment** page so that the workflow is no longer scheduled to run once per day. ## Next steps From 1b6b1c5d8a6612709c96066e267fc5af78f6cd58 Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Fri, 24 May 2024 16:16:01 -0500 Subject: [PATCH 4/4] Remove unnecessary import in first script The first script doesn't need the prefect package imports (just a copy/pasta error). Co-authored-by: Bill Palombi --- docs/getting-started/quickstart.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 3fa29de6eef0..d44bc0c00c9f 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -24,7 +24,6 @@ Here's a basic script that fetches statistics about the [main Prefect GitHub rep ```python title="my_gh_workflow.py" import httpx # an HTTP client library and dependency of Prefect -from prefect import flow, task def get_repo_info(repo_owner: str, repo_name: str):