Skip to content

Commit

Permalink
Merge pull request #91 from neutrinoceros/rel_1.0
Browse files Browse the repository at this point in the history
REL: release 1.0.0
  • Loading branch information
neutrinoceros authored Jan 15, 2022
2 parents 710105f + e24cc72 commit 6858cc8
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 359 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: '3.8'
- name: Install build dependencies
run: python -m pip install build wheel
- name: Build distributions
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [
'3.6',
'3.7',
'3.8',
'3.9',
'3.10',
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ repos:
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
hooks:
- id: mypy
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
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.0.0] - 2022-01-15

The API is now declared stable and any future intentionally breaking change
will follow a deprecation cycle.

- DEPR: drop support for Python 3.6 and 3.7, inifix now requires Python 3.8 or newer
- DEPR: end deprecation cycle for function arguments marked as "future-potisional-only"
- ENH: simplify internal logic (remove a non-user facing class, InifixConf)
- TYP: add mypy conf, add missing type annotations


https://github.com/neutrinoceros/inifix/pull/91

## [0.11.2] - 2022-01-05

BUG: fix formatting for files with only sections and comments (no parameters)
Expand Down
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `inifix`

[![PyPI](https://img.shields.io/pypi/v/inifix.svg?logo=pypi&logoColor=white&label=PyPI)](https://pypi.org/project/inifix/)
[![PyPI](https://img.shields.io/pypi/pyversions/inifix/0.7.0?logo=python&logoColor=white&label=Python)](https://pypi.org/project/inifix/)
[![PyPI](https://img.shields.io/pypi/pyversions/inifix/1.0.0?logo=python&logoColor=white&label=Python)](https://pypi.org/project/inifix/)
[![codecov](https://codecov.io/gh/neutrinoceros/inifix/branch/main/graph/badge.svg)](https://codecov.io/gh/neutrinoceros/inifix)
[![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)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Expand All @@ -18,7 +18,7 @@ supports section-free definitions.


## File format specifications

<details><summary>Unroll !</summary>
- parameter names are strings
- names and values are separated by non-newline white spaces
- values are represented in unicode characters
Expand Down Expand Up @@ -92,39 +92,44 @@ e-notation is prefered in encoding.

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

## Installation

```shell
$ pip install inifix
pip install inifix
```

## Usage

The Python API is similar to that of `toml` and stdlib `json`, though
intentionally simplified, and consists in two main user-facing functions:
`inifix.load` and `inifix.dump`.
The public API mimicks that of Python's standard library `json`,
and consists in two main functions: `inifix.load` and `inifix.dump`.


### Reading data
`inifix.load` reads from a file and returns a `dict`

```python
import inifix

# read
with open("pluto.ini") as fh:
conf = inifix.load(fh)

# or equivalently
conf = inifix.load("pluto.ini")
```

# patch
conf["Time"]["CFL"] = 0.1
### ... and writing back to disk

# write back
inifix.dump(conf, "pluto-mod.ini")
```
`inifix.dumps` allows to write back to a file.

`inifix.load` supports loading from an open file
This allows to change a value on the fly and create new
configuration files programmatically, for instance.
```python
with open("pluto.ini") as fh:
conf = inifix.load(fh)
conf["Time"]["CFL"] = 0.1
inifix.dump(conf, "pluto-mod.ini")
```
or from a `str/os.PathLike` object representing a file.

Data will be validated against inifix's format specification at write time.

### Schema Validation

Expand Down
2 changes: 1 addition & 1 deletion inifix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .io import load
from .validation import validate_inifile_schema

__version__ = "0.11.2"
__version__ = "1.0.0"
29 changes: 0 additions & 29 deletions inifix/_deprecation.py

This file was deleted.

16 changes: 12 additions & 4 deletions inifix/_typing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import os
import sys
from typing import AnyStr
from typing import Dict
from typing import Iterable
from typing import Mapping
from typing import Optional
from typing import TypeVar
from typing import Union

T = TypeVar("T")
Scalar = Union[int, float, bool, str]
IterableOrSingle = Union[Iterable[T], T]
PathLike = Union[str, bytes, os.PathLike]

Section = Mapping[str, IterableOrSingle[Scalar]]
InifixParsable = Mapping[str, Union[Section, Scalar]]
if sys.version_info > (3, 9):
PathLike = Union[AnyStr, os.PathLike[AnyStr]]
else:
PathLike = Union[AnyStr, os.PathLike]

# these types are used to validate schemas internally at type-checking time
SectionT = Dict[str, IterableOrSingle[Scalar]]
InifixConfT = Dict[Optional[str], SectionT]
17 changes: 6 additions & 11 deletions inifix/enotation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from typing import Union

from inifix._deprecation import future_positional_only

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

Expand All @@ -13,8 +12,7 @@ class ENotationIO:
"""

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

digits, _, exponent = s.partition("e")
exponent = int(exponent)
digits, _, sexponent = s.partition("e")
exponent = int(sexponent)
if "." in digits:
digits, decimals = digits.split(".")
decimals = decimals.rstrip("0")
Expand All @@ -68,8 +66,7 @@ def decode(s: str) -> int:
return int(float(s))

@staticmethod
@future_positional_only({0: "s"})
def simplify(s: str) -> str:
def simplify(s: str, /) -> str:
"""
Simplify exponents and trailing zeros in decimals.
This is a helper function to `ENotationIO.encode`.
Expand All @@ -94,8 +91,7 @@ def simplify(s: str) -> str:
return s.replace("+", "")

@staticmethod
@future_positional_only({0: "r"})
def encode(r: Union[float, int]) -> str:
def encode(r: Union[float, int], /) -> str:
"""
Convert a real number `r` to string, using scientific notation.
Expand Down Expand Up @@ -144,8 +140,7 @@ def encode(r: Union[float, int]) -> str:
return ENotationIO.simplify(s)

@staticmethod
@future_positional_only({0: "r"})
def encode_preferential(r: Union[float, int]) -> str:
def encode_preferential(r: Union[float, int], /) -> str:
"""
Convert a real number `r` to string, using sci notation if
and only if it saves space.
Expand Down
Loading

0 comments on commit 6858cc8

Please sign in to comment.