Skip to content

Commit

Permalink
Merge pull request #229 from DigitalSlideArchive/56-consistent-yaml
Browse files Browse the repository at this point in the history
Clean up yaml files we commit to source control
  • Loading branch information
naglepuff authored Jul 19, 2024
2 parents 4fb1905 + 23bc7a4 commit eef8a6c
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Reformat code to standardize double quoted strings
92c1ec85ab680851055c16f022ab9ce80c600e3c

# Format yaml files
8846ba15625de7bfb68d40c4eb224c2c2d59dda2
File renamed without changes.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: ci
on:
pull_request:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
name: release
on:
release:
types: [published]
types:
- published
jobs:
publish:
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Image redaction is determined by a set of rules. By default, the base set of rul
## Rule Application
All runs of `imagedephi` use the provided base set of rules as a foundation. End users can use the ruleset framework to build custom rulesets that handle additional or custom metadata not covered by the base rules, or override the behavior of the base rule set.

Override rule sets can be specified by using the `-r my_ruleset.yml` or `--override-rules my_ruleset.yml` option. This option is available for both the `imagedephi run` and `imagedephi plan` commands. Override rules sets are not provided by `imagedephi`, and must de defined by the end user.
Override rule sets can be specified by using the `-r my_ruleset.yaml` or `--override-rules my_ruleset.yaml` option. This option is available for both the `imagedephi run` and `imagedephi plan` commands. Override rules sets are not provided by `imagedephi`, and must de defined by the end user.

When `imagedephi` determines the steps to redact a file, it checks each piece of metadata in the file. For each piece of metadata found this way, it will first consult the override rule set, if present, for an applicable rule. If the override rule set does not contain a rule for that piece of metadata, the program will check the base ruleset.

Expand All @@ -34,7 +34,7 @@ For whole slide image formats based on the tiff standard, `imagedephi` allows a


## Ruleset Format Overview
In order to read the base rules and build your own custom rule sets, it is important to understand the format in which rulesets are specified. Rulesets are defined by `.yml` files (one ruleset per file), and are a dictionary with the following top-level tags: `name`, `description`, `output_file_name`, `tiff`, and `svs`.
In order to read the base rules and build your own custom rule sets, it is important to understand the format in which rulesets are specified. Rulesets are defined by `.yaml` files (one ruleset per file), and are a dictionary with the following top-level tags: `name`, `description`, `output_file_name`, `tiff`, and `svs`.

### Generic Properties
The following three properties belong to the rulesets themselves, and don't influence redaction behavior.
Expand Down
5 changes: 2 additions & 3 deletions imagedephi/base_rules.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Base rules
description: These are the default rules for each potential piece of redactable material
(metadata, image) to be used as a fallback if there are no user defined rules for
a piece of redactable material.
description: These are the default rules for each potential piece of redactable material (metadata, image) to be used as a fallback if there are no user defined rules for a piece of redactable material.
output_file_name: study_slide
tiff:
associated_images:
Expand Down
4 changes: 2 additions & 2 deletions imagedephi/minimum_rules.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Minimum Rules
description: A set of rules that defines a minimum amount of metadata for images
to be read. Metadata not specified by a rule is deleted (controlled by the metadata_fallback_action).
description: A set of rules that defines a minimum amount of metadata for images to be read. Metadata not specified by a rule is deleted (controlled by the metadata_fallback_action).
output_file_name: study_slide
tiff:
metadata_fallback_action: delete
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ testpaths = ["tests"]

[tool.pyright]
stubPath = "stubs"

[tool.yamlfix]
line_length = 200
preserve_quotes = true
sequence_style = "block_style"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ tiff:
action: check_type
expected_type: number
expected_count: 2

svs:
associated_images: {}
metadata:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_e2e_run(
main.imagedephi,
[
"--override-rules",
str(rules_dir / "example_user_rules.yml"),
str(rules_dir / "example_user_rules.yaml"),
"run",
str(data_dir / "input" / "tiff"),
"--output-dir",
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_e2e_plan(
main.imagedephi,
[
"--override-rules",
str(rules_dir / "example_user_rules.yml"),
str(rules_dir / "example_user_rules.yaml"),
"plan",
str(data_dir / "input" / "tiff" / "test_image.tif"),
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def base_rule_set():

@pytest.fixture
def override_rule_set(rules_dir: Path):
rule_file = rules_dir / "example_user_rules.yml"
rule_file = rules_dir / "example_user_rules.yaml"
with rule_file.open() as rule_stream:
return Ruleset.parse_obj(yaml.safe_load(rule_stream))

Expand Down
11 changes: 10 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minversion = 4
env_list =
lint,
type,
test
test,

[testenv]
base_python = python3.11
Expand All @@ -20,17 +20,21 @@ deps =
flake8-docstrings
flake8-isort
pep8-naming
yamlfix
commands =
flake8 {posargs:.}
yamlfix -c pyproject.toml --exclude ./build/**/* --exclude ./client/node_modules/**/* . --check

[testenv:format]
package = skip
deps =
black
isort
yamlfix
commands =
isort {posargs:.}
black {posargs:.}
yamlfix -c pyproject.toml --exclude ./build/**/* --exclude ./client/node_modules/**/* .

[testenv:type]
# Editable ensures dependencies are installed, but full packaging isn't necessary
Expand Down Expand Up @@ -92,3 +96,8 @@ ignore =
D10,
# Multiple statements on one line (https://github.com/psf/black/issues/3887)
E704,

[yamlfix]
line_length = 200
preserve_quotes = True
sequence_style = YamlNodeStyle.BLOCK_STYLE

0 comments on commit eef8a6c

Please sign in to comment.