Skip to content

Commit 6858cc8

Browse files
Merge pull request #91 from neutrinoceros/rel_1.0
REL: release 1.0.0
2 parents 710105f + e24cc72 commit 6858cc8

22 files changed

Lines changed: 437 additions & 359 deletions

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup Python
1212
uses: actions/setup-python@v2
1313
with:
14-
python-version: 3.6
14+
python-version: '3.8'
1515
- name: Install build dependencies
1616
run: python -m pip install build wheel
1717
- name: Build distributions

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313
matrix:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515
python-version: [
16-
'3.6',
17-
'3.7',
1816
'3.8',
1917
'3.9',
2018
'3.10',

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ repos:
4242
hooks:
4343
- id: flake8
4444
additional_dependencies: [flake8-bugbear]
45+
46+
- repo: https://github.com/pre-commit/mirrors-mypy
47+
rev: v0.931
48+
hooks:
49+
- id: mypy

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
8+
## [1.0.0] - 2022-01-15
9+
10+
The API is now declared stable and any future intentionally breaking change
11+
will follow a deprecation cycle.
12+
13+
- DEPR: drop support for Python 3.6 and 3.7, inifix now requires Python 3.8 or newer
14+
- DEPR: end deprecation cycle for function arguments marked as "future-potisional-only"
15+
- ENH: simplify internal logic (remove a non-user facing class, InifixConf)
16+
- TYP: add mypy conf, add missing type annotations
17+
18+
19+
https://github.com/neutrinoceros/inifix/pull/91
20+
721
## [0.11.2] - 2022-01-05
822

923
BUG: fix formatting for files with only sections and comments (no parameters)

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# `inifix`
22

33
[![PyPI](https://img.shields.io/pypi/v/inifix.svg?logo=pypi&logoColor=white&label=PyPI)](https://pypi.org/project/inifix/)
4-
[![PyPI](https://img.shields.io/pypi/pyversions/inifix/0.7.0?logo=python&logoColor=white&label=Python)](https://pypi.org/project/inifix/)
4+
[![PyPI](https://img.shields.io/pypi/pyversions/inifix/1.0.0?logo=python&logoColor=white&label=Python)](https://pypi.org/project/inifix/)
55
[![codecov](https://codecov.io/gh/neutrinoceros/inifix/branch/main/graph/badge.svg)](https://codecov.io/gh/neutrinoceros/inifix)
66
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/neutrinoceros/inifix/main.svg)](https://results.pre-commit.ci/badge/github/neutrinoceros/inifix/main.svg)
77
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
@@ -18,7 +18,7 @@ supports section-free definitions.
1818

1919

2020
## File format specifications
21-
21+
<details><summary>Unroll !</summary>
2222
- parameter names are strings
2323
- names and values are separated by non-newline white spaces
2424
- values are represented in unicode characters
@@ -92,39 +92,44 @@ e-notation is prefered in encoding.
9292

9393
While decoding, `e` can be lower or upper case, but they are always encoded as
9494
lower case.
95+
</details>
9596

9697
## Installation
9798

9899
```shell
99-
$ pip install inifix
100+
pip install inifix
100101
```
101102

102103
## Usage
103104

104-
The Python API is similar to that of `toml` and stdlib `json`, though
105-
intentionally simplified, and consists in two main user-facing functions:
106-
`inifix.load` and `inifix.dump`.
105+
The public API mimicks that of Python's standard library `json`,
106+
and consists in two main functions: `inifix.load` and `inifix.dump`.
107+
108+
109+
### Reading data
110+
`inifix.load` reads from a file and returns a `dict`
107111

108112
```python
109113
import inifix
110114

111-
# read
115+
with open("pluto.ini") as fh:
116+
conf = inifix.load(fh)
117+
118+
# or equivalently
112119
conf = inifix.load("pluto.ini")
120+
```
113121

114-
# patch
115-
conf["Time"]["CFL"] = 0.1
122+
### ... and writing back to disk
116123

117-
# write back
118-
inifix.dump(conf, "pluto-mod.ini")
119-
```
124+
`inifix.dumps` allows to write back to a file.
120125

121-
`inifix.load` supports loading from an open file
126+
This allows to change a value on the fly and create new
127+
configuration files programmatically, for instance.
122128
```python
123-
with open("pluto.ini") as fh:
124-
conf = inifix.load(fh)
129+
conf["Time"]["CFL"] = 0.1
130+
inifix.dump(conf, "pluto-mod.ini")
125131
```
126-
or from a `str/os.PathLike` object representing a file.
127-
132+
Data will be validated against inifix's format specification at write time.
128133

129134
### Schema Validation
130135

inifix/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from .io import load
33
from .validation import validate_inifile_schema
44

5-
__version__ = "0.11.2"
5+
__version__ = "1.0.0"

inifix/_deprecation.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

inifix/_typing.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import os
2+
import sys
3+
from typing import AnyStr
4+
from typing import Dict
25
from typing import Iterable
3-
from typing import Mapping
6+
from typing import Optional
47
from typing import TypeVar
58
from typing import Union
69

710
T = TypeVar("T")
811
Scalar = Union[int, float, bool, str]
912
IterableOrSingle = Union[Iterable[T], T]
10-
PathLike = Union[str, bytes, os.PathLike]
1113

12-
Section = Mapping[str, IterableOrSingle[Scalar]]
13-
InifixParsable = Mapping[str, Union[Section, Scalar]]
14+
if sys.version_info > (3, 9):
15+
PathLike = Union[AnyStr, os.PathLike[AnyStr]]
16+
else:
17+
PathLike = Union[AnyStr, os.PathLike]
18+
19+
# these types are used to validate schemas internally at type-checking time
20+
SectionT = Dict[str, IterableOrSingle[Scalar]]
21+
InifixConfT = Dict[Optional[str], SectionT]

inifix/enotation.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
from typing import Union
33

4-
from inifix._deprecation import future_positional_only
54

65
ENOTATION_REGEXP = re.compile(r"\d+(\.\d*)?e[+-]?\d+?")
76

@@ -13,8 +12,7 @@ class ENotationIO:
1312
"""
1413

1514
@staticmethod
16-
@future_positional_only({0: "s"})
17-
def decode(s: str) -> int:
15+
def decode(s: str, /) -> int:
1816
"""
1917
Cast an 'e' formatted string `s` to integer if such a conversion can
2018
be perfomed without loss of data. Raise ValueError otherwise.
@@ -52,8 +50,8 @@ def decode(s: str) -> int:
5250
if not re.match(ENOTATION_REGEXP, s):
5351
raise ValueError
5452

55-
digits, _, exponent = s.partition("e")
56-
exponent = int(exponent)
53+
digits, _, sexponent = s.partition("e")
54+
exponent = int(sexponent)
5755
if "." in digits:
5856
digits, decimals = digits.split(".")
5957
decimals = decimals.rstrip("0")
@@ -68,8 +66,7 @@ def decode(s: str) -> int:
6866
return int(float(s))
6967

7068
@staticmethod
71-
@future_positional_only({0: "s"})
72-
def simplify(s: str) -> str:
69+
def simplify(s: str, /) -> str:
7370
"""
7471
Simplify exponents and trailing zeros in decimals.
7572
This is a helper function to `ENotationIO.encode`.
@@ -94,8 +91,7 @@ def simplify(s: str) -> str:
9491
return s.replace("+", "")
9592

9693
@staticmethod
97-
@future_positional_only({0: "r"})
98-
def encode(r: Union[float, int]) -> str:
94+
def encode(r: Union[float, int], /) -> str:
9995
"""
10096
Convert a real number `r` to string, using scientific notation.
10197
@@ -144,8 +140,7 @@ def encode(r: Union[float, int]) -> str:
144140
return ENotationIO.simplify(s)
145141

146142
@staticmethod
147-
@future_positional_only({0: "r"})
148-
def encode_preferential(r: Union[float, int]) -> str:
143+
def encode_preferential(r: Union[float, int], /) -> str:
149144
"""
150145
Convert a real number `r` to string, using sci notation if
151146
and only if it saves space.

0 commit comments

Comments
 (0)