Skip to content

Commit

Permalink
Rename configuration knob to better describe its purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankSpruce committed Aug 4, 2024
1 parent 7cca1f7 commit 440cad1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gersemirc.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ indent: 4
line_length: 80
list_expansion: favour-inlining
quiet: false
require_definitions: true
unsafe: false
warn_about_unknown_commands: true
workers: 8
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Changelog
## [0.15.0] 2024-08-04
### Added
- cache can be disabled through `--no-cache`/`cache: false`, cache is still enabled by default
- warnings about unknown commands can be suppressed through `--no-warn-about-unknown-commands`/`warn_about_unknown_commands: false`, warnings are enabled by default

### Fixed
- only those files that were checked or formatted without warning will be cached

## [0.14.0] 2024-07-15
### Added
- warnings about unknown commands when `quiet` isn't used
Expand Down
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ usage: gersemi [-c] [-i] [--diff] [--default-config] [--version] [-h] [-l INTEGE
[--indent (INTEGER | tabs)] [--unsafe] [-q] [--color]
[--definitions src [src ...]]
[--list-expansion {favour-inlining,favour-expansion}] [-w INTEGER]
[--cache] [--require-definitions]
[--cache] [--warn-about-unknown-commands]
[src ...]
A formatter to make your CMake code the real treasure.
Expand Down Expand Up @@ -75,13 +75,11 @@ configuration:
--cache, --no-cache Enables cache with data about files that are known to be
formatted to speed up execution.
[default: cache enabled]
--require-definitions, --no-require-definitions
Require definitions of custom commands. When enabled file which
has unknown custom commands will have warnings issued about
that and result won't be cached. When disabled it will be
assumed that original formatting of unknown command is the
correct one. See: "Let's make a deal" section in README.
[default: definitions are required]
--warn-about-unknown-commands, --no-warn-about-unknown-commands
When enabled file which has unknown custom commands will have
warnings issued about that and result won't be cached.
See: "Let's make a deal" section in README.
[default: warnings enabled]
```

### [pre-commit](https://pre-commit.com/) hook
Expand All @@ -91,7 +89,7 @@ You can use gersemi with a pre-commit hook by adding the following to `.pre-comm
```yaml
repos:
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.14.0
rev: 0.15.0
hooks:
- id: gersemi
```
Expand Down
10 changes: 5 additions & 5 deletions gersemi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ def create_argparser():
""",
)
configuration_group.add_argument(
"--require-definitions",
"--no-require-definitions",
dest="require_definitions",
"--warn-about-unknown-commands",
"--no-warn-about-unknown-commands",
dest="warn_about_unknown_commands",
action=ToggleAction,
nargs=0,
default=None,
help=f"""
{conf_doc["require_definitions"]}
[default: definitions are required]
{conf_doc["warn_about_unknown_commands"]}
[default: warnings enabled]
""",
)

Expand Down
2 changes: 1 addition & 1 deletion gersemi/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
__license__ = "MPL 2.0"
__title__ = "gersemi"
__url__ = "https://github.com/BlankSpruce/gersemi"
__version__ = "0.14.0"
__version__ = "0.15.0"
12 changes: 5 additions & 7 deletions gersemi/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,15 @@ class Configuration: # pylint: disable=too-many-instance-attributes
),
)

require_definitions: bool = field(
warn_about_unknown_commands: bool = field(
default=True,
metadata=dict(
title="Require definitions",
title="Warn about unknown commands",
description=doc(
"""
Require definitions of custom commands. When enabled
file which has unknown custom commands will have warnings
issued about that and result won't be cached. When disabled
it will be assumed that original formatting of unknown command
is the correct one. See: "Let's make a deal" section in README.
When enabled file which has unknown custom commands will have warnings
issued about that and result won't be cached. See: "Let's make a deal"
section in README.
"""
),
),
Expand Down
6 changes: 3 additions & 3 deletions gersemi/configuration.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
"title": "Enable cache",
"type": "boolean"
},
"require_definitions": {
"warn_about_unknown_commands": {
"default": true,
"description": "Require definitions of custom commands. When enabled file which has unknown custom commands will have warnings issued about that and result won't be cached. When disabled it will be assumed that original formatting of unknown command is the correct one. See: \"Let's make a deal\" section in README.",
"title": "Require definitions",
"description": "When enabled file which has unknown custom commands will have warnings issued about that and result won't be cached. See: \"Let's make a deal\" section in README.",
"title": "Warn about unknown commands",
"type": "boolean"
}
},
Expand Down
2 changes: 1 addition & 1 deletion gersemi/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def consume_task_result(

warnings = (
[w for w in task_result.warnings if not isinstance(w, UnknownCommandWarning)]
if not configuration.require_definitions
if not configuration.warn_about_unknown_commands
else task_result.warnings
)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,9 @@ def check_warnings(result, stderr):
[
((), False),
(("--check",), True),
(("--require-definitions", "--check"), True),
(("--warn-about-unknown-commands", "--check"), True),
(("--in-place",), True),
(("--require-definitions", "--in-place"), True),
(("--warn-about-unknown-commands", "--in-place"), True),
(("--diff",), False),
],
)
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def test_dont_warn_about_unknown_commands_when_definition_arent_required(

cmakelists = Path(target) / "CMakeLists.txt"
without_definition = gersemi_(
*args, "--no-require-definitions", cmakelists, cwd=tmpdir
*args, "--no-warn-about-unknown-commands", cmakelists, cwd=tmpdir
)
assert without_definition.returncode == 0, (
without_definition.returncode,
Expand All @@ -1053,7 +1053,7 @@ def test_dont_warn_about_unknown_commands_when_definition_arent_required(
inspector.assert_that_has_no_tables()

cmakelists = Path(target) / "CMakeLists.txt"
with create_dot_gersemirc(where=target, require_definitions=False):
with create_dot_gersemirc(where=target, warn_about_unknown_commands=False):
without_definition = gersemi_(*args, cmakelists, cwd=tmpdir)
assert without_definition.returncode == 0, (
without_definition.returncode,
Expand All @@ -1071,9 +1071,9 @@ def test_dont_warn_about_unknown_commands_when_definition_arent_required(
inspector.assert_that_has_no_tables()

cmakelists = Path(target) / "CMakeLists.txt"
with create_dot_gersemirc(where=target, require_definitions=True):
with create_dot_gersemirc(where=target, warn_about_unknown_commands=True):
without_definition = gersemi_(
*args, "--no-require-definitions", cmakelists, cwd=tmpdir
*args, "--no-warn-about-unknown-commands", cmakelists, cwd=tmpdir
)
assert without_definition.returncode == 0, (
without_definition.returncode,
Expand Down

0 comments on commit 440cad1

Please sign in to comment.