2022-01-13 03:21:41 +08:00
|
|
|
|
.. Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
|
2018-10-08 04:52:23 +08:00
|
|
|
|
Spack Project Developers. See the top-level COPYRIGHT file for details.
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
|
2016-10-06 22:45:47 +08:00
|
|
|
|
.. _contribution-guide:
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
==================
|
2016-10-06 22:45:47 +08:00
|
|
|
|
Contribution Guide
|
2016-10-15 00:16:13 +08:00
|
|
|
|
==================
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
This guide is intended for developers or administrators who want to
|
|
|
|
|
contribute a new package, feature, or bugfix to Spack.
|
|
|
|
|
It assumes that you have at least some familiarity with Git VCS and Github.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
The guide will show a few examples of contributing workflows and discuss
|
|
|
|
|
the granularity of pull-requests (PRs). It will also discuss the tests your
|
|
|
|
|
PR must pass in order to be accepted into Spack.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
First, what is a PR? Quoting `Bitbucket's tutorials <https://www.atlassian.com/git/tutorials/making-a-pull-request/>`_:
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Pull requests are a mechanism for a developer to notify team members that
|
|
|
|
|
they have **completed a feature**. The pull request is more than just a
|
|
|
|
|
notification—it’s a dedicated forum for discussing the proposed feature.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Important is **completed feature**. The changes one proposes in a PR should
|
2016-10-06 22:45:47 +08:00
|
|
|
|
correspond to one feature/bugfix/extension/etc. One can create PRs with
|
|
|
|
|
changes relevant to different ideas, however reviewing such PRs becomes tedious
|
2016-10-15 00:16:13 +08:00
|
|
|
|
and error prone. If possible, try to follow the **one-PR-one-package/feature** rule.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2020-07-04 16:50:55 +08:00
|
|
|
|
--------
|
|
|
|
|
Branches
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
Spack's ``develop`` branch has the latest contributions. Nearly all pull
|
|
|
|
|
requests should start from ``develop`` and target ``develop``.
|
|
|
|
|
|
|
|
|
|
There is a branch for each major release series. Release branches
|
|
|
|
|
originate from ``develop`` and have tags for each point release in the
|
|
|
|
|
series. For example, ``releases/v0.14`` has tags for ``0.14.0``,
|
|
|
|
|
``0.14.1``, ``0.14.2``, etc. versions of Spack. We backport important bug
|
|
|
|
|
fixes to these branches, but we do not advance the package versions or
|
|
|
|
|
make other changes that would change the way Spack concretizes
|
|
|
|
|
dependencies. Currently, the maintainers manage these branches by
|
|
|
|
|
cherry-picking from ``develop``. See :ref:`releases` for more
|
|
|
|
|
information.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
----------------------
|
|
|
|
|
Continuous Integration
|
|
|
|
|
----------------------
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2020-08-01 06:01:12 +08:00
|
|
|
|
Spack uses `Github Actions <https://docs.github.com/en/actions>`_ for Continuous Integration
|
2016-10-15 00:16:13 +08:00
|
|
|
|
testing. This means that every time you submit a pull request, a series of tests will
|
2018-01-08 00:28:56 +08:00
|
|
|
|
be run to make sure you didn't accidentally introduce any bugs into Spack. **Your PR
|
|
|
|
|
will not be accepted until it passes all of these tests.** While you can certainly wait
|
2016-10-15 00:16:13 +08:00
|
|
|
|
for the results of these tests after submitting a PR, we recommend that you run them
|
|
|
|
|
locally to speed up the review process.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2018-01-08 00:28:56 +08:00
|
|
|
|
.. note::
|
|
|
|
|
|
2020-08-01 06:01:12 +08:00
|
|
|
|
Oftentimes, CI will fail for reasons other than a problem with your PR.
|
2018-01-08 00:28:56 +08:00
|
|
|
|
For example, apt-get, pip, or homebrew will fail to download one of the
|
|
|
|
|
dependencies for the test suite, or a transient bug will cause the unit tests
|
2020-08-01 06:01:12 +08:00
|
|
|
|
to timeout. If any job fails, click the "Details" link and click on the test(s)
|
2018-01-08 00:28:56 +08:00
|
|
|
|
that is failing. If it doesn't look like it is failing for reasons related to
|
|
|
|
|
your PR, you have two options. If you have write permissions for the Spack
|
2020-08-01 06:01:12 +08:00
|
|
|
|
repository, you should see a "Restart workflow" button on the right-hand side. If
|
2018-01-08 00:28:56 +08:00
|
|
|
|
not, you can close and reopen your PR to rerun all of the tests. If the same
|
|
|
|
|
test keeps failing, there may be a problem with your PR. If you notice that
|
2020-08-01 06:01:12 +08:00
|
|
|
|
every recent PR is failing with the same error message, it may be that an issue
|
|
|
|
|
occurred with the CI infrastructure or one of Spack's dependencies put out a
|
|
|
|
|
new release that is causing problems. If this is the case, please file an issue.
|
2018-01-08 00:28:56 +08:00
|
|
|
|
|
|
|
|
|
|
2022-08-04 21:26:56 +08:00
|
|
|
|
We currently test against Python 2.7 and 3.6-3.10 on both macOS and Linux and
|
2018-01-08 00:28:56 +08:00
|
|
|
|
perform 3 types of tests:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
.. _cmd-spack-unit-test:
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
Unit Tests
|
|
|
|
|
^^^^^^^^^^
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Unit tests ensure that core Spack features like fetching or spec resolution are
|
|
|
|
|
working as expected. If your PR only adds new packages or modifies existing ones,
|
|
|
|
|
there's very little chance that your changes could cause the unit tests to fail.
|
|
|
|
|
However, if you make changes to Spack's core libraries, you should run the unit
|
|
|
|
|
tests to make sure you didn't break anything.
|
|
|
|
|
|
|
|
|
|
Since they test things like fetching from VCS repos, the unit tests require
|
|
|
|
|
`git <https://git-scm.com/>`_, `mercurial <https://www.mercurial-scm.org/>`_,
|
|
|
|
|
and `subversion <https://subversion.apache.org/>`_ to run. Make sure these are
|
|
|
|
|
installed on your system and can be found in your ``PATH``. All of these can be
|
|
|
|
|
installed with Spack or with your system package manager.
|
|
|
|
|
|
|
|
|
|
To run *all* of the unit tests, use:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
$ spack unit-test
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
These tests may take several minutes to complete. If you know you are
|
|
|
|
|
only modifying a single Spack feature, you can run subsets of tests at a
|
|
|
|
|
time. For example, this would run all the tests in
|
|
|
|
|
``lib/spack/spack/test/architecture.py``:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
$ spack unit-test lib/spack/spack/test/architecture.py
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
|
|
|
|
|
And this would run the ``test_platform`` test from that file:
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
$ spack unit-test lib/spack/spack/test/architecture.py::test_platform
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
|
|
|
|
|
This allows you to develop iteratively: make a change, test that change,
|
|
|
|
|
make another change, test that change, etc. We use `pytest
|
2020-08-01 06:01:12 +08:00
|
|
|
|
<http://pytest.org/>`_ as our tests framework, and these types of
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
arguments are just passed to the ``pytest`` command underneath. See `the
|
|
|
|
|
pytest docs
|
|
|
|
|
<http://doc.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests>`_
|
|
|
|
|
for more details on test selection syntax.
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
``spack unit-test`` has a few special options that can help you
|
|
|
|
|
understand what tests are available. To get a list of all available
|
|
|
|
|
unit test files, run:
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
.. command-output:: spack unit-test --list
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
:ellipsis: 5
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
To see a more detailed list of available unit tests, use ``spack
|
|
|
|
|
unit-test --list-long``:
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
.. command-output:: spack unit-test --list-long
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
:ellipsis: 10
|
|
|
|
|
|
|
|
|
|
And to see the fully qualified names of all tests, use ``--list-names``:
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
.. command-output:: spack unit-test --list-names
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
:ellipsis: 5
|
|
|
|
|
|
|
|
|
|
You can combine these with ``pytest`` arguments to restrict which tests
|
|
|
|
|
you want to know about. For example, to see just the tests in
|
|
|
|
|
``architecture.py``:
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
.. command-output:: spack unit-test --list-long lib/spack/spack/test/architecture.py
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
|
|
|
|
|
You can also combine any of these options with a ``pytest`` keyword
|
2020-08-27 14:23:26 +08:00
|
|
|
|
search. See the `pytest usage docs
|
|
|
|
|
<https://docs.pytest.org/en/stable/usage.html#specifying-tests-selecting-tests>`_:
|
|
|
|
|
for more details on test selection syntax. For example, to see the names of all tests that have "spec"
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
or "concretize" somewhere in their names:
|
2017-01-24 01:48:49 +08:00
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
.. command-output:: spack unit-test --list-names -k "spec and concretize"
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
By default, ``pytest`` captures the output of all unit tests, and it will
|
|
|
|
|
print any captured output for failed tests. Sometimes it's helpful to see
|
|
|
|
|
your output interactively, while the tests run (e.g., if you add print
|
|
|
|
|
statements to a unit tests). To see the output *live*, use the ``-s``
|
|
|
|
|
argument to ``pytest``:
|
2018-04-28 23:59:33 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
$ spack unit-test -s --list-long lib/spack/spack/test/architecture.py::test_platform
|
2018-04-28 23:59:33 +08:00
|
|
|
|
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
Unit tests are crucial to making sure bugs aren't introduced into
|
|
|
|
|
Spack. If you are modifying core Spack libraries or adding new
|
|
|
|
|
functionality, please add new unit tests for your feature, and consider
|
|
|
|
|
strengthening existing tests. You will likely be asked to do this if you
|
|
|
|
|
submit a pull request to the Spack project on GitHub. Check out the
|
|
|
|
|
`pytest docs <http://pytest.org/>`_ and feel free to ask for guidance on
|
|
|
|
|
how to write tests!
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
You may notice the ``share/spack/qa/run-unit-tests`` script in the
|
2020-08-01 06:01:12 +08:00
|
|
|
|
repository. This script is designed for CI. It runs the unit
|
tests: improved `spack test` command line options
Previously, `spack test` automatically passed all of its arguments to
`pytest -k` if no options were provided, and to `pytest` if they were.
`spack test -l` also provided a list of test filenames, but they didn't
really let you completely narrow down which tests you wanted to run.
Instead of trying to do our own weird thing, this passes `spack test`
args directly to `pytest`, and omits the implicit `-k`. This means we
can now run, e.g.:
```console
$ spack test spec_syntax.py::TestSpecSyntax::test_ambiguous
```
This wasn't possible before, because we'd pass the fully qualified name
to `pytest -k` and get an error.
Because `pytest` doesn't have the greatest ability to list tests, I've
tweaked the `-l`/`--list`, `-L`/`--list-long`, and `-N`/`--list-names`
options to `spack test` so that they help you understand the names
better. you can combine these options with `-k` or other arguments to do
pretty powerful searches.
This one makes it easy to get a list of names so you can run tests in
different orders (something I find useful for debugging `pytest` issues):
```console
$ spack test --list-names -k "spec and concretize"
cmd/env.py::test_concretize_user_specs_together
concretize.py::TestConcretize::test_conflicts_in_spec
concretize.py::TestConcretize::test_find_spec_children
concretize.py::TestConcretize::test_find_spec_none
concretize.py::TestConcretize::test_find_spec_parents
concretize.py::TestConcretize::test_find_spec_self
concretize.py::TestConcretize::test_find_spec_sibling
concretize.py::TestConcretize::test_no_matching_compiler_specs
concretize.py::TestConcretize::test_simultaneous_concretization_of_specs
spec_dag.py::TestSpecDag::test_concretize_deptypes
spec_dag.py::TestSpecDag::test_copy_concretized
```
You can combine any list option with keywords:
```console
$ spack test --list -k microarchitecture
llnl/util/cpu.py modules/lmod.py
```
```console
$ spack test --list-long -k microarchitecture
llnl/util/cpu.py::
test_generic_microarchitecture
modules/lmod.py::TestLmod::
test_only_generic_microarchitectures_in_root
```
Or just list specific files:
```console
$ spack test --list-long cmd/test.py
cmd/test.py::
test_list test_list_names_with_pytest_arg
test_list_long test_list_with_keywords
test_list_long_with_pytest_arg test_list_with_pytest_arg
test_list_names
```
Hopefully this stuff will help with debugging test issues.
- [x] make `spack test` send args directly to `pytest` instead of trying
to do fancy things.
- [x] rework `--list`, `--list-long`, and add `--list-names` to make
searching for tests easier.
- [x] make it possible to mix Spack's list args with `pytest` args
(they're just fancy parsing around `pytest --collect-only`)
- [x] add docs
- [x] add tests
- [x] update spack completion
2019-12-30 09:53:52 +08:00
|
|
|
|
tests and reports coverage statistics back to Codecov. If you want to
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
|
run the unit tests yourself, we suggest you use ``spack unit-test``.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
^^^^^^^^^^^^
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
Style Tests
|
2016-10-15 00:16:13 +08:00
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Spack uses `Flake8 <http://flake8.pycqa.org/en/latest/>`_ to test for
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
`PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_ conformance and
|
|
|
|
|
`mypy <https://mypy.readthedocs.io/en/stable/>` for type checking. PEP 8 is
|
2016-10-15 00:16:13 +08:00
|
|
|
|
a series of style guides for Python that provide suggestions for everything
|
|
|
|
|
from variable naming to indentation. In order to limit the number of PRs that
|
|
|
|
|
were mostly style changes, we decided to enforce PEP 8 conformance. Your PR
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
needs to comply with PEP 8 in order to be accepted, and if it modifies the
|
|
|
|
|
spack library it needs to successfully type-check with mypy as well.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
Testing for compliance with spack's style is easy. Simply run the ``spack style``
|
2016-11-01 02:40:20 +08:00
|
|
|
|
command:
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
$ spack style
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
``spack style`` has a couple advantages over running the tools by hand:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-11-01 02:40:20 +08:00
|
|
|
|
#. It only tests files that you have modified since branching off of
|
|
|
|
|
``develop``.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
#. It works regardless of what directory you are in.
|
|
|
|
|
|
2016-11-01 02:40:20 +08:00
|
|
|
|
#. It automatically adds approved exemptions from the ``flake8``
|
|
|
|
|
checks. For example, URLs are often longer than 80 characters, so we
|
|
|
|
|
exempt them from line length checks. We also exempt lines that start
|
|
|
|
|
with "homepage", "url", "version", "variant", "depends_on", and
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
"extends" in ``package.py`` files. This is now also possible when directly
|
|
|
|
|
running flake8 if you can use the ``spack`` formatter plugin included with
|
|
|
|
|
spack.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
More approved flake8 exemptions can be found
|
2017-11-05 08:08:04 +08:00
|
|
|
|
`here <https://github.com/spack/spack/blob/develop/.flake8>`_.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
If all is well, you'll see something like this:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ run-flake8-tests
|
|
|
|
|
Dependencies found.
|
|
|
|
|
=======================================================
|
|
|
|
|
flake8: running flake8 code checks on spack.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Modified files:
|
|
|
|
|
|
|
|
|
|
var/spack/repos/builtin/packages/hdf5/package.py
|
|
|
|
|
var/spack/repos/builtin/packages/hdf/package.py
|
|
|
|
|
var/spack/repos/builtin/packages/netcdf/package.py
|
|
|
|
|
=======================================================
|
|
|
|
|
Flake8 checks were clean.
|
|
|
|
|
|
|
|
|
|
However, if you aren't compliant with PEP 8, flake8 will complain:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
var/spack/repos/builtin/packages/netcdf/package.py:26: [F401] 'os' imported but unused
|
|
|
|
|
var/spack/repos/builtin/packages/netcdf/package.py:61: [E303] too many blank lines (2)
|
|
|
|
|
var/spack/repos/builtin/packages/netcdf/package.py:106: [E501] line too long (92 > 79 characters)
|
|
|
|
|
Flake8 found errors.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Most of the error messages are straightforward, but if you don't understand what
|
|
|
|
|
they mean, just ask questions about them when you submit your PR. The line numbers
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
will change if you add or delete lines, so simply run ``spack style`` again
|
2016-10-15 00:16:13 +08:00
|
|
|
|
to update them.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
.. tip::
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Try fixing flake8 errors in reverse order. This eliminates the need for
|
add mypy to style checks; rename `spack flake8` to `spack style` (#20384)
I lost my mind a bit after getting the completion stuff working and
decided to get Mypy working for spack as well. This adds a
`.mypy.ini` that checks all of the spack and llnl modules, though
not yet packages, and fixes all of the identified missing types and
type issues for the spack library.
In addition to these changes, this includes:
* rename `spack flake8` to `spack style`
Aliases flake8 to style, and just runs flake8 as before, but with
a warning. The style command runs both `flake8` and `mypy`,
in sequence. Added --no-<tool> options to turn off one or the
other, they are on by default. Fixed two issues caught by the tools.
* stub typing module for python2.x
We don't support typing in Spack for python 2.x. To allow 2.x to
support `import typing` and `from typing import ...` without a
try/except dance to support old versions, this adds a stub module
*just* for python 2.x. Doing it this way means we can only reliably
use all type hints in python3.7+, and mypi.ini has been updated to
reflect that.
* add non-default black check to spack style
This is a first step to requiring black. It doesn't enforce it by
default, but it will check it if requested. Currently enforcing the
line length of 79 since that's what flake8 requires, but it's a bit odd
for a black formatted project to be quite that narrow. All settings are
in the style command since spack has no pyproject.toml and I don't
want to add one until more discussion happens. Also re-format
`style.py` since it no longer passed the black style check
with the new length.
* use style check in github action
Update the style and docs action to use `spack style`, adding in mypy
and black to the action even if it isn't running black right now.
2020-12-23 13:39:10 +08:00
|
|
|
|
multiple runs of ``spack style`` just to re-compute line numbers and
|
2020-08-01 06:01:12 +08:00
|
|
|
|
makes it much easier to fix errors directly off of the CI output.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
.. warning::
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2018-06-28 04:44:22 +08:00
|
|
|
|
Flake8 and ``pep8-naming`` require a number of dependencies in order
|
|
|
|
|
to run. If you installed ``py-flake8`` and ``py-pep8-naming``, the
|
|
|
|
|
easiest way to ensure the right packages are on your ``PYTHONPATH`` is
|
|
|
|
|
to run::
|
|
|
|
|
|
|
|
|
|
spack activate py-flake8
|
|
|
|
|
spack activate pep8-naming
|
|
|
|
|
|
|
|
|
|
so that all of the dependencies are symlinked to a central
|
|
|
|
|
location. If you see an error message like:
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
|
File: "/usr/bin/flake8", line 5, in <module>
|
|
|
|
|
from pkg_resources import load_entry_point
|
|
|
|
|
ImportError: No module named pkg_resources
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2018-01-11 03:02:33 +08:00
|
|
|
|
that means Flake8 couldn't find setuptools in your ``PYTHONPATH``.
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
Documentation Tests
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Spack uses `Sphinx <http://www.sphinx-doc.org/en/stable/>`_ to build its
|
|
|
|
|
documentation. In order to prevent things like broken links and missing imports,
|
|
|
|
|
we added documentation tests that build the documentation and fail if there
|
|
|
|
|
are any warning or error messages.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2019-12-09 06:22:25 +08:00
|
|
|
|
Building the documentation requires several dependencies:
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
* sphinx
|
2017-05-18 00:36:02 +08:00
|
|
|
|
* sphinxcontrib-programoutput
|
2018-06-17 16:13:56 +08:00
|
|
|
|
* sphinx-rtd-theme
|
2016-10-15 00:16:13 +08:00
|
|
|
|
* graphviz
|
|
|
|
|
* git
|
|
|
|
|
* mercurial
|
|
|
|
|
* subversion
|
|
|
|
|
|
2019-12-09 06:22:25 +08:00
|
|
|
|
All of these can be installed with Spack, e.g.
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ spack install py-sphinx py-sphinxcontrib-programoutput py-sphinx-rtd-theme graphviz git mercurial subversion
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
.. warning::
|
|
|
|
|
|
2017-11-05 08:08:04 +08:00
|
|
|
|
Sphinx has `several required dependencies <https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/py-sphinx/package.py>`_.
|
2019-12-09 06:22:25 +08:00
|
|
|
|
If you're using a ``python`` from Spack and you installed
|
|
|
|
|
``py-sphinx`` and friends, you need to make them available to your
|
|
|
|
|
``python``. The easiest way to do this is to run:
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2018-01-11 03:02:33 +08:00
|
|
|
|
$ spack activate py-sphinx
|
2018-06-17 16:13:56 +08:00
|
|
|
|
$ spack activate py-sphinx-rtd-theme
|
2018-01-11 03:02:33 +08:00
|
|
|
|
$ spack activate py-sphinxcontrib-programoutput
|
|
|
|
|
|
2019-12-09 06:22:25 +08:00
|
|
|
|
so that all of the dependencies are symlinked into that Python's
|
|
|
|
|
tree. Alternatively, you could arrange for their library
|
|
|
|
|
directories to be added to PYTHONPATH. If you see an error message
|
|
|
|
|
like:
|
2018-01-11 03:02:33 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
Extension error:
|
|
|
|
|
Could not import extension sphinxcontrib.programoutput (exception: No module named sphinxcontrib.programoutput)
|
|
|
|
|
make: *** [html] Error 1
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
2018-01-11 03:02:33 +08:00
|
|
|
|
that means Sphinx couldn't find ``py-sphinxcontrib-programoutput`` in your
|
|
|
|
|
``PYTHONPATH``.
|
2016-10-15 00:16:13 +08:00
|
|
|
|
|
|
|
|
|
Once all of the dependencies are installed, you can try building the documentation:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2020-08-27 14:23:26 +08:00
|
|
|
|
$ cd path/to/spack/lib/spack/docs/
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ make clean
|
|
|
|
|
$ make
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
If you see any warning or error messages, you will have to correct those before
|
|
|
|
|
your PR is accepted.
|
|
|
|
|
|
|
|
|
|
If you are editing the documentation, you should obviously be running the
|
|
|
|
|
documentation tests. But even if you are simply adding a new package, your
|
|
|
|
|
changes could cause the documentation tests to fail:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
package_list.rst:8745: WARNING: Block quote ends without a blank line; unexpected unindent.
|
|
|
|
|
|
|
|
|
|
At first, this error message will mean nothing to you, since you didn't edit
|
|
|
|
|
that file. Until you look at line 8745 of the file in question:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
Description:
|
|
|
|
|
NetCDF is a set of software libraries and self-describing, machine-
|
|
|
|
|
independent data formats that support the creation, access, and sharing
|
|
|
|
|
of array-oriented scientific data.
|
|
|
|
|
|
|
|
|
|
Our documentation includes :ref:`a list of all Spack packages <package-list>`.
|
|
|
|
|
If you add a new package, its docstring is added to this page. The problem in
|
|
|
|
|
this case was that the docstring looked like:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
class Netcdf(Package):
|
|
|
|
|
"""
|
|
|
|
|
NetCDF is a set of software libraries and self-describing,
|
|
|
|
|
machine-independent data formats that support the creation,
|
|
|
|
|
access, and sharing of array-oriented scientific data.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Docstrings cannot start with a newline character, or else Sphinx will complain.
|
|
|
|
|
Instead, they should look like:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
class Netcdf(Package):
|
|
|
|
|
"""NetCDF is a set of software libraries and self-describing,
|
|
|
|
|
machine-independent data formats that support the creation,
|
|
|
|
|
access, and sharing of array-oriented scientific data."""
|
|
|
|
|
|
|
|
|
|
Documentation changes can result in much more obfuscated warning messages.
|
|
|
|
|
If you don't understand what they mean, feel free to ask when you submit
|
|
|
|
|
your PR.
|
|
|
|
|
|
2018-01-08 00:28:56 +08:00
|
|
|
|
--------
|
|
|
|
|
Coverage
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
Spack uses `Codecov <https://codecov.io/>`_ to generate and report unit test
|
|
|
|
|
coverage. This helps us tell what percentage of lines of code in Spack are
|
|
|
|
|
covered by unit tests. Although code covered by unit tests can still contain
|
|
|
|
|
bugs, it is much less error prone than code that is not covered by unit tests.
|
|
|
|
|
|
2020-03-31 22:49:25 +08:00
|
|
|
|
Codecov provides `browser extensions <https://github.com/codecov/sourcegraph-codecov>`_
|
|
|
|
|
for Google Chrome and Firefox. These extensions integrate with GitHub
|
2018-01-08 00:28:56 +08:00
|
|
|
|
and allow you to see coverage line-by-line when viewing the Spack repository.
|
|
|
|
|
If you are new to Spack, a great way to get started is to write unit tests to
|
|
|
|
|
increase coverage!
|
|
|
|
|
|
2020-08-01 06:01:12 +08:00
|
|
|
|
Unlike with CI on Github Actions Codecov tests are not required to pass in order for your
|
2018-01-08 00:28:56 +08:00
|
|
|
|
PR to be merged. If you modify core Spack libraries, we would greatly
|
|
|
|
|
appreciate unit tests that cover these changed lines. Otherwise, we have no
|
|
|
|
|
way of knowing whether or not your changes introduce a bug. If you make
|
|
|
|
|
substantial changes to the core, we may request unit tests to increase coverage.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
If the only files you modified are package files, we do not care about
|
|
|
|
|
coverage on your PR. You may notice that the Codecov tests fail even though
|
|
|
|
|
you didn't modify any core files. This means that Spack's overall coverage
|
|
|
|
|
has increased since you branched off of develop. This is a good thing!
|
|
|
|
|
If you really want to get the Codecov tests to pass, you can rebase off of
|
|
|
|
|
the latest develop, but again, this is not required.
|
|
|
|
|
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
-------------
|
|
|
|
|
Git Workflows
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
Spack is still in the beta stages of development. Most of our users run off of
|
|
|
|
|
the develop branch, and fixes and new features are constantly being merged. So
|
|
|
|
|
how do you keep up-to-date with upstream while maintaining your own local
|
|
|
|
|
differences and contributing PRs to Spack?
|
|
|
|
|
|
|
|
|
|
^^^^^^^^^
|
|
|
|
|
Branching
|
|
|
|
|
^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
The easiest way to contribute a pull request is to make all of your changes on
|
|
|
|
|
new branches. Make sure your ``develop`` is up-to-date and create a new branch
|
|
|
|
|
off of it:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git checkout develop
|
|
|
|
|
$ git pull upstream develop
|
|
|
|
|
$ git branch <descriptive_branch_name>
|
|
|
|
|
$ git checkout <descriptive_branch_name>
|
|
|
|
|
|
|
|
|
|
Here we assume that the local ``develop`` branch tracks the upstream develop
|
|
|
|
|
branch of Spack. This is not a requirement and you could also do the same with
|
|
|
|
|
remote branches. But for some it is more convenient to have a local branch that
|
|
|
|
|
tracks upstream.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Normally we prefer that commits pertaining to a package ``<package-name>`` have
|
|
|
|
|
a message ``<package-name>: descriptive message``. It is important to add
|
|
|
|
|
descriptive message so that others, who might be looking at your changes later
|
|
|
|
|
(in a year or maybe two), would understand the rationale behind them.
|
|
|
|
|
|
|
|
|
|
Now, you can make your changes while keeping the ``develop`` branch pure.
|
|
|
|
|
Edit a few files and commit them by running:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git add <files_to_be_part_of_the_commit>
|
|
|
|
|
$ git commit --message <descriptive_message_of_this_particular_commit>
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Next, push it to your remote fork and create a PR:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
.. code-block:: console
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git push origin <descriptive_branch_name> --set-upstream
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
GitHub provides a `tutorial <https://help.github.com/articles/about-pull-requests/>`_
|
|
|
|
|
on how to file a pull request. When you send the request, make ``develop`` the
|
|
|
|
|
destination branch.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
If you need this change immediately and don't have time to wait for your PR to
|
|
|
|
|
be merged, you can always work on this branch. But if you have multiple PRs,
|
|
|
|
|
another option is to maintain a Frankenstein branch that combines all of your
|
|
|
|
|
other branches:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git co develop
|
|
|
|
|
$ git branch <your_modified_develop_branch>
|
|
|
|
|
$ git checkout <your_modified_develop_branch>
|
|
|
|
|
$ git merge <descriptive_branch_name>
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
This can be done with each new PR you submit. Just make sure to keep this local
|
|
|
|
|
branch up-to-date with upstream ``develop`` too.
|
|
|
|
|
|
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
Cherry-Picking
|
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
What if you made some changes to your local modified develop branch and already
|
|
|
|
|
committed them, but later decided to contribute them to Spack? You can use
|
|
|
|
|
cherry-picking to create a new branch with only these commits.
|
|
|
|
|
|
|
|
|
|
First, check out your local modified develop branch:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git checkout <your_modified_develop_branch>
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Now, get the hashes of the commits you want from the output of:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git log
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Next, create a new branch off of upstream ``develop`` and copy the commits
|
|
|
|
|
that you want in your PR:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git checkout develop
|
|
|
|
|
$ git pull upstream develop
|
|
|
|
|
$ git branch <descriptive_branch_name>
|
|
|
|
|
$ git checkout <descriptive_branch_name>
|
|
|
|
|
$ git cherry-pick <hash>
|
|
|
|
|
$ git push origin <descriptive_branch_name> --set-upstream
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Now you can create a PR from the web-interface of GitHub. The net result is as
|
|
|
|
|
follows:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
#. You patched your local version of Spack and can use it further.
|
|
|
|
|
#. You "cherry-picked" these changes in a stand-alone branch and submitted it
|
|
|
|
|
as a PR upstream.
|
|
|
|
|
|
|
|
|
|
Should you have several commits to contribute, you could follow the same
|
|
|
|
|
procedure by getting hashes of all of them and cherry-picking to the PR branch.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
It is important that whenever you change something that might be of
|
|
|
|
|
importance upstream, create a pull request as soon as possible. Do not wait
|
|
|
|
|
for weeks/months to do this, because:
|
|
|
|
|
|
|
|
|
|
#. you might forget why you modified certain files
|
|
|
|
|
#. it could get difficult to isolate this change into a stand-alone clean PR.
|
|
|
|
|
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
Rebasing
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Other developers are constantly making contributions to Spack, possibly on the
|
|
|
|
|
same files that your PR changed. If their PR is merged before yours, it can
|
|
|
|
|
create a merge conflict. This means that your PR can no longer be automatically
|
|
|
|
|
merged without a chance of breaking your changes. In this case, you will be
|
|
|
|
|
asked to rebase on top of the latest upstream ``develop``.
|
|
|
|
|
|
|
|
|
|
First, make sure your develop branch is up-to-date:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git checkout develop
|
|
|
|
|
$ git pull upstream develop
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Now, we need to switch to the branch you submitted for your PR and rebase it
|
|
|
|
|
on top of develop:
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ git checkout <descriptive_branch_name>
|
|
|
|
|
$ git rebase develop
|
|
|
|
|
|
|
|
|
|
Git will likely ask you to resolve conflicts. Edit the file that it says can't
|
|
|
|
|
be merged automatically and resolve the conflict. Then, run:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git add <file_that_could_not_be_merged>
|
|
|
|
|
$ git rebase --continue
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
You may have to repeat this process multiple times until all conflicts are resolved.
|
|
|
|
|
Once this is done, simply force push your rebased branch to your remote fork:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
.. code-block:: console
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git push --force origin <descriptive_branch_name>
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
Rebasing with cherry-pick
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
You can also perform a rebase using ``cherry-pick``. First, create a temporary
|
|
|
|
|
backup branch:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git checkout <descriptive_branch_name>
|
|
|
|
|
$ git branch tmp
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
If anything goes wrong, you can always go back to your ``tmp`` branch.
|
|
|
|
|
Now, look at the logs and save the hashes of any commits you would like to keep:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git log
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
Next, go back to the original branch and reset it to ``develop``.
|
|
|
|
|
Before doing so, make sure that you local ``develop`` branch is up-to-date
|
2016-10-15 00:16:13 +08:00
|
|
|
|
with upstream:
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ git checkout develop
|
|
|
|
|
$ git pull upstream develop
|
|
|
|
|
$ git checkout <descriptive_branch_name>
|
|
|
|
|
$ git reset --hard develop
|
|
|
|
|
|
|
|
|
|
Now you can cherry-pick relevant commits:
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ git cherry-pick <hash1>
|
|
|
|
|
$ git cherry-pick <hash2>
|
|
|
|
|
|
|
|
|
|
Push the modified branch to your fork:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git push --force origin <descriptive_branch_name>
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
If everything looks good, delete the backup branch:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git branch --delete --force tmp
|
|
|
|
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
|
|
|
|
Re-writing History
|
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
Sometimes you may end up on a branch that has diverged so much from develop
|
|
|
|
|
that it cannot easily be rebased. If the current commits history is more of
|
|
|
|
|
an experimental nature and only the net result is important, you may rewrite
|
|
|
|
|
the history.
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
First, merge upstream ``develop`` and reset you branch to it. On the branch
|
|
|
|
|
in question, run:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git merge develop
|
|
|
|
|
$ git reset develop
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
At this point your branch will point to the same commit as develop and
|
|
|
|
|
thereby the two are indistinguishable. However, all the files that were
|
|
|
|
|
previously modified will stay as such. In other words, you do not lose the
|
|
|
|
|
changes you made. Changes can be reviewed by looking at diffs:
|
2016-10-06 22:45:47 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
2016-10-15 00:16:13 +08:00
|
|
|
|
$ git status
|
|
|
|
|
$ git diff
|
|
|
|
|
|
|
|
|
|
The next step is to rewrite the history by adding files and creating commits:
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ git add <files_to_be_part_of_commit>
|
|
|
|
|
$ git commit --message <descriptive_message>
|
|
|
|
|
|
|
|
|
|
After all changed files are committed, you can push the branch to your fork
|
|
|
|
|
and create a PR:
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ git push origin --set-upstream
|