Skip to content

Commit

Permalink
Merge pull request #1706 from buildtesters/rebuild_cache_when_root_is…
Browse files Browse the repository at this point in the history
…_specified

Rebuild buildspec cache when --root option is specified
  • Loading branch information
shahzebsiddiqui authored Feb 14, 2024
2 parents e0b3677 + 6b529e9 commit 8fa27db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
15 changes: 7 additions & 8 deletions buildtest/cli/buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def __init__(
self.row_count = row_count

# if --root is not specified we set to empty list instead of None
self.roots = roots or []
self.roots = (
roots or self.configuration.target_config["buildspecs"].get("root") or []
)

# list of buildspec directories to search for .yml files
self.paths = []
Expand All @@ -114,6 +116,10 @@ def __init__(
self.rebuild = rebuild or self.configuration.target_config["buildspecs"].get(
"rebuild"
)
# if --root is specified we set rebuild to True
if self.roots:
self.rebuild = True

self.cache = {}

self.load_paths()
Expand All @@ -137,13 +143,6 @@ def load_paths(self):
and `general_tests <https://github.com/buildtesters/buildtest/tree/devel/general_tests>`_ directory.
"""

buildspec_paths = (
self.configuration.target_config["buildspecs"].get("root") or []
)

if buildspec_paths:
self.roots += buildspec_paths

# if no roots specified we load the default buildspec roots.
if not self.roots:
self.paths += BUILDSPEC_DEFAULT_PATH
Expand Down
2 changes: 1 addition & 1 deletion buildtest/settings/spack_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ system:
url: https://my.cdash.org/
project: buildtest
site: generic
buildname: buildtest_spack_tutorial
buildname: buildtest_spack_tutorial
34 changes: 25 additions & 9 deletions docs/gettingstarted/buildspecs_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ provided for this command.

.. command-output:: buildtest buildspec find --help

The ``buildtest buildspec find`` command will discover all buildspecs by recursively searching all `.yml` extensions.
The ``buildtest buildspec find`` command will discover all buildspecs by recursively searching all **.yml** extensions.
buildtest will validate each buildspec file with the json schema and buildtest will display all valid buildspecs in the output,
all invalid buildspecs will be stored in a file for post-processing.

Expand Down Expand Up @@ -92,9 +92,25 @@ or pass them via command line.
buildtest will search buildspecs in :ref:`buildspecs root <buildspec_roots>` defined in your configuration,
which is a list of directory paths to search for buildspecs.
If you want to load buildspecs from a directory path, you can specify a directory
via ``--root`` option in the format: ``buildtest buildspec find --root <path> --rebuild``.
buildtest will load all valid buildspecs into cache and ignore
the rest. It's important to add ``--rebuild`` if you want to regenerate buildspec cache.
via ``--root`` option in the format: ``buildtest buildspec find --root <path>``.
buildtest will rebuild cache when `--root` option is specified. Note that to rebuild cache you typically
need to pass **--rebuild** option but that is not required when using **--root** option because we want
buildtest to load buildspecs into cache.

The **--root** option must be path to a directory, if you specify a file path then buildtest will report an error message similar
to one below

.. dropdown:: ``buildtest buildspec find --root $BUILDTEST_ROOT/README.rst``
:color: warning

.. command-output:: buildtest buildspec find --root $BUILDTEST_ROOT/README.rst
:returncode: 1

If you want to specify multiple root paths you can specify the **--root** options multiple times.

Let's rebuild the cache again by running ``buildtest buildspec find`` which will load the default buildspecs into the cache

.. command-output:: buildtest buildspec find --rebuild --quiet

Filtering buildspec
~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -138,7 +154,7 @@ We can filter output of buildspec cache by buildspec using ``--filter buildspec=
expects a path to buildspec file. The buildspec must be in the cache and file path must exist in order to
fetch the result. The path can be absolute or relative path.

In this next example, we will filter cache by file `tutorials/test_status/pass_returncode.yml` and use ``--format name,buildspec``
In this next example, we will filter cache by file ``tutorials/test_status/pass_returncode.yml`` and use ``--format name,buildspec``
to format columns. The ``--format buildspec`` will show full path to buildspec and ``name`` refers to name of test.
For more details on **--format** see :ref:`format_buildspec`.

Expand Down Expand Up @@ -249,10 +265,10 @@ report a list of invalid buildspecs as shown below
If you want to see error messages for each buildspec you can pass the ``-e`` or ``--error`` option which will display output of
each buildspec followed by error message.

.. dropdown:: ``buildtest buildspec find -e``
.. dropdown:: ``buildtest buildspec find invalid --error``
:color: warning

.. command-output:: buildtest buildspec find invalid -e
.. command-output:: buildtest buildspec find invalid --error
:returncode: 1

.. _buildspec_maintainers:
Expand Down Expand Up @@ -282,15 +298,15 @@ If you prefer a machine readable format, then you can use ``--terse`` and ``--no

.. command-output:: buildtest buildspec maintainers --terse --no-header

If you want to see a breakdown of all buildspecs by maintainers you can use `--breakdown` which will
If you want to see a breakdown of all buildspecs by maintainers you can use ``--breakdown`` which will
display the following information

.. dropdown:: ``buildtest buildspec maintainers --breakdown``

.. command-output:: buildtest buildspec maintainers --breakdown

The ``buildtest buildspec maintainers find`` command can be used to report buildspec given a maintainer
name which works similar to `--breakdown` but doesn't report information for all maintainers. Shown
name which works similar to ``--breakdown`` but doesn't report information for all maintainers. Shown
below, we query all buildspecs by maintainer **@shahzebsiddiqui**

.. dropdown:: ``buildtest buildspec maintainers find @shahzebsiddiqui``
Expand Down
21 changes: 11 additions & 10 deletions tests/cli/test_buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,17 @@ def test_buildspec_find_roots():
os.path.join(BUILDTEST_ROOT, "tutorials"),
]
# buildtest buildspec find --root $BUILDTEST_ROOT/tests/buildsystem --root $BUILDTEST_ROOT/tutorials
BuildspecCache(roots=root_buildspecs, configuration=configuration)

# buildtest buildspec find --root $BUILDTEST_ROOT/README.rst --root $BUILDTEST_ROOT/environment.yml
BuildspecCache(
roots=[
os.path.join(BUILDTEST_ROOT, "README.rst"),
os.path.join(BUILDTEST_ROOT, "tutorials", "environment.yml"),
],
configuration=configuration,
)
BuildspecCache(roots=root_buildspecs, configuration=configuration, rebuild=False)

with pytest.raises(BuildTestError):
# buildtest buildspec find --root $BUILDTEST_ROOT/README.rst --root $BUILDTEST_ROOT/environment.yml
BuildspecCache(
roots=[
os.path.join(BUILDTEST_ROOT, "README.rst"),
os.path.join(BUILDTEST_ROOT, "tutorials", "environment.yml"),
],
configuration=configuration,
)


@pytest.mark.cli
Expand Down

0 comments on commit 8fa27db

Please sign in to comment.