|
1 | 1 | # Copyright 2020 Pants project contributors. |
2 | 2 | # Licensed under the Apache License, Version 2.0 (see LICENSE). |
3 | 3 |
|
4 | | -# `name` defaults to the name of this directory, i.e., `helloworld`. |
5 | | -pex_binary( |
6 | | - sources=["main.py"], |
7 | | - entry_point="helloworld.main", |
8 | | -) |
9 | | - |
| 4 | +# This target sets the metadata for all the Python non-test files in this directory. |
| 5 | +# |
| 6 | +# * `name` defaults to the name of this directory, i.e., `helloworld`. |
| 7 | +# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. |
| 8 | +# * Pants cannot infer dependencies on resources targets, so we explicitly add it. |
10 | 9 | python_library( |
11 | | - name="awslambda_lib", |
12 | | - sources=["awslambda.py"], |
| 10 | + dependencies=[":config_file"], |
13 | 11 | ) |
14 | 12 |
|
15 | | -# Note: This has sdist dependencies, so it must be built on Linux. |
16 | | -python_awslambda( |
17 | | - name="helloworld-awslambda", |
18 | | - dependencies=[":awslambda_lib"], |
19 | | - handler="helloworld.awslambda:handler", |
20 | | - runtime="python3.7", |
| 13 | +# This target teaches Pants about our JSON file, which allows for other targets to depend on it. |
| 14 | +resources( |
| 15 | + name="config_file", |
| 16 | + sources=["config.json"], |
21 | 17 | ) |
22 | 18 |
|
23 | | -# Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly add them. |
24 | | -python_library( |
25 | | - name="config", |
26 | | - sources=["config.py"], |
27 | | - dependencies=[":config_file", "helloworld/util/proto"], |
| 19 | +# This target allows us to bundle our app into a PEX binary file via |
| 20 | +# `./pants package`. We can also run it with `./pants run`. See |
| 21 | +# https://www.pantsbuild.org/docs/python-package-goal and |
| 22 | +# https://www.pantsbuild.org/docs/python-run-goal. |
| 23 | +pex_binary( |
| 24 | + name="pex_binary", |
| 25 | + entry_point="main.py", |
28 | 26 | ) |
29 | 27 |
|
30 | | -resources( |
31 | | - name="config_file", |
32 | | - sources=["config.json"], |
| 28 | +# This target allows us to create an AWS Lambda binary via `./pants package`. |
| 29 | +# See https://www.pantsbuild.org/docs/awslambda-python. |
| 30 | +# |
| 31 | +# Note: This has sdist dependencies, so it must be built on Linux. |
| 32 | +python_awslambda( |
| 33 | + name="awslambda", |
| 34 | + handler="awslambda.py:handler", |
| 35 | + runtime="python3.7", |
33 | 36 | ) |
0 commit comments