Skip to content

Commit 2a6f66c

Browse files
Remove Python 2 (pantsbuild#56)
Demonstrating Python 2 is no longer pulling its weight. Python 2 interpreters are becoming harder to come by, and there are some issues with it like PyYAML failing to be built on macOS Big Sur when using a Python 2 interpreter. Instead, we might want a dedicated example repo for Python 2 -> 3 repos. It can be more focused, such as not showing off Protobuf.
1 parent 5bcef28 commit 2a6f66c

13 files changed

Lines changed: 44 additions & 109 deletions

File tree

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ script:
2424
# We also smoke test that our release process will work by running `package`.
2525
- ./pants lint typecheck test package '::'
2626
- ./pants run helloworld/main.py
27-
- ./pants run helloworld/main_py2.py

BUILD

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
# with the name of the corresponding dist.
77
#
88
# For example, `translate>=3.2.1` expands to:
9+
#
910
# python_requirement_library(
1011
# name='translate',
11-
# requirements=[
12-
# python_requirement('translate>=3.2.1')
13-
# ]
12+
# requirements=['translate>=3.2.1']
1413
# )
1514
#
16-
# Refer to https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies.
17-
15+
# We set `module_mapping` for any requirements whose module names differ from the project's name so that dependency
16+
# inference works.
17+
#
18+
# Refer to https://www.pantsbuild.org/docs/python-third-party-dependencies.
1819
python_requirements(
19-
# `setuptools` exposes a module different than the project name. We teach this to Pants so that
20-
# it can correctly infer dependencies.
2120
module_mapping={
21+
"ansicolors": ["colors"],
2222
"setuptools": ["pkg_resources"],
2323
},
2424
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Try these out in this repo!
144144
## Create a PEX binary
145145

146146
```
147-
./pants package helloworld/main.py helloworld/main_py2.py
147+
./pants package helloworld/main.py
148148
```
149149

150150
## Run a binary

build-support/generate_constraints.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,3 @@ CONSTRAINTS_FILE=constraints.txt
1616
"${PIP}" install -r <(./pants dependencies --type=3rdparty ::)
1717
echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}"
1818
"${PIP}" freeze --all >> "${CONSTRAINTS_FILE}"
19-
20-
# This example repo includes some Python 2-only code for demonstration. Because we generated
21-
# the constraints using Python 3.7, we must manually ensure things still work with Python 2.7. So,
22-
# we warn to the user that they should check the diff. You can delete this if you don't use Python 2.
23-
echo "Check the diff for ${CONSTRAINTS_FILE} and restore any entries that were specific to" \
24-
"Python 2, i.e. entries ending in \`python_version == '2.7'\`. Those are needed for Python 2 to" \
25-
"work properly, and this script will overwrite it." 1>&2

constraints.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
1-
# Generated by build-support/generate_constraints.sh on Wed Sep 16 11:30:54 MST 2020
1+
# Generated by build-support/generate_constraints.sh on Tue Nov 24 13:57:41 MST 2020
22
ansicolors==1.1.8
33
appdirs==1.4.4
44
certifi==2020.6.20
5-
cfgv==2.0.1 ; python_version == '2.7'
6-
cfgv==3.1.0 ; python_version > '2.7'
5+
cfgv==3.2.0
76
chardet==3.0.4
87
click==7.1.2
98
distlib==0.3.1
109
filelock==3.0.12
11-
identify==1.5.2
10+
identify==1.5.5
1211
idna==2.10
1312
importlib-metadata==1.7.0
1413
importlib-resources==3.0.0
1514
lxml==4.5.2
1615
nodeenv==1.5.0
1716
packaging==20.4
18-
pip==20.2.3
17+
pip==20.2.4
1918
pluggy==0.13.1
20-
pre-commit==1.21.0 ; python_version == '2.7'
21-
pre-commit==2.7.1 ; python_version > '2.7'
19+
pre-commit==2.7.1
2220
protobuf==3.13.0
2321
py==1.9.0
2422
pyparsing==2.4.7
2523
PyYAML==5.3.1
2624
requests==2.24.0
27-
setuptools==44.1.1 ; python_version == '2.7'
28-
setuptools==50.3.0 ; python_version > '2.7'
25+
setuptools==50.3.0
2926
six==1.15.0
3027
toml==0.10.1
3128
tox==3.20.0
3229
translate==3.5.0
3330
urllib3==1.25.10
34-
virtualenv==20.0.31
35-
zipp==1.2.0 ; python_version == '2.7'
36-
zipp==3.1.0 ; python_version > '2.7'
31+
virtualenv==20.0.33
32+
zipp==3.3.0

helloworld/BUILD

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
# Copyright 2020 Pants project contributors.
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4+
# `name` defaults to the name of this directory, i.e., `helloworld`.
45
pex_binary(
5-
# name defaults to the name of this directory, i.e., `helloworld`.
66
sources=["main.py"],
77
entry_point="helloworld.main",
88
)
99

10-
pex_binary(
11-
name="helloworld_py2",
12-
sources=["main_py2.py"],
13-
entry_point="helloworld.main_py2",
14-
interpreter_constraints=["==2.7.*"],
15-
)
16-
1710
python_library(
1811
name="awslambda_lib",
1912
sources=["awslambda.py"],
@@ -27,15 +20,11 @@ python_awslambda(
2720
runtime="python3.7",
2821
)
2922

23+
# Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly add them.
3024
python_library(
3125
name="config",
3226
sources=["config.py"],
33-
dependencies=[
34-
# Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly
35-
# add them.
36-
":config_file",
37-
"helloworld/util/proto",
38-
],
27+
dependencies=[":config_file", "helloworld/util/proto"],
3928
)
4029

4130
resources(

helloworld/greet_py2/BUILD

Lines changed: 0 additions & 9 deletions
This file was deleted.

helloworld/greet_py2/__init__.py

Whitespace-only changes.

helloworld/greet_py2/greeting_py2.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

helloworld/main_py2.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)