Skip to content

Commit

Permalink
Version 5.1.1
Browse files Browse the repository at this point in the history
Bugfix dots default (#166)
  • Loading branch information
cdgriffith authored Aug 20, 2020
1 parent 69db25b commit 4b66113
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 74 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Tests

on:
push:
branches: [ master, development ]
branches: [ master, development, develop, test, tests ]
pull_request:
branches: [ master, development ]
branches: [ master, development, develop, test, tests ]

jobs:
package_checks:
Expand Down Expand Up @@ -45,12 +45,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, pypy3]
python-version: [3.6, 3.7, 3.8, 3.9.0-rc.1, pypy3]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: debug-statements
- id: check-yaml
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: stable
hooks:
- id: black
args: [--config=.black.toml]
Expand Down
23 changes: 14 additions & 9 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
Changelog
=========

Version 5.1.1
-------------

* Adding testing for Python 3.9
* Fixing #165 `box_dots` to work with `default_box`

Version 5.1.0
-------------

* Adding `dotted` option for `items` function (thanks to ipcoder)
* Fixing bug in box.set_default where value is dictionary, return the internal value and not detached temporary (thanks to Noam Graetz)
* Adding #152 `dotted` option for `items` function (thanks to ipcoder)
* Fixing #157 bug in box.set_default where value is dictionary, return the internal value and not detached temporary (thanks to Noam Graetz)
* Removing warnings on import if optional libraries are missing

Version 5.0.1
-------------

* Fixing default box saving internal method calls and restricted options (thanks to Marcelo Huerta)
* Fixing #155 default box saving internal method calls and restricted options (thanks to Marcelo Huerta)

Version 5.0.0
-------------

* Adding support for msgpack converters `to_msgpack` and `from_msgpack`
* Adding support for comparision of `Box` to other boxes or dicts via the `-` sub operator #144 (thanks to Hitz)
* Adding #144 support for comparision of `Box` to other boxes or dicts via the `-` sub operator (thanks to Hitz)
* Adding support to `|` union boxes like will come default in Python 3.9 from PEP 0584
* Adding `mypy` type checking, `black` formatting and other checks on commit
* Adding new parameter `box_class` for cleaner inheritance #148 (thanks to David Aronchick)
* Adding `dotted` option for `keys` method to return box_dots style keys (thanks to ipcoder)
* Adding #148 new parameter `box_class` for cleaner inheritance (thanks to David Aronchick)
* Adding #152 `dotted` option for `keys` method to return box_dots style keys (thanks to ipcoder)
* Fixing box_dots to properly delete items from lists
* Fixing box_dots to properly find items with dots in their key
* Fixing that recast of subclassses of `Box` or `BoxList` were not fed box properties (thanks to Alexander Kapustin)
* Changing that sub boxes are always created to properly propagate settings and copy objects #150 (thanks to ipcoder)
* Changing that default_box will not raise key errors on `pop` #67 (thanks to Patrock)
* Changing #150 that sub boxes are always created to properly propagate settings and copy objects (thanks to ipcoder)
* Changing #67 that default_box will not raise key errors on `pop` (thanks to Patrock)
* Changing `to_csv` and `from_csv` to have same string and filename options as all other transforms
* Changing back to no required external imports, instead have extra requires like [all] (thanks to wim glenn)
* Changing #127 back to no required external imports, instead have extra requires like [all] (thanks to wim glenn)
* Changing from putting all details in README.rst to a github wiki at https://github.com/cdgriffith/Box/wiki
* Changing `BoxList.box_class` to be stored in `BoxList.box_options` dict as `box_class`
* Changing `del` will raise `BoxKeyError`, subclass of both `KeyError` and `BoxError`
Expand Down
4 changes: 2 additions & 2 deletions box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# -*- coding: utf-8 -*-

__author__ = "Chris Griffith"
__version__ = "5.1.0"
__version__ = "5.1.1"

from box.box import Box
from box.box_list import BoxList
from box.config_box import ConfigBox
from box.shorthand_box import SBox
from box.exceptions import BoxError, BoxKeyError
from box.from_file import box_from_file
from box.shorthand_box import SBox
28 changes: 16 additions & 12 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@
import re
import string
import warnings
from os import PathLike
from collections.abc import Iterable, Mapping, Callable
from collections.abc import Callable, Iterable, Mapping
from keyword import kwlist
from typing import Any, Union, Tuple, List, Dict, Generator

from os import PathLike
from typing import Any, Dict, Generator, List, Tuple, Union

import box
from box.converters import (
_to_json,
BOX_PARAMETERS,
_from_json,
_from_msgpack,
_from_toml,
_to_toml,
_from_yaml,
_to_yaml,
_to_json,
_to_msgpack,
_from_msgpack,
BOX_PARAMETERS,
yaml_available,
toml_available,
_to_toml,
_to_yaml,
msgpack_available,
toml_available,
yaml_available,
)
from box.exceptions import BoxError, BoxKeyError, BoxTypeError, BoxValueError, BoxWarning

Expand Down Expand Up @@ -454,7 +453,12 @@ def __getitem__(self, item, _ignore_default=False):
if item == "_box_config":
raise BoxKeyError("_box_config should only exist as an attribute and is never defaulted") from None
if self._box_config["box_dots"] and isinstance(item, str) and ("." in item or "[" in item):
first_item, children = _parse_box_dots(self, item)
try:
first_item, children = _parse_box_dots(self, item)
except BoxError:
if self._box_config["default_box"] and not _ignore_default:
return self.__get_default(item)
raise
if first_item in self.keys():
if hasattr(self[first_item], "__getitem__"):
return self[first_item][children]
Expand Down
20 changes: 10 additions & 10 deletions box/box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
import copy
import re
from os import PathLike
from typing import Iterable, Type, Union
from pathlib import Path
from typing import Iterable, Type, Union

