Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@
# python_requirement('translate>=3.2.1')
# ]
# )
#
# Refer to https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies.

python_requirements()
python_requirements(
# `setuptools` exposes a module different than the project name. We teach this to Pants so that
# it can correctly infer dependencies.
module_mapping={
"setuptools": ["pkg_resources"],
},
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ Try these out in this repo!
## Count lines of code

```
./pants cloc '**/*'
./pants count-loc '**/*'
```
46 changes: 17 additions & 29 deletions helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,37 @@

python_binary(
# name defaults to the name of this directory, i.e., `helloworld`.
sources = ["main.py"],
entry_point = "helloworld.main",
dependencies = [
":config",
"//:ansicolors",
"helloworld/greet",
],
sources=["main.py"],
entry_point="helloworld.main",
)

# Note: Has sdist dependencies, so must be built on Linux.
python_awslambda(
name='helloworld-awslambda',
sources = ["awslambda.py"],
dependencies=[
":config",
"helloworld/greet",
],
handler='helloworld.awslambda:handler',
runtime='python3.7',
name="helloworld-awslambda",
sources=["awslambda.py"],
handler="helloworld.awslambda:handler",
runtime="python3.7",
)

python_binary(
name = "helloworld_py2",
sources = ["main_py2.py"],
entry_point = "helloworld.main_py2",
compatibility = ">=2.7,<3",
dependencies = [
"//:ansicolors",
"helloworld/greet_py2",
],
name="helloworld_py2",
sources=["main_py2.py"],
entry_point="helloworld.main_py2",
compatibility=">=2.7,<3",
)

python_library(
name = "config",
sources = ["config.py"],
dependencies = [
name="config",
sources=["config.py"],
dependencies=[
# Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly
# add them.
":config_file",
"helloworld/util",
"helloworld/util/proto",
],
)

resources(
name = "config_file",
sources = ["config.json"],
name="config_file",
sources=["config.json"],
)
22 changes: 7 additions & 15 deletions helloworld/greet/BUILD
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# Copyright 2020 Pants project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_library(
# `name` defaults to the name of this directory, i.e., `greet`.
# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py'].
dependencies = [
"//:translate",
"helloworld/util",
],
)
# `name` defaults to the name of this directory, i.e., `greet`.
# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py'].
# `dependencies` are inferred.
python_library()

python_tests(
name = 'tests',
# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py'].
dependencies = [
":greet",
]
)
# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py'].
# `dependencies` are inferred.
python_tests(name = 'tests')
16 changes: 8 additions & 8 deletions helloworld/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# See https://www.pantsbuild.org/docs/python-setup-py-goal.
python_distribution(
name="dist",
# Because this has no source code, Pants cannot infer dependencies.
dependencies=[":util"],
provides=setup_py(
name='helloworld.util',
Expand All @@ -12,22 +13,21 @@ python_distribution(
),
)

# `name` defaults to the name of this directory, i.e., `util`.
# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py'].
python_library(
# `name` defaults to the name of this directory, i.e., `util`.
# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py'].
dependencies=[
"//:setuptools",
"//:translate",
"helloworld/util/proto",
],
# Pants cannot infer dependencies on Protobuf, so we explicitly add it.
dependencies=[
"helloworld/util/proto",
],
)

python_tests(
name='tests',
# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py'].
# Pants cannot infer dependencies on `resources` targets, so we explicitly add it.
dependencies=[
":config_loader_test_data",
":util",
],
)

Expand Down
5 changes: 1 addition & 4 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ root_patterns = ["/"]
env_vars = ["LANG", "LC_ALL"]

[python-setup]
# The default interpreter compatibility for code in this repo. Individual targets can ovverride
# The default interpreter compatibility for code in this repo. Individual targets can override
# this with the `compatibility` field. See
# https://www.pantsbuild.org/docs/python-interpreter-compatibility.
interpreter_constraints = [">=3.7"]
Expand All @@ -42,6 +42,3 @@ config = ".flake8"

[isort]
config = [".isort.cfg"]

[python-infer]
imports = false