|
| 1 | +# CASE Implementation Template: CLI Example |
| 2 | + |
| 3 | +[](https://github.com/casework/CASE-Implementation-Template-Python-CLI/actions/workflows/ci.yml) |
| 4 | + |
| 5 | + |
| 6 | +_(Please see the [NIST disclaimer](#disclaimer).)_ |
| 7 | + |
| 8 | +This template repository is provided for those looking to develop command-line utilities using ontologies within the [Cyber Domain Ontology](https://cyberdomainontology.org) ecosystem, particularly [CASE](https://caseontology.org) and [UCO](https://unifiedcyberontology.org). |
| 9 | + |
| 10 | +This template repository provides a [Make](https://en.wikipedia.org/wiki/Make_%28software%29)-based test workflow used in some other CASE projects. The workflow exercises this project as a command-line interface (CLI) application (under [`tests/cli/`](tests/cli/)), and as a package (under [`tests/package/`](tests/package/)). |
| 11 | + |
| 12 | +This is only one possible application development style, and templates are available to support other styles. See for instance: |
| 13 | + |
| 14 | +* [casework/CASE-Mapping-Template-Python](https://github.com/casework/CASE-Mapping-Template-Python), which demonstrates an approach based on constructing Python `dict`s and checking generated results afterwards for CASE conformance with the [CASE Validation Action](https://github.com/kchason/case-validation-action). |
| 15 | + |
| 16 | +Testing procedures run in _this_ repository are: |
| 17 | + |
| 18 | +* _GitHub Actions_: [Workflows](.github/workflows/) are defined to run testing as they would be run in a local command-line environment, reviewing on pushes and pull requests to certain branches. |
| 19 | +* _Supply chain review_: [One workflow](.github/workflows/supply-chain.yml) checks dependencies on a schedule, confirming pinned dependencies are the latest, and loosely-pinned dependencies do not impact things like type review. |
| 20 | +* _Type review_: `mypy --strict` reviews the package source tree and the tests directory. |
| 21 | +* _Code style_: `pre-commit` reviews code patches in Continuous Integration testing and in local development. Running `make` will install `pre-commit` in a special virtual environment dedicated to the cloned repository instance. |
| 22 | +* _Doctests_: Module docstrings' inlined tests are run with `pytest`. |
| 23 | +* _CASE validation_: Unit tests that generate CASE graph files are written to run `case_validate` before considering the file "successfully" built. |
| 24 | +* _Editable package installation_: The test suite installs the package in an "editable" mode into the virtual environment under `tests/venv/`. Activating the virtual environment (e.g. for Bash users, running `source tests/venv/bin/activate` from the repository's top source directory) enables "live code" testing. |
| 25 | +* _Parallel Make runs_: Tests based on `make` have dependencies specified in a manner that enables `make --jobs` to run testing in parallel. |
| 26 | +* _Directory-local Make runs_: The Makefiles are written to run regardless of the present working directory within the top source directory or the [`tests/`](tests/) directory, assuming `make check` has been run from the top source directory at least once. If a test is failing, `cd`'ing into that test's directory and running `make check` should reproduce the failure quickly and focus development effort. |
| 27 | + |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +To use the template, push the "Use this template" button on GitHub, and adapt files as suits your new project's needs. The README should be revised at least from its top to the "Versioning" section. Source files should be renamed and revised, and any other files with a `TODO` within it should be adjusted. |
| 32 | + |
| 33 | +After any revisions, running `make check` (or `make -j check`) from the top source directory should have unit tests continue to pass. |
| 34 | + |
| 35 | +_Below this line is sample text to use and adapt for your project. Most text above this line is meant to document the template, rather than projects using the template._ |
| 36 | + |
| 37 | +To install this software, clone this repository, and run `pip install .` from within this directory. (You might want to do this in a virtual environment.) |
| 38 | + |
| 39 | +This provides a standalone command: |
| 40 | + |
| 41 | +```bash |
| 42 | +case_cli_example output.rdf |
| 43 | +``` |
| 44 | + |
| 45 | +The tests build several examples of output for the command line mode, under [`tests/cli`](tests/cli/). |
| 46 | + |
| 47 | +The installation also provides a package to import: |
| 48 | + |
| 49 | +```python |
| 50 | +import case_cli_example |
| 51 | +help(case_cli_example.foo) |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +## Versioning |
| 56 | + |
| 57 | +This project follows [SEMVER 2.0.0](https://semver.org/) where versions are declared. |
| 58 | + |
| 59 | + |
| 60 | +## Make targets |
| 61 | + |
| 62 | +Some `make` targets are defined for this repository: |
| 63 | +* `all` - Installs `pre-commit` for this cloned repository instance. |
| 64 | +* `check` - Run unit tests. *NOTE*: The tests entail an installation of this project's source tree, including prerequisites downloaded from PyPI. |
| 65 | +* `clean` - Remove test build files. |
| 66 | + |
| 67 | + |
| 68 | +## Licensing |
| 69 | + |
| 70 | +Portions of this repository contributed by NIST are governed by the [NIST Software Licensing Statement](LICENSE). |
| 71 | + |
| 72 | + |
| 73 | +## Disclaimer |
| 74 | + |
| 75 | +Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. |
0 commit comments