Skip to content

Conversation

@cjqian
Copy link

@cjqian cjqian commented Jul 17, 2018

Add an example workflow using a PyPI dependency and a custom dependency, and corresponding custom dependency.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 17, 2018
@tswast tswast self-requested a review July 19, 2018 19:15
@tswast tswast self-assigned this Jul 19, 2018
@tswast tswast added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jul 19, 2018
Updates sample to use relative imports.

Adds license headers.

Uses 4 spaces for indentation.
Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I had some nits, but I fixed them in 99b2401

As we discussed, I've moved to using relative imports since I think that will be more future-proof for Python 3.

@@ -0,0 +1,11 @@
# Python dependencies example

In this example DAG (`dag.py`), we need to use two Python packages:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Two spaces before comments.

@@ -0,0 +1,16 @@
# This custom PyPI package requires your environment to have the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header.


# Returns "Heads" or "Tails" depending on a calculation
def flip_coin():
# Returns a 2x2 randomly sampled array of values in the range [-5, 5]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Indent 4 spaces in public Python samples. (Follows PEP-8 style guide.)

@tswast tswast merged commit 230b566 into GoogleCloudPlatform:master Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. kokoro:run Add this label to force Kokoro to re-run the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants