Skip to content

Commit

Permalink
Merge pull request #102 from neutrinoceros/better_invalidate
Browse files Browse the repository at this point in the history
BUG: fix section invalidation
  • Loading branch information
neutrinoceros authored Apr 9, 2022
2 parents bc73bc1 + e7b9122 commit d809335
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.2.1] - 2022-04-09

BUG: fix section invalidation

## [1.2.0] - 2022-03-18

- ENH: add two functions to the public API to read from and write to strings (`inifix.loads` and `inifix.dumps`)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ This simple validator can be used as a hook for `pre-commit`. Simply add the
following to your project's `.pre-commit-config.yaml`
```yaml
- repo: https://github.com/neutrinoceros/inifix.git
rev: v1.2.0
rev: v1.2.1
hooks:
- id: inifix-validate
```
Expand Down
2 changes: 1 addition & 1 deletion inifix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .io import loads
from .validation import validate_inifile_schema

__version__ = "1.2.0"
__version__ = "1.2.1"
6 changes: 3 additions & 3 deletions inifix/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

__all__ = ["load", "dump"]

SECTION_REGEXP = re.compile(r"\[.+\]\s*")
SECTION_REGEXP = re.compile(r"\[(?P<title>[^(){}\[\]]+)\]\s*")


def bool_caster(s: str) -> bool:
Expand Down Expand Up @@ -140,11 +140,11 @@ def _from_string(data: str, file: Optional[TextIO] = None) -> InifixConfT:
for line_number, line in enumerate(lines, start=1):
if not line:
continue
match = re.match(SECTION_REGEXP, line)
match = re.fullmatch(SECTION_REGEXP, line)
if match is not None:
if section:
section._dump_to(container)
section = Section(name=match.group().strip("[]"))
section = Section(name=match["title"])
continue

values: Union[Scalar, List[Scalar]]
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = inifix
version = 1.2.0
version = 1.2.1
description = I/O facility for Idefix/Pluto configuration files
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -35,7 +35,6 @@ console_scripts =

[options.extras_require]
dev =
pre-commit
pytest>=6.1
typecheck =
mypy==0.931
Expand Down
7 changes: 6 additions & 1 deletion tests/test_file_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
(r"/!\\\n", "invalid param name (special chars)"),
("100 100\n", "invalid param name (num-1)"),
("1e2 100\n", "invalid param name (num-2)"),
(("[Unclosed Section\n" "a 1 2 3\n"), "unclosed section"),
("[Unclosed Section\na 1 2 3\n", "unclosed section"),
("[[extra left bracket]\na 1 2 3\n", "mismatched left bracket"),
("[extra right bracket]]\na 1 2 3\n", "mismatched right bracket"),
("[extra] stuff that's not a comment", "missing comment char"),
("[()]", "invalid section chars (parens)"),
("[{}]", "invalid section chars (brackets)"),
)
)

Expand Down

0 comments on commit d809335

Please sign in to comment.