Skip to content

Commit 55a6645

Browse files
committed
Initial commit
Signed-off-by: Alex Nelson <[email protected]>
0 parents  commit 55a6645

27 files changed

+967
-0
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Portions of this file contributed by NIST are governed by the
2+
# following statement:
3+
#
4+
# This software was developed at the National Institute of Standards
5+
# and Technology by employees of the Federal Government in the course
6+
# of their official duties. Pursuant to Title 17 Section 105 of the
7+
# United States Code, this software is not subject to copyright
8+
# protection within the United States. NIST assumes no responsibility
9+
# whatsoever for its use by other parties, and makes no guarantees,
10+
# expressed or implied, about its quality, reliability, or any other
11+
# characteristic.
12+
#
13+
# We would appreciate acknowledgement if the software is used.
14+
15+
name: Continuous Integration
16+
17+
on:
18+
push:
19+
branches: [ main, develop ]
20+
pull_request:
21+
branches: [ main, develop ]
22+
schedule:
23+
- cron: '15 5 * * TUE'
24+
25+
jobs:
26+
build:
27+
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
python-version:
32+
- '3.9'
33+
- '3.11'
34+
35+
steps:
36+
- uses: actions/checkout@v3
37+
- name: Set up Python ${{ matrix.python-version }}
38+
uses: actions/setup-python@v4
39+
with:
40+
python-version: ${{ matrix.python-version }}
41+
- name: Pre-commit Checks
42+
run: |
43+
pip -q install pre-commit
44+
pre-commit run --all-files
45+
- name: Start from clean state
46+
run: make clean
47+
- name: Run tests
48+
run: make PYTHON3=python3 check

.github/workflows/supply-chain.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Portions of this file contributed by NIST are governed by the
2+
# following statement:
3+
#
4+
# This software was developed at the National Institute of Standards
5+
# and Technology by employees of the Federal Government in the course
6+
# of their official duties. Pursuant to Title 17 Section 105 of the
7+
# United States Code, this software is not subject to copyright
8+
# protection within the United States. NIST assumes no responsibility
9+
# whatsoever for its use by other parties, and makes no guarantees,
10+
# expressed or implied, about its quality, reliability, or any other
11+
# characteristic.
12+
#
13+
# We would appreciate acknowledgement if the software is used.
14+
15+
# This workflow uses Make to review direct dependencies of this
16+
# repository.
17+
18+
name: Supply Chain
19+
20+
on:
21+
schedule:
22+
- cron: '15 5 * * 1,2,3,4,5'
23+
24+
jobs:
25+
build:
26+
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
python-version:
31+
- '3.9'
32+
- '3.11'
33+
34+
steps:
35+
- uses: actions/checkout@v3
36+
with:
37+
# This enables supply chain review against only a selected
38+
# branch. For those using the "Git-Flow" style of branching,
39+
# the ref value should be 'develop', so an upstream dependency
40+
# only relevant for, say, code formatting does not need to
41+
# induce a new commit on 'main', or a release.
42+
# https://cyberdomainontology.org/ontology/development/#branching-cdo-git-flow
43+
ref: main
44+
- name: Set up Python ${{ matrix.python-version }}
45+
uses: actions/setup-python@v4
46+
with:
47+
python-version: ${{ matrix.python-version }}
48+
- name: Review dependencies
49+
run: make check-supply-chain

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.egg-info
2+
*.swp
3+
.DS_Store
4+
.git_submodule_init.done.log
5+
.venv-pre-commit
6+
__pycache__
7+
build
8+
dist

.gitmodules

Whitespace-only changes.

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 23.9.1
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pycqa/flake8
7+
rev: 6.1.0
8+
hooks:
9+
- id: flake8
10+
- repo: https://github.com/pycqa/isort
11+
rev: 5.12.0
12+
hooks:
13+
- id: isort
14+
name: isort (python)

LICENSE

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Portions of this repository contributed by NIST are governed by
2+
the following license.
3+
4+
5+
# NIST Software Licensing Statement
6+
7+
NIST-developed software is provided by NIST as a public service.
8+
You may use, copy, and distribute copies of the software in any
9+
medium, provided that you keep intact this entire notice. You may
10+
improve, modify, and create derivative works of the software or
11+
any portion of the software, and you may copy and distribute such
12+
modifications or works. Modified works should carry a notice
13+
stating that you changed the software and should note the date
14+
and nature of any such change. Please explicitly acknowledge the
15+
National Institute of Standards and Technology as the source of
16+
the software.
17+
18+
NIST-developed software is expressly provided "AS IS." NIST MAKES
19+
NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT, OR ARISING BY
20+
OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21+
WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
22+
NON-INFRINGEMENT, AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
23+
WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED
24+
OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST DOES
25+
NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE
26+
SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE
27+
CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE
28+
SOFTWARE.
29+
30+
You are solely responsible for determining the appropriateness of
31+
using and distributing the software and you assume all risks
32+
associated with its use, including but not limited to the risks
33+
and costs of program errors, compliance with applicable laws,
34+
damage to or loss of data, programs or equipment, and the
35+
unavailability or interruption of operation. This software is not
36+
intended to be used in any situation where a failure could cause
37+
risk of injury or damage to property. The software developed by
38+
NIST employees is not subject to copyright protection within the
39+
United States.

