Add Python dependencies example workflow.#1576
Merged
tswast merged 5 commits intoGoogleCloudPlatform:masterfrom Jul 19, 2018
Merged
Add Python dependencies example workflow.#1576tswast merged 5 commits intoGoogleCloudPlatform:masterfrom
tswast merged 5 commits intoGoogleCloudPlatform:masterfrom
Conversation
Updates sample to use relative imports. Adds license headers. Uses 4 spaces for indentation.
tswast
approved these changes
Jul 19, 2018
| @@ -0,0 +1,11 @@ | |||
| # Python dependencies example | |||
|
|
|||
| In this example DAG (`dag.py`), we need to use two Python packages: | |||
Contributor
There was a problem hiding this comment.
Let's add a requirements.txt file for these dependencies. The test runner uses the presence of requirements.txt to find samples.
| @@ -0,0 +1,18 @@ | |||
| # This DAG consists of a single BashOperator that prints the result of a coin flip. | |||
Contributor
There was a problem hiding this comment.
We required Apache 2 license headers per http://go/releasing/preparing#headers
|
|
||
| from airflow import DAG | ||
| from airflow.operators.bash_operator import BashOperator | ||
| from datetime import datetime, timedelta |
Contributor
There was a problem hiding this comment.
Nit: Import modules not classes/functions.
Also, the order of imports should be: (1) built-ins (2) third-party (3) local packages
| from airflow import DAG | ||
| from airflow.operators.bash_operator import BashOperator | ||
| from datetime import datetime, timedelta | ||
| from dependencies import coin_package |
Contributor
There was a problem hiding this comment.
Should this be a relative import instead?
| # scipy PyPI package installed. | ||
|
|
||
| import numpy as np # numpy is installed by default in Composer. | ||
| from scipy import special # scipy is not. |
Contributor
There was a problem hiding this comment.
Nit: Two spaces before comments.
| @@ -0,0 +1,16 @@ | |||
| # This custom PyPI package requires your environment to have the | |||
|
|
||
| # Returns "Heads" or "Tails" depending on a calculation | ||
| def flip_coin(): | ||
| # Returns a 2x2 randomly sampled array of values in the range [-5, 5] |
Contributor
There was a problem hiding this comment.
Nit: Indent 4 spaces in public Python samples. (Follows PEP-8 style guide.)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add an example workflow using a PyPI dependency and a custom dependency, and corresponding custom dependency.