Skip to content

Commit 975c798

Browse files
authored
Merge pull request #5890: pants: Add st2_shell_sources_and_resources() macro to pants-plugins/macros.py
2 parents cc303a7 + 96a3c8a commit 975c798

File tree

10 files changed

+56
-4
lines changed

10 files changed

+56
-4
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Added
1616
to pants' use of PEX lockfiles. This is not a user-facing addition.
1717
#5778 #5789 #5817 #5795 #5830 #5833 #5834 #5841 #5840 #5838 #5842 #5837 #5849 #5850
1818
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5864 #5874 #5884 #5893 #5891
19+
#5890
1920
Contributed by @cognifloyd
2021

2122
* Added a joint index to solve the problem of slow mongo queries for scheduled executions. #5805

pants-plugins/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ pants_requirements(
1111
name="pants",
1212
testutil=True,
1313
)
14+
15+
python_sources()

pants-plugins/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ These StackStorm-specific plugins might be useful in other StackStorm-related re
1616

1717
These StackStorm-specific plugins are probably only useful for the st2 repo.
1818
- `api_spec`
19+
- `macros.py` (not a plugin - see pants.toml `[GLOBAL].build_file_prelude_globs`)
1920
- `release`
2021
- `sample_conf`
2122
- `schemas`
@@ -33,6 +34,16 @@ This plugin also wires up pants so that the `lint` goal runs additional
3334
api spec validation on `st2common/st2common/openapi.yaml` with something
3435
like `./pants lint st2common/st2common/openapi.yaml`.
3536

37+
### `macros.py` macros
38+
39+
[Macros](https://www.pantsbuild.org/docs/macros) are a pants feature
40+
that can reduce "boilerplate"/duplication in BUILD files. The functions
41+
defined in `macros.py` are available in all the BUILD files, and using
42+
them looks just like using the normal BUILD targets.
43+
44+
For documentation about our macros, please refer to the function docstrings
45+
in the `macros.py` file.
46+
3647
### `pack_metadata` plugin
3748

3849
This plugin adds two new targets to pants:

pants-plugins/macros.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def st2_shell_sources_and_resources(**kwargs):
17+
"""This creates a shell_sources and a resources target.
18+
19+
This is needed because python_sources dependencies on shell_sources
20+
are silently ignored. So, we also need the resources target
21+
to allow depending on them.
22+
"""
23+
shell_sources(**kwargs) # noqa: F821
24+
25+
kwargs.pop("skip_shellcheck", None)
26+
27+
kwargs["name"] += "_resources"
28+
resources(**kwargs) # noqa: F821

pants.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repo_id = "de0dea7a-9f6a-4c6e-aa20-6ba5ad969b8a"
88
[GLOBAL]
99
pants_version = "2.14.0"
1010
pythonpath = ["%(buildroot)s/pants-plugins"]
11+
build_file_prelude_globs = ["pants-plugins/macros.py"]
1112
backend_packages = [
1213
# python
1314
"pants.backend.python",

st2actions/bin/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ python_sources(
55
skip_pylint=True,
66
)
77

8-
shell_sources(
8+
st2_shell_sources_and_resources(
99
name="shell",
10+
sources=["*.sh"],
1011
skip_shellcheck=True,
1112
)

st2common/bin/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ python_sources(
55
skip_pylint=True,
66
)
77

8-
shell_sources(
8+
st2_shell_sources_and_resources(
99
name="shell",
1010
sources=["st2ctl", "st2-self-check", "st2-run-pack-tests"],
1111
skip_shellcheck=True,

st2tests/st2tests/fixtures/generic/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
pack_metadata(
22
name="metadata",
3+
dependencies=[
4+
"./actions:shell",
5+
"./actions:shell_resources",
6+
],
37
)
48

59
python_sources(
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
shell_sources()
1+
st2_shell_sources_and_resources(
2+
name="shell",
3+
sources=["*.sh"],
4+
)

st2tests/st2tests/fixtures/packs/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pack_metadata_in_git_submodule(
1313
],
1414
)
1515

16-
shell_sources(
16+
st2_shell_sources_and_resources(
1717
name="test_content_version_shell",
1818
# do not check across git submodule boundary
1919
skip_shellcheck=True,
@@ -29,6 +29,7 @@ python_sources(
2929
dependencies=[
3030
":test_content_version_metadata",
3131
":test_content_version_shell",
32+
":test_content_version_shell_resources",
3233
],
3334
sources=[
3435
"test_content_version/**/*.py",

0 commit comments

Comments
 (0)