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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ script:
# We also smoke test that our release process will work by running `package`.
- ./pants lint typecheck test package '::'
- ./pants run helloworld/main.py
- ./pants run helloworld/main_py2.py
14 changes: 7 additions & 7 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
# with the name of the corresponding dist.
#
# For example, `translate>=3.2.1` expands to:
#
# python_requirement_library(
# name='translate',
# requirements=[
# python_requirement('translate>=3.2.1')
# ]
# requirements=['translate>=3.2.1']
# )
#
# Refer to https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies.

# We set `module_mapping` for any requirements whose module names differ from the project's name so that dependency
# inference works.
#
# Refer to https://www.pantsbuild.org/docs/python-third-party-dependencies.
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={
"ansicolors": ["colors"],
"setuptools": ["pkg_resources"],
},
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Try these out in this repo!
## Create a PEX binary

```
./pants package helloworld/main.py helloworld/main_py2.py
./pants package helloworld/main.py
```

## Run a binary
Expand Down
7 changes: 0 additions & 7 deletions build-support/generate_constraints.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,3 @@ CONSTRAINTS_FILE=constraints.txt
"${PIP}" install -r <(./pants dependencies --type=3rdparty ::)
echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}"
"${PIP}" freeze --all >> "${CONSTRAINTS_FILE}"

# This example repo includes some Python 2-only code for demonstration. Because we generated
# the constraints using Python 3.7, we must manually ensure things still work with Python 2.7. So,
# we warn to the user that they should check the diff. You can delete this if you don't use Python 2.
echo "Check the diff for ${CONSTRAINTS_FILE} and restore any entries that were specific to" \
"Python 2, i.e. entries ending in \`python_version == '2.7'\`. Those are needed for Python 2 to" \
"work properly, and this script will overwrite it." 1>&2
20 changes: 8 additions & 12 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
# Generated by build-support/generate_constraints.sh on Wed Sep 16 11:30:54 MST 2020
# Generated by build-support/generate_constraints.sh on Tue Nov 24 13:57:41 MST 2020
ansicolors==1.1.8
appdirs==1.4.4
certifi==2020.6.20
cfgv==2.0.1 ; python_version == '2.7'
cfgv==3.1.0 ; python_version > '2.7'
cfgv==3.2.0
chardet==3.0.4
click==7.1.2
distlib==0.3.1
filelock==3.0.12
identify==1.5.2
identify==1.5.5
idna==2.10
importlib-metadata==1.7.0
importlib-resources==3.0.0
lxml==4.5.2
nodeenv==1.5.0
packaging==20.4
pip==20.2.3
pip==20.2.4
pluggy==0.13.1
pre-commit==1.21.0 ; python_version == '2.7'
pre-commit==2.7.1 ; python_version > '2.7'
pre-commit==2.7.1
protobuf==3.13.0
py==1.9.0
pyparsing==2.4.7
PyYAML==5.3.1
requests==2.24.0
setuptools==44.1.1 ; python_version == '2.7'
setuptools==50.3.0 ; python_version > '2.7'
setuptools==50.3.0
six==1.15.0
toml==0.10.1
tox==3.20.0
translate==3.5.0
urllib3==1.25.10
virtualenv==20.0.31
zipp==1.2.0 ; python_version == '2.7'
zipp==3.1.0 ; python_version > '2.7'
virtualenv==20.0.33
zipp==3.3.0
17 changes: 3 additions & 14 deletions helloworld/BUILD
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Copyright 2020 Pants project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# `name` defaults to the name of this directory, i.e., `helloworld`.
pex_binary(
# name defaults to the name of this directory, i.e., `helloworld`.
sources=["main.py"],
entry_point="helloworld.main",
)

pex_binary(
name="helloworld_py2",
sources=["main_py2.py"],
entry_point="helloworld.main_py2",
interpreter_constraints=["==2.7.*"],
)

python_library(
name="awslambda_lib",
sources=["awslambda.py"],
Expand All @@ -27,15 +20,11 @@ python_awslambda(
runtime="python3.7",
)

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

resources(
Expand Down
9 changes: 0 additions & 9 deletions helloworld/greet_py2/BUILD

This file was deleted.

Empty file removed helloworld/greet_py2/__init__.py
Empty file.
7 changes: 0 additions & 7 deletions helloworld/greet_py2/greeting_py2.py

This file was deleted.

14 changes: 0 additions & 14 deletions helloworld/main_py2.py

This file was deleted.

44 changes: 20 additions & 24 deletions helloworld/util/BUILD
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
# Copyright 2020 Pants project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# 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"],
setup_py_commands=["bdist_wheel", "sdist"],
provides=setup_py(
name='helloworld.util',
version='0.0.1',
description='Greeting library utilities.',
),
)

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

# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py'].
# Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep.
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",
],
dependencies=[":test_data"],
)

resources(
name='config_loader_test_data',
sources=['config_loader_test_data.json'],
name='test_data',
sources=['*_test_data.json'],
)

# See https://www.pantsbuild.org/docs/python-distributions.
# Because this target has no source code, Pants cannot infer dependencies.
python_distribution(
name="dist",
dependencies=[":util"],
setup_py_commands=["bdist_wheel", "sdist"],
provides=setup_py(
name='helloworld.util',
version='0.0.1',
description='Greeting library utilities.',
),
)
15 changes: 5 additions & 10 deletions helloworld/util/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

# `name` defaults to the name of this directory, i.e., `proto`.
# `sources` defaults to ["*.proto"].
protobuf_library(dependencies=[":init"])
protobuf_library()


# Note that we need an `__init__.py` file for MyPy to recognize our generated code as a valid
# module. We include this in the dependencies for the `protobuf_library` to ensure the
# `__init__.py` is always used.
#
# Often, you won't want to put `__init__.py` files in your Protobuf directories; see
# https://www.pantsbuild.org/docs/protobuf#protobuf-and-source-roots for how to change where the
# protobuf code is generated.
python_library(name="init")
# Note that we have an empty `__init__.py` file in this folder. Pants will generate
# `helloworld/util/proto/config_pb2.py`, and we need an `__init__.py` file in the folder for that file to be properly
# recognized. Pants will automatically use this `__init__.py` file if it exists, even though we don't have a
# `python_library` target here.
3 changes: 0 additions & 3 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ backend_packages.add = [
"pants.backend.python.lint.flake8",
"pants.backend.python.lint.isort",
"pants.backend.python.typecheck.mypy",
# Adds the `py-constraints` goal, as this example repository has
# both Python 2 and Python 3 code.
"pants.backend.python.mixed_interpreter_constraints",
]

[source]
Expand Down