Skip to content

Commit 34ad323

Browse files
authored
Merge branch 'main' into csb/up-2.24.0
2 parents 007731d + 29e160e commit 34ad323

File tree

9 files changed

+322
-618
lines changed

9 files changed

+322
-618
lines changed

.github/workflows/pants.yaml

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

4-
# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to set up your CI with Pants.
4+
# See https://www.pantsbuild.org/stable/docs/using-pants/using-pants-in-ci for tips on how to set up your CI with Pants.
55

66
name: Pants
77

@@ -23,15 +23,17 @@ jobs:
2323
matrix:
2424
python-version: [3.9]
2525
steps:
26-
- uses: actions/checkout@v3
27-
- uses: pantsbuild/actions/init-pants@v2
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
- uses: pantsbuild/actions/init-pants@v8
2831
# This action bootstraps pants and manages 2-3 GHA caches.
2932
# See: github.com/pantsbuild/actions/tree/main/init-pants/
3033
with:
31-
pants-python-version: ${{ matrix.python-version }}
32-
# cache0 makes it easy to bust the cache if needed
34+
# v0 makes it easy to bust the cache if needed
3335
# just increase the integer to start with a fresh cache
34-
gha-cache-key: cache0-py${{ matrix.python-version }}
36+
gha-cache-key: v0
3537
# The Python backend uses named_caches for Pip/PEX state,
3638
# so it is appropriate to invalidate on lockfile changes.
3739
named-caches-hash: ${{ hashFiles('python-default.lock') }}
@@ -43,25 +45,25 @@ jobs:
4345
# Note that named_caches and lmdb_store falls back to partial restore keys which
4446
# may give a useful partial result that will save time over completely clean state,
4547
# but will cause the cache entry to grow without bound over time.
46-
# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up.
48+
# See https://www.pantsbuild.org/stable/docs/using-pants/using-pants-in-ci for tips on how to periodically clean it up.
4749
# Alternatively you change gha-cache-key to ignore old caches.
4850
- name: Check BUILD files
49-
run: |
50-
./pants tailor --check update-build-files --check ::
51+
run: |
52+
pants tailor --check update-build-files --check ::
5153
- name: Lint and typecheck
52-
run: |
53-
./pants lint check ::
54+
run: |
55+
pants lint check ::
5456
- name: Test
5557
run: |
56-
./pants test ::
58+
pants test ::
5759
- name: Package / Run
5860
run: |
5961
# We also smoke test that our release process will work by running `package`.
60-
./pants package ::
61-
./pants run helloworld/main.py
62+
pants package ::
63+
pants run helloworld/:pex_binary
6264
- name: Upload pants log
63-
uses: actions/upload-artifact@v3
65+
uses: actions/upload-artifact@v4
6466
with:
6567
name: pants-log
66-
path: .pants.d/pants.log
68+
path: .pants.d/workdir/pants.log
6769
if: always() # We want the log even on failures.

README.md

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@ An example repository to demonstrate Python support in Pants.
33