Makefile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/make -f
2+
3+
# Portions of this file contributed by NIST are governed by the
4+
# following statement:
5+
#
6+
# This software was developed at the National Institute of Standards
7+
# and Technology by employees of the Federal Government in the course
8+
# of their official duties. Pursuant to Title 17 Section 105 of the
9+
# United States Code, this software is not subject to copyright
10+
# protection within the United States. NIST assumes no responsibility
11+
# whatsoever for its use by other parties, and makes no guarantees,
12+
# expressed or implied, about its quality, reliability, or any other
13+
# characteristic.
14+
#
15+
# We would appreciate acknowledgement if the software is used.
16+
17+
SHELL := /bin/bash
18+
19+
PYTHON3 ?= python3
20+
21+
all: \
22+
.venv-pre-commit/var/.pre-commit-built.log
23+
24+
.PHONY: \
25+
check-supply-chain \
26+
check-supply-chain-mypy \
27+
check-supply-chain-pre-commit
28+
29+
.git_submodule_init.done.log: \
30+
.gitmodules
31+
git submodule update --init
32+
touch $@
33+
34+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
35+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
36+
.venv-pre-commit/var/.pre-commit-built.log:
37+
rm -rf .venv-pre-commit
38+
test -r .pre-commit-config.yaml \
39+
|| (echo "ERROR:Makefile:pre-commit is expected to install for this repository, but .pre-commit-config.yaml does not seem to exist." >&2 ; exit 1)
40+
$(PYTHON3) -m venv \
41+
.venv-pre-commit
42+
source .venv-pre-commit/bin/activate \
43+
&& pip install \
44+
--upgrade \
45+
pip \
46+
setuptools \
47+
wheel
48+
source .venv-pre-commit/bin/activate \
49+
&& pip install \
50+
pre-commit
51+
source .venv-pre-commit/bin/activate \
52+
&& pre-commit install
53+
mkdir -p \
54+
.venv-pre-commit/var
55+
touch $@
56+
57+
check: \
58+
check-supply-chain-mypy \
59+
.venv-pre-commit/var/.pre-commit-built.log
60+
$(MAKE) \
61+
PYTHON3=$(PYTHON3) \
62+
--directory tests \
63+
check
64+
65+
# This target's dependencies potentially modify the working directory's Git state, so it is intentionally not a dependency of check.
66+
check-supply-chain: \
67+
check-supply-chain-pre-commit \
68+
check-supply-chain-mypy
69+
70+
check-supply-chain-mypy: \
71+
.git_submodule_init.done.log
72+
$(MAKE) \
73+
PYTHON3=$(PYTHON3) \
74+
--directory tests \
75+
check-mypy
76+
77+
check-supply-chain-pre-commit: \
78+
.venv-pre-commit/var/.pre-commit-built.log
79+
source .venv-pre-commit/bin/activate \
80+
&& pre-commit autoupdate
81+
git diff \
82+
--exit-code \
83+
.pre-commit-config.yaml
84+
85+
clean:
86+
@rm -rf \
87+
*.egg-info \
88+
build \
89+
dist
90+
@$(MAKE) \
91+
--directory tests \
92+
clean
93+
@rm -f \
94+
.git_submodule_init.done.log

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# CASE Implementation Template: CLI Example
2+
3+
[![Continuous Integration](https://github.com/casework/CASE-Implementation-Template-Python-CLI/actions/workflows/ci.yml/badge.svg)](https://github.com/casework/CASE-Implementation-Template-Python-CLI/actions/workflows/ci.yml)
4+
![CASE Version](https://img.shields.io/badge/CASE%20Version-1.2.0-green)
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.

case_cli_example/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
# Portions of this file contributed by NIST are governed by the
4+
# following statement:
5+
#
6+
# This software was developed at the National Institute of Standards
7+
# and Technology by employees of the Federal Government in the course
8+
# of their official duties. Pursuant to Title 17 Section 105 of the
9+
# United States Code, this software is not subject to copyright
10+
# protection within the United States. NIST assumes no responsibility
11+
# whatsoever for its use by other parties, and makes no guarantees,
12+
# expressed or implied, about its quality, reliability, or any other
13+
# characteristic.
14+
#
15+
# We would appreciate acknowledgement if the software is used.
16+
17+
# TODO - Adapt below.
18+
19+
"""
20+
case_cli_example is a command that demonstrates making a CLI application tested with a Make-based workflow.
21+
"""
22+
23+
__version__ = "0.0.1"
24+
25+
26+
def foo() -> str:
27+
"""
28+
This function is provided to demonstrate the doctests system templated in this repository. If all doctests from the package source directory are removed, the 'check-doctest' recipe in /tests/Makefile will also need to be removed, because pytest reports a failure if no tests are found.
29+
30+
>>> foo()
31+
'x'
32+
"""
33+
return "x"

0 commit comments

Comments
 (0)