Skip to content

Commit

Permalink
Version 6.10.0 (#232)
Browse files Browse the repository at this point in the history
* Adding Python 3.11 support
* Adding #195 box_from_string function (thanks to Marcelo Huerta)
* Changing the deprecated ``toml`` package with modern ``tomllib``, ``tomli`` and ``tomli-w`` usage (thanks to Michał Górny)
* Fixing mypy __ior__ type (thanks to Jacob Hayes)
* Fixing line endings with a pre-commit update
* Fixing BoxList was using old style of `super` in internal code usage

Co-authored-by: Jacob Hayes <[email protected]>
Co-authored-by: Michał Górny <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2022
1 parent f15fa1b commit f5c326c
Show file tree
Hide file tree
Showing 24 changed files with 233 additions and 94 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -34,13 +34,13 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -58,15 +58,15 @@ jobs:
deploy-cython-manylinux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: "3.10"

- uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310'
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311'
build-requirements: 'cython'

- name: Install dependencies
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
package-checks:
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "pypy-3.8"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy-3.8"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
Expand Down Expand Up @@ -66,9 +66,9 @@ jobs:
package-manylinux-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: "3.10"

Expand All @@ -85,7 +85,7 @@ jobs:
- uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310'
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311'
build-requirements: 'cython'

- name: Test packaged wheel on linux
Expand All @@ -103,13 +103,13 @@ jobs:
test:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
# Identify invalid files
- id: check-ast
Expand Down Expand Up @@ -29,7 +29,7 @@ repos:
exclude: ^test/data/.+

- repo: https://github.com/ambv/black
rev: 22.1.0
rev: 22.10.0
hooks:
- id: black
args: [--config=.black.toml]
Expand All @@ -51,8 +51,8 @@ repos:
always_run: true

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.931'
rev: 'v0.982'
hooks:
- id: mypy
types: [python]
additional_dependencies: [ruamel.yaml,toml,msgpack,types-PyYAML,types-toml]
additional_dependencies: [ruamel.yaml,toml,types-toml,tomli,tomli-w,msgpack,types-PyYAML]
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Code contributions:
- Jacob Hayes (JacobHayes)
- Dominic (Yobmod)
- Ivan Pepelnjak (ipspace)
- Michał Górny (mgorny)

Suggestions and bug reporting:

Expand Down
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Changelog
=========

Version 6.1.0
-------------

* Adding Python 3.11 support
* Adding #195 box_from_string function (thanks to Marcelo Huerta)
* Changing the deprecated ``toml`` package with modern ``tomllib``, ``tomli`` and ``tomli-w`` usage (thanks to Michał Górny)
* Fixing mypy __ior__ type (thanks to Jacob Hayes)
* Fixing line endings with a pre-commit update
* Fixing BoxList was using old style of `super` in internal code usage

Version 6.0.2
-------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ But you can also sub out `ruamel.yaml` for `PyYAML`.

Check out `more details <https://github.com/cdgriffith/Box/wiki/Installation>`_ on installation details.

Box 6 is tested on python 3.6+, if you are upgrading from previous versions, please look through
Box 6 is tested on python 3.7+, if you are upgrading from previous versions, please look through
`any breaking changes and new features <https://github.com/cdgriffith/Box/wiki/Major-Version-Breaking-Changes>`_.

Optimized Version
Expand Down
4 changes: 2 additions & 2 deletions box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# -*- coding: utf-8 -*-

__author__ = "Chris Griffith"
__version__ = "6.0.2"
__version__ = "6.1.0"

from box.box import Box
from box.box_list import BoxList
from box.config_box import ConfigBox
from box.exceptions import BoxError, BoxKeyError
from box.from_file import box_from_file
from box.from_file import box_from_file, box_from_string
from box.shorthand_box import SBox
import box.converters

Expand Down
19 changes: 12 additions & 7 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
_to_toml,
_to_yaml,
msgpack_available,
toml_available,
toml_read_library,
toml_write_library,
yaml_available,
)
from box.exceptions import BoxError, BoxKeyError, BoxTypeError, BoxValueError, BoxWarning
Expand Down Expand Up @@ -301,7 +302,7 @@ def __ror__(self, other: Mapping[Any, Any]):
new_box.update(other)
return new_box

def __ior__(self, other: Mapping[Any, Any]):
def __ior__(self, other: Mapping[Any, Any]): # type: ignore[override]
if not isinstance(other, dict):
raise BoxTypeError("Box can only merge two boxes or a box and a dictionary.")
self.update(other)
Expand Down Expand Up @@ -954,7 +955,7 @@ def from_yaml(
) -> "Box":
raise BoxError('yaml is unavailable on this system, please install the "ruamel.yaml" or "PyYAML" package')

if toml_available:
if toml_write_library is not None:

def to_toml(self, filename: Union[str, PathLike] = None, encoding: str = "utf-8", errors: str = "strict"):
"""
Expand All @@ -967,6 +968,13 @@ def to_toml(self, filename: Union[str, PathLike] = None, encoding: str = "utf-8"
"""
return _to_toml(self.to_dict(), filename=filename, encoding=encoding, errors=errors)

else:

def to_toml(self, filename: Union[str, PathLike] = None, encoding: str = "utf-8", errors: str = "strict"):
raise BoxError('toml is unavailable on this system, please install the "tomli-w" package')

if toml_read_library is not None:

@classmethod
def from_toml(
cls,
Expand Down Expand Up @@ -996,9 +1004,6 @@ def from_toml(

else:

def to_toml(self, filename: Union[str, PathLike] = None, encoding: str = "utf-8", errors: str = "strict"):
raise BoxError('toml is unavailable on this system, please install the "toml" package')

@classmethod
def from_toml(
cls,
Expand All @@ -1008,7 +1013,7 @@ def from_toml(
errors: str = "strict",
**kwargs,
) -> "Box":
raise BoxError('toml is unavailable on this system, please install the "toml" package')
raise BoxError('toml is unavailable on this system, please install the "tomli" package')

if msgpack_available:

Expand Down
2 changes: 1 addition & 1 deletion box/box.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Box(dict):
def __iadd__(self, other: Mapping[Any, Any]) -> Any: ...
def __or__(self, other: Mapping[Any, Any]) -> Any: ...
def __ror__(self, other: Mapping[Any, Any]) -> Any: ...
def __ior__(self, other: Mapping[Any, Any]) -> Any: ...
def __ior__(self, other: Mapping[Any, Any]) -> Any: ... # type: ignore[override]
def __sub__(self, other: Mapping[Any, Any]) -> Any: ...
def __hash__(self) -> Any: ... # type: ignore[override]
def __dir__(self): ...
Expand Down
45 changes: 25 additions & 20 deletions box/box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
_to_toml,
_to_yaml,
msgpack_available,
toml_available,
toml_read_library,
toml_write_library,
yaml_available,
)
from box.exceptions import BoxError, BoxTypeError
Expand Down Expand Up @@ -61,11 +62,11 @@ def frozen(*args, **kwargs):
def __getitem__(self, item):
if self.box_options.get("box_dots") and isinstance(item, str) and item.startswith("["):
list_pos = _list_pos_re.search(item)
value = super(BoxList, self).__getitem__(int(list_pos.groups()[0]))
value = super().__getitem__(int(list_pos.groups()[0]))
if len(list_pos.group()) == len(item):
return value
return value.__getitem__(item[len(list_pos.group()) :].lstrip("."))
return super(BoxList, self).__getitem__(item)
return super().__getitem__(item)

def __delitem__(self, key):
if self.box_options.get("frozen_box"):
Expand All @@ -74,10 +75,10 @@ def __delitem__(self, key):
list_pos = _list_pos_re.search(key)
pos = int(list_pos.groups()[0])
if len(list_pos.group()) == len(key):
return super(BoxList, self).__delitem__(pos)
return super().__delitem__(pos)
if hasattr(self[pos], "__delitem__"):
return self[pos].__delitem__(key[len(list_pos.group()) :].lstrip(".")) # type: ignore
super(BoxList, self).__delitem__(key)
super().__delitem__(key)

def __setitem__(self, key, value):
if self.box_options.get("frozen_box"):
Expand All @@ -86,9 +87,9 @@ def __setitem__(self, key, value):
list_pos = _list_pos_re.search(key)
pos = int(list_pos.groups()[0])
if len(list_pos.group()) == len(key):
return super(BoxList, self).__setitem__(pos, value)
return super(BoxList, self).__getitem__(pos).__setitem__(key[len(list_pos.group()) :].lstrip("."), value)
super(BoxList, self).__setitem__(key, value)
return super().__setitem__(pos, value)
return super().__getitem__(pos).__setitem__(key[len(list_pos.group()) :].lstrip("."), value)
super().__setitem__(key, value)

def _is_intact_type(self, obj):
if self.box_options.get("box_intact_types") and isinstance(obj, self.box_options["box_intact_types"]):
Expand All @@ -107,14 +108,14 @@ def _convert(self, p_object):
return p_object

def append(self, p_object):
super(BoxList, self).append(self._convert(p_object))
super().append(self._convert(p_object))

def extend(self, iterable):
for item in iterable:
self.append(item)

def insert(self, index, p_object):
super(BoxList, self).insert(index, self._convert(p_object))
super().insert(index, self._convert(p_object))

def _dotted_helper(self):
keys = []
Expand Down Expand Up @@ -312,7 +313,7 @@ def from_yaml(
):
raise BoxError('yaml is unavailable on this system, please install the "ruamel.yaml" or "PyYAML" package')

if toml_available:
if toml_read_library is not None:

def to_toml(
self,
Expand All @@ -333,6 +334,19 @@ def to_toml(
"""
return _to_toml({key_name: self.to_list()}, filename=filename, encoding=encoding, errors=errors)

else:

def to_toml(
self,
filename: Union[str, PathLike] = None,
key_name: str = "toml",
encoding: str = "utf-8",
errors: str = "strict",
):
raise BoxError('toml is unavailable on this system, please install the "tomli-w" package')

if toml_read_library is not None:

@classmethod
def from_toml(
cls,
Expand Down Expand Up @@ -367,15 +381,6 @@ def from_toml(

else:

def to_toml(
self,
filename: Union[str, PathLike] = None,
key_name: str = "toml",
encoding: str = "utf-8",
errors: str = "strict",
):
raise BoxError('toml is unavailable on this system, please install the "toml" package')

@classmethod
def from_toml(
cls,
Expand Down
9 changes: 5 additions & 4 deletions box/box_list.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import box
from box.converters import (
BOX_PARAMETERS as BOX_PARAMETERS,
msgpack_available as msgpack_available,
toml_available as toml_available,
yaml_available as yaml_available,
BOX_PARAMETERS,
msgpack_available,
yaml_available,
toml_read_library,
toml_write_library,
)
from box.exceptions import BoxError as BoxError, BoxTypeError as BoxTypeError
from os import PathLike as PathLike
Expand Down
Loading

0 comments on commit f5c326c

Please sign in to comment.