44
See [pantsbuild.org](https://www.pantsbuild.org/docs) for much more detailed documentation.
55

6-
This is only one possible way of laying out your project with Pants. See
6+
This is only one possible way of laying out your project with Pants. See
77
[pantsbuild.org/docs/source-roots#examples](https://www.pantsbuild.org/docs/source-roots#examples) for some other
88
example layouts.
99

1010
# Running Pants
1111

12-
You run Pants goals using the `./pants` wrapper script, which will bootstrap the
13-
configured version of Pants if necessary.
12+
You run Pants goals using the `pants` launcher binary, which will bootstrap the
13+
version of Pants configured for this repo if necessary.
1414

15-
> :question: Running with Apple Silicon and/or MacOS? You will want to make changes to the `search_path` and
16-
`interpreter_constraints` values in `pants.toml` before running `./pants` - there is guidance in `pants.toml`
15+
See [here](https://www.pantsbuild.org/docs/installation) for how to install the `pants` binary.
16+
17+
> :question: Running with Apple Silicon and/or macOS? You will want to make changes to the `search_path` and
18+
`interpreter_constraints` values in `pants.toml` before running `pants` - there is guidance in `pants.toml`
1719
for those settings.
1820

19-
Use `./pants --version` to see the version of Pants configured for the repo (which you can also find
21+
Use `pants --version` to see the version of Pants configured for the repo (which you can also find
2022
in `pants.toml`).
2123

2224
# Goals
2325

2426
Pants commands are called _goals_. You can get a list of goals with
2527

2628
```
27-
./pants help goals
29+
pants help goals
2830
```
2931

3032
# Targets
3133

32-
Targets are a way of setting metadata for some part of your code, such as timeouts for tests and
33-
entry points for binaries. Targets have types like `python_source`, `resources`, and
34+
Targets are a way of setting metadata for some part of your code, such as timeouts for tests and
35+
entry points for binaries. Targets have types like `python_source`, `resources`, and
3436
`pex_binary`. They are defined in `BUILD` files.
3537

3638
Pants goals can be invoked on targets or directly on source files (which is often more intuitive and convenient).
@@ -41,52 +43,52 @@ In the latter case, Pants locates target metadata for the source files as needed
4143
Invoking goals on files is straightforward, e.g.,
4244

4345
```
44-
./pants test helloworld/greet/greeting_test.py
46+
pants test helloworld/greet/greeting_test.py
4547
```
4648

4749
You can use globs:
4850

4951
```
50-
./pants lint helloworld/greet/*.py
52+
pants lint helloworld/greet/*.py
5153
```
5254

5355
But note that these will be expanded by your shell, so this is equivalent to having used
5456

5557
```
56-
./pants lint helloworld/greet/__init__.py helloworld/greet/greeting.py helloworld/greet/greeting_test.py
58+
pants lint helloworld/greet/__init__.py helloworld/greet/greeting.py helloworld/greet/greeting_test.py
5759
```
5860

5961
If you want Pants itself to expand the globs (which is sometimes necessary), you must quote them in the shell:
6062

6163
```
62-
./pants lint 'helloworld/greet/*.py'
64+
pants lint 'helloworld/greet/*.py'
6365
```
6466

6567
You can run on all changed files:
6668

6769
```
68-
./pants --changed-since=HEAD lint
70+
pants --changed-since=HEAD lint
6971
```
7072

71-
You can run on all changed files, and any of their "dependees":
73+
You can run on all changed files, and any of their "dependents":
7274

7375
```
74-
./pants --changed-since=HEAD --changed-dependees=transitive test
76+
pants --changed-since=HEAD --changed-dependents=transitive test
7577
```
7678

7779
## Target specifications
7880

7981
Targets are referenced on the command line using their address, of the form `path/to/dir:name`, e.g.,
8082

8183
```
82-
./pants lint helloworld/greet:lib
84+
pants lint helloworld/greet:lib
8385
```
8486

8587
You can glob over all targets in a directory with a single trailing `:`, or over all targets in a directory
8688
and all its subdirectories with a double trailing `::`, e.g.,
8789

8890
```
89-
./pants lint helloworld::
91+
pants lint helloworld::
9092
```
9193

9294
## Globbing semantics
@@ -96,7 +98,7 @@ For example, if you run the `test` goal over a set of files that includes non-te
9698
those, rather than error. So you can safely do things like
9799

98100
```
99-
./pants test ::
101+
pants test ::
100102
```
101103

102104
To run all tests.
@@ -108,67 +110,79 @@ Try these out in this repo!
108110
## List targets
109111

110112
```
111-
./pants list :: # All targets.
112-
./pants list 'helloworld/**/*.py' # Just targets containing Python code.
113+
pants list :: # All targets.
114+
pants list 'helloworld/**/*.py' # Just targets containing Python code.
113115
```
114116

115117
## Run linters and formatters
116118

117119
```
118-
./pants lint ::
119-
./pants fmt helloworld/greet::
120+
pants lint ::
121+
pants fmt helloworld/greet::
120122
```
121123

122124
## Run MyPy
123125

124126
```
125-
./pants check ::
127+
pants check ::
126128
```
127129

128130
## Run tests
129131

130132
```
131-
./pants test :: # Run all tests in the repo.
132-
./pants test --output=all :: # Run all tests in the repo and view pytest output even for tests that passed (you can set this permanently in pants.toml).
133-
./pants test helloworld/translator:tests # Run all the tests in this target.
134-
./pants test helloworld/translator/translator_test.py # Run just the tests in this file.
135-
./pants test helloworld/translator/translator_test.py -- -k test_unknown_phrase # Run just this one test by passing through pytest args.
133+
pants test :: # Run all tests in the repo.
134+
pants test --output=all :: # Run all tests in the repo and view pytest output even for tests that passed (you can set this permanently in pants.toml).
135+
pants test helloworld/translator:tests # Run all the tests in this target.
136+
pants test helloworld/translator/translator_test.py # Run just the tests in this file.
137+
pants test helloworld/translator/translator_test.py -- -k test_unknown_phrase # Run just this one test by passing through pytest args.
136138
```
137139

138140
## Create a PEX binary
139141

142+
The `package` goal requires specifying a target which can be packaged. In this case, the there is a `pex_binary` target with the name `pex_binary` in the `helloworld/BUILD` file.
143+
140144
```
141-
./pants package helloworld/main.py
145+
pants package helloworld:pex_binary
142146
```
143147

148+
The pex file is output to `dist/helloworld/pex_binary.pex` and can be executed directly.
149+
144150
## Run a binary directly
145151

146152
```
147-
./pants run helloworld/main.py
153+
pants run helloworld/main.py
148154
```
149155

150156
## Open a REPL
151157

152158
```
153-
./pants repl helloworld/greet:lib # The REPL will have all relevant code and dependencies on its sys.path.
154-
./pants repl --shell=ipython helloworld/greet:lib --no-pantsd # To use IPython, you must disable Pantsd for now.
159+
pants repl helloworld/greet:lib # The REPL will have all relevant code and dependencies on its sys.path.
160+
pants repl --shell=ipython helloworld/greet:lib --no-pantsd # To use IPython, you must disable Pantsd for now.
155161
```
156162

157163
## Build a wheel / generate `setup.py`
158164

159165
This will build both a `.whl` bdist and a `.tar.gz` sdist.
160166

161167
```
162-
./pants package helloworld/translator:dist
168+
pants package helloworld/translator:dist
163169
```
164170

165171
## Count lines of code
166172

167173
```
168-
./pants count-loc '**/*'
174+
pants count-loc '**/*'
169175
```
176+
177+
## Generate or update a lockfile containing the dependencies
178+
179+
```
180+
pants generate-lockfiles --resolve=python-default
181+
```
182+
183+
170184
## Create virtualenv for IDE integration
171185

172186
```
173-
./pants export ::
187+
pants export --resolve=python-default
174188
```

0 commit comments

Comments
 (0)