Skip to content

Commit

Permalink
Merge pull request #5890: pants: Add `st2_shell_sources_and_resources…
Browse files Browse the repository at this point in the history
…()` macro to `pants-plugins/macros.py`
  • Loading branch information
cognifloyd committed Feb 14, 2023
2 parents cc303a7 + 96a3c8a commit 975c798
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Added
to pants' use of PEX lockfiles. This is not a user-facing addition.
#5778 #5789 #5817 #5795 #5830 #5833 #5834 #5841 #5840 #5838 #5842 #5837 #5849 #5850
#5846 #5853 #5848 #5847 #5858 #5857 #5860 #5868 #5871 #5864 #5874 #5884 #5893 #5891
#5890
Contributed by @cognifloyd

* Added a joint index to solve the problem of slow mongo queries for scheduled executions. #5805
Expand Down
2 changes: 2 additions & 0 deletions pants-plugins/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ pants_requirements(
name="pants",
testutil=True,
)

python_sources()
11 changes: 11 additions & 0 deletions pants-plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ These StackStorm-specific plugins might be useful in other StackStorm-related re

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

### `macros.py` macros

[Macros](https://www.pantsbuild.org/docs/macros) are a pants feature
that can reduce "boilerplate"/duplication in BUILD files. The functions
defined in `macros.py` are available in all the BUILD files, and using
them looks just like using the normal BUILD targets.

For documentation about our macros, please refer to the function docstrings
in the `macros.py` file.

### `pack_metadata` plugin

This plugin adds two new targets to pants:
Expand Down
28 changes: 28 additions & 0 deletions pants-plugins/macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 The StackStorm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def st2_shell_sources_and_resources(**kwargs):
"""This creates a shell_sources and a resources target.
This is needed because python_sources dependencies on shell_sources
are silently ignored. So, we also need the resources target
to allow depending on them.
"""
shell_sources(**kwargs) # noqa: F821

kwargs.pop("skip_shellcheck", None)

kwargs["name"] += "_resources"
resources(**kwargs) # noqa: F821
1 change: 1 addition & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repo_id = "de0dea7a-9f6a-4c6e-aa20-6ba5ad969b8a"
[GLOBAL]
pants_version = "2.14.0"
pythonpath = ["%(buildroot)s/pants-plugins"]
build_file_prelude_globs = ["pants-plugins/macros.py"]
backend_packages = [
# python
"pants.backend.python",
Expand Down
3 changes: 2 additions & 1 deletion st2actions/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ python_sources(
skip_pylint=True,
)

shell_sources(
st2_shell_sources_and_resources(
name="shell",
sources=["*.sh"],
skip_shellcheck=True,
)
2 changes: 1 addition & 1 deletion st2common/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python_sources(
skip_pylint=True,
)

shell_sources(
st2_shell_sources_and_resources(
name="shell",
sources=["st2ctl", "st2-self-check", "st2-run-pack-tests"],
skip_shellcheck=True,
Expand Down
4 changes: 4 additions & 0 deletions st2tests/st2tests/fixtures/generic/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pack_metadata(
name="metadata",
dependencies=[
"./actions:shell",
"./actions:shell_resources",
],
)

python_sources(
Expand Down
5 changes: 4 additions & 1 deletion st2tests/st2tests/fixtures/generic/actions/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
shell_sources()
st2_shell_sources_and_resources(
name="shell",
sources=["*.sh"],
)
3 changes: 2 additions & 1 deletion st2tests/st2tests/fixtures/packs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pack_metadata_in_git_submodule(
],
)

shell_sources(
st2_shell_sources_and_resources(
name="test_content_version_shell",
# do not check across git submodule boundary
skip_shellcheck=True,
Expand All @@ -29,6 +29,7 @@ python_sources(
dependencies=[
":test_content_version_metadata",
":test_content_version_shell",
":test_content_version_shell_resources",
],
sources=[
"test_content_version/**/*.py",
Expand Down

0 comments on commit 975c798

Please sign in to comment.