Skip to content

Commit 2b4c66b

Browse files
Remove Protobuf and AWS Lambda from example (#84)
We got feedback in Slack that these two backends were making the example too complex. > I could not use that repo as a template because of the aws and protobuf stuff. ie do you want the repo to be a reusable template? or a fully baked example? We would rather have the example repo be very easy to get started than to show every bell and whistle of Pants. Our docs are for the niche features like AWS Lambdas. Our example repo is to allow you to very easily try out Pants to get a feel for it before committing to prototyping in your own repo.
1 parent 48256bd commit 2b4c66b

16 files changed

Lines changed: 30 additions & 114 deletions

BUILD

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

4-
5-
# A macro that turns every entry in this directory's requirements.txt into a target
6-
# with the name of the corresponding dist.
7-
#
8-
# For example, `translate>=3.2.1` expands to:
9-
#
10-
# python_requirement_library(
11-
# name='translate',
12-
# requirements=['translate>=3.2.1']
13-
# )
14-
#
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.
19-
python_requirements(
20-
module_mapping={
21-
"ansicolors": ["colors"],
22-
"setuptools": ["pkg_resources"],
23-
},
24-
)
4+
# A macro that turns every entry in this directory's requirements.txt into a
5+
# `python_requirement_library` target. Refer to
6+
# https://www.pantsbuild.org/docs/python-third-party-dependencies.
7+
python_requirements()

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@ This will build both a `.whl` bdist and a `.tar.gz` sdist.
171171
We can also remove the `setup_py_commands` field from `helloworld/util/BUILD` to have Pants instead generate a
172172
`setup.py` file, with all the relevant code in a chroot.
173173

174-
## Build an AWS Lambda
175-
176-
(This example only works on Linux because it has an sdist. See https://www.pantsbuild.org/docs/awslambda-python.)
177-
178-
```
179-
./pants package helloworld/awslambda.py
180-
```
181-
182174
## Count lines of code
183175

184176
```

constraints.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ importlib-metadata==4.6.3
88
libretranslatepy==2.1.1
99
lxml==4.6.3
1010
pip==21.2.2
11-
protobuf==3.17.3
1211
requests==2.26.0
1312
setuptools==56.2.0
1413
six==1.16.0
1514
translate==3.6.1
1615
types-futures==0.1.6
17-
types-protobuf==3.17.4
1816
types-setuptools==57.0.0
1917
typing-extensions==3.10.0.0
2018
urllib3==1.26.6

helloworld/BUILD

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,3 @@ pex_binary(
2424
name="pex_binary",
2525
entry_point="main.py",
2626
)
27-
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",
36-
)

helloworld/awslambda.py

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

helloworld/config.py

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

helloworld/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33

44
from colors import green
55

6-
from helloworld.config import load_config
76
from helloworld.greet.greeting import Greeter
7+
from helloworld.util.config import Config
88

99

1010
def say_hello() -> None:
11-
config = load_config()
12-
greeter = Greeter(
13-
languages=list(config.languages), greetings=list(config.greetings)
14-
)
11+
config = Config.load_from_json_resource(__name__, "config.json")
12+
greeter = Greeter(languages=config.languages, greetings=config.greetings)
1513
sentence = greeter.greet("world")
1614
print(green(sentence))
1715

helloworld/util/config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2020 Pants project contributors.
2+
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3+
4+
from __future__ import annotations
5+
6+
import json
7+
from dataclasses import dataclass
8+
9+
import pkg_resources
10+
11+
12+
@dataclass
13+
class Config:
14+
languages: list[str]
15+
greetings: list[str]
16+
17+
@classmethod
18+
def load_from_json_resource(cls, pkg_name: str, resource_name: str) -> Config:
19+
resource_content = pkg_resources.resource_string(pkg_name, resource_name)
20+
parsed = json.loads(resource_content)
21+
return cls(languages=parsed["languages"], greetings=parsed["greetings"])

helloworld/util/config_loader.py

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

4-
from helloworld.util.config_loader import load_config_from_json
4+
from helloworld.util.config import Config
55

66

77
def test_load_config_from_json() -> None:
8-
config = load_config_from_json(__name__, "config_loader_test_data.json")
8+
config = Config.load_from_json_resource(__name__, "config_test_data.json")
99
assert config.languages == ["af", "zh"]
1010
assert config.greetings == ["hi", "hey"]

0 commit comments

Comments
 (0)