import box
from box.converters import (
_to_yaml,
_from_yaml,
_to_json,
BOX_PARAMETERS,
_from_csv,
_from_json,
_to_toml,
_from_msgpack,
_from_toml,
_from_yaml,
_to_csv,
_from_csv,
_to_json,
_to_msgpack,
_from_msgpack,
BOX_PARAMETERS,
yaml_available,
toml_available,
_to_toml,
_to_yaml,
msgpack_available,
toml_available,
yaml_available,
)
from box.exceptions import BoxError, BoxTypeError

Expand Down
2 changes: 1 addition & 1 deletion box/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import csv
import json
from pathlib import Path
from io import StringIO
from os import PathLike
from pathlib import Path
from typing import Union

from box.exceptions import BoxError
Expand Down
13 changes: 7 additions & 6 deletions box/from_file.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from json import JSONDecodeError
from pathlib import Path
from os import PathLike
from typing import Union, Callable, Dict
from pathlib import Path
from typing import Callable, Dict, Union

from box.box import Box
from box.box_list import BoxList
from box.converters import msgpack_available, toml_available, yaml_available
from box.exceptions import BoxError

try:
from ruamel.yaml import YAMLError
Expand All @@ -23,10 +28,6 @@
except ImportError:
UnpackException = False # type: ignore

from box.exceptions import BoxError
from box.box import Box
from box.box_list import BoxList
from box.converters import yaml_available, toml_available, msgpack_available

__all__ = ["box_from_file"]

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup
# Must import multiprocessing as a fix for issues with testing, experienced on win10
import multiprocessing
import os
import re

# Fix for issues with testing, experienced on win10
import multiprocessing
from setuptools import setup

root = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -40,6 +40,7 @@
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Development Status :: 5 - Production/Stable",
"Natural Language :: English",
Expand Down
38 changes: 25 additions & 13 deletions test/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@
import json
import os
import pickle
import platform
import shutil
from multiprocessing import Queue
from pathlib import Path
import platform

import pytest
import ruamel.yaml as yaml

from box import box
from box import Box, BoxError, BoxKeyError, BoxList, SBox, ConfigBox
from test.common import (
test_dict,
extended_test_dict,
tmp_dir,
tmp_json_file,
tmp_yaml_file,
movie_data,
data_json_file,
data_yaml_file,
extended_test_dict,
movie_data,
test_dict,
test_root,
tmp_dir,
tmp_json_file,
tmp_msgpack_file,
tmp_yaml_file,
)

import pytest
import ruamel.yaml as yaml

from box import Box, BoxError, BoxKeyError, BoxList, ConfigBox, SBox, box


def mp_queue_test(q):
bx = q.get()
Expand Down Expand Up @@ -1139,3 +1138,16 @@ def test_default_box_restricted_calls(self):
a = Box(default_box=True)
a._test_thing_
assert len(list(a.keys())) == 0

def test_default_dots(self):
a = Box(default_box=True, box_dots=True)
a["a.a.a"]
assert a == {"a.a.a": {}}
a["a.a.a."]
a["a.a.a.."]
assert a == {"a.a.a": {"": {"": {}}}}
a["b.b"] = 3
assert a == {"a.a.a": {"": {"": {}}}, "b.b": 3}
a.b.b = 4
assert a == {"a.a.a": {"": {"": {}}}, "b.b": 3, "b": {"b": 4}}
assert a["non.existent.key"] == {}
5 changes: 2 additions & 3 deletions test/test_box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import os
import shutil
from pathlib import Path
from test.common import test_root, tmp_dir

import pytest
import ruamel.yaml as yaml
import toml

from box import BoxList, Box, BoxError

from test.common import tmp_dir, test_root
from box import Box, BoxError, BoxList


class TestBoxList:
Expand Down
3 changes: 2 additions & 1 deletion test/test_config_box.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from box import Box, ConfigBox
from test.common import test_dict

from box import Box, ConfigBox


class TestConfigBox:
def test_config_box(self):
Expand Down
9 changes: 4 additions & 5 deletions test/test_converters.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os
import shutil
from pathlib import Path
import json
from test.common import movie_data, tmp_dir

import msgpack
import pytest
import ruamel.yaml as yaml
import msgpack

from box import BoxError
from box.converters import _to_toml, _from_toml, _to_json, _to_yaml, _to_msgpack
from test.common import tmp_dir, movie_data

from box.converters import _from_toml, _to_json, _to_msgpack, _to_toml, _to_yaml

toml_string = """[movies.Spaceballs]
imdb_stars = 7.1
Expand Down
4 changes: 2 additions & 2 deletions test/test_from_file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pathlib import Path
from test.common import test_root

import pytest

from box import box_from_file, Box, BoxList, BoxError
from test.common import test_root
from box import Box, BoxError, BoxList, box_from_file


class TestFromFile:
Expand Down
4 changes: 2 additions & 2 deletions test/test_sbox.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from test.common import test_dict

import ruamel.yaml as yaml

from box import SBox, Box
from test.common import test_dict
from box import Box, SBox


class TestSBox:
Expand Down

0 comments on commit 4b66113

Please sign in to comment.