Skip to content

Commit e61a7d2

Browse files
cdgriffithericpre
andauthored
Version 7.1.0 (#256)
* Adding #255 defer ipython import for large import speed improvements (thanks to Eric Prestat) * Adding testing for Python 3.12 * Fixing #253 merge_update box list merge types not populated to sub dictionaries (thanks to lei wang) * Fixing #257 Two test failures due to arguments having incorrect types (thanks to Michał Górny) * Fixing stub files to match latest code signatures * Removing #251 support for circular references in lists (thanks to d00m514y3r) --------- Co-authored-by: Eric Prestat <[email protected]>
1 parent 9a4b108 commit e61a7d2

21 files changed

+268
-213
lines changed

.github/workflows/pythonpublish.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up Python
1919
uses: actions/setup-python@v4
2020
with:
21-
python-version: '3.10'
21+
python-version: '3.11'
2222

2323
- name: Install Dependencies
2424
run: |
@@ -39,7 +39,7 @@ jobs:
3939
strategy:
4040
matrix:
4141
os: [macos-11, windows-latest]
42-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
42+
python-version: ["3.8", "3.9", "3.10", "3.11"]
4343
runs-on: ${{ matrix.os }}
4444

4545
steps:
@@ -51,7 +51,7 @@ jobs:
5151
- name: Install dependencies
5252
run: |
5353
python -m pip install --upgrade pip
54-
pip install setuptools wheel twine Cython --upgrade
54+
pip install setuptools wheel twine Cython==3.0.0 --upgrade
5555
- name: Build and publish
5656
env:
5757
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
@@ -64,24 +64,26 @@ jobs:
6464
runs-on: ubuntu-latest
6565
steps:
6666
- uses: actions/checkout@v3
67-
- name: Set up Python 3.10
67+
- name: Set up Python 3.11
6868
uses: actions/setup-python@v4
6969
with:
70-
python-version: "3.10"
70+
python-version: "3.11"
7171

72-
- uses: RalfG/[email protected]_x86_64
73-
with:
74-
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310'
75-
build-requirements: 'cython'
76-
77-
- name: Install dependencies
72+
- name: Build wheels
7873
run: |
7974
python -m pip install --upgrade pip
80-
pip install twine --upgrade
75+
pip install cibuildwheel
76+
python -m cibuildwheel --output-dir dist
77+
env:
78+
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp311-macosx_x86_64
79+
CIBW_BEFORE_BUILD: pip install Cython==3.0.0
80+
CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine
81+
CIBW_TEST_COMMAND: pytest {package}/test -vv
8182

8283
- name: Publish
8384
env:
8485
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
8586
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
8687
run: |
8788
twine upload dist/*-manylinux*.whl
89+
twine upload dist/*-macosx*.whl

.github/workflows/tests.yml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
package-checks:
1414
strategy:
1515
matrix:
16-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy-3.8"]
16+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy-3.8"]
1717
os: [ubuntu-latest, macos-11, windows-latest]
1818
runs-on: ${{ matrix.os }}
1919
steps:
@@ -31,7 +31,7 @@ jobs:
3131
python -m pip install --upgrade pip
3232
pip install -r requirements.txt
3333
pip install -r requirements-test.txt
34-
pip install coveralls flake8 flake8-print mypy setuptools wheel twine Cython
34+
pip install coveralls flake8 flake8-print mypy setuptools wheel twine Cython==3.0.0
3535
- name: Lint with flake8
3636
run: |
3737
# stop the build if there are Python syntax errors, undefined names or print statements
@@ -49,16 +49,16 @@ jobs:
4949
run: |
5050
pip install dist/*.whl
5151
rm -rf box
52-
python -m pytest
52+
python -m pytest -vv
5353
- name: Test packaged wheel on Windows
5454
if: matrix.os == 'windows-latest'
5555
run: |
5656
$wheel = (Get-ChildItem dist\*.whl | Sort lastWriteTime | Select-Object -last 1).Name
5757
pip install dist\${wheel}
5858
Remove-item box -recurse -force
59-
python -m pytest
59+
python -m pytest -vv
6060
- name: Upload wheel artifact
61-
uses: actions/upload-artifact@v2
61+
uses: actions/upload-artifact@v3
6262
with:
6363
name: python_box
6464
path: dist/*.whl
@@ -67,44 +67,37 @@ jobs:
6767
runs-on: ubuntu-latest
6868
steps:
6969
- uses: actions/checkout@v3
70-
- name: Set up Python 3.10
70+
- name: Set up Python 3.11
7171
uses: actions/setup-python@v4
7272
with:
73-
python-version: "3.10"
73+
python-version: "3.11"
7474

7575
- uses: actions/cache@v3
7676
with:
7777
path: ~/.cache/pip
7878
key: package-manylinux-check-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
7979

80-
- name: Install dependencies
80+
- name: Build wheels
8181
run: |
8282
python -m pip install --upgrade pip
83-
pip install -r requirements.txt
84-
pip install -r requirements-test.txt
85-
pip install coveralls flake8 flake8-print mypy setuptools wheel twine Cython
86-
87-
- uses: RalfG/[email protected]_x86_64
88-
with:
89-
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310'
90-
build-requirements: 'cython'
91-
92-
- name: Test packaged wheel on linux
93-
run: |
94-
pip install dist/*cp310-manylinux*.whl
95-
rm -rf box
96-
python -m pytest
83+
pip install cibuildwheel
84+
python -m cibuildwheel --output-dir dist
85+
env:
86+
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp311-macosx_x86_64
87+
CIBW_BEFORE_BUILD: pip install Cython==3.0.0
88+
CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine
89+
CIBW_TEST_COMMAND: pytest {package}/test -vv
9790

9891
- name: Upload wheel artifact
99-
uses: actions/upload-artifact@v2
92+
uses: actions/upload-artifact@v3
10093
with:
10194
name: python_box
10295
path: dist/*-manylinux*.whl
10396

10497
test:
10598
strategy:
10699
matrix:
107-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
100+
python-version: ["3.8", "3.9", "3.10", "3.11"]
108101
os: [ubuntu-latest, macos-11, windows-latest]
109102
runs-on: ${{ matrix.os }}
110103
steps:
@@ -122,10 +115,10 @@ jobs:
122115
python -m pip install --upgrade pip
123116
pip install -r requirements.txt
124117
pip install -r requirements-test.txt
125-
pip install setuptools wheel Cython
118+
pip install setuptools wheel Cython==3.0.0
126119
python setup.py build_ext --inplace
127120
- name: Test with pytest
128121
env:
129122
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130123
run: |
131-
pytest --cov=box test/
124+
pytest --cov=box -vv test/

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
exclude: ^test/data/.+
3030

3131
- repo: https://github.com/ambv/black
32-
rev: 23.1.0
32+
rev: 23.7.0
3333
hooks:
3434
- id: black
3535
args: [--config=.black.toml]
@@ -51,7 +51,7 @@ repos:
5151
always_run: true
5252

5353
- repo: https://github.com/pre-commit/mirrors-mypy
54-
rev: 'v1.0.1'
54+
rev: 'v1.4.1'
5555
hooks:
5656
- id: mypy
5757
types: [python]

AUTHORS.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Code contributions:
2929
- Ivan Pepelnjak (ipspace)
3030
- Michał Górny (mgorny)
3131
- Serge Lu (Serge45)
32+
- Eric Prestat (ericpre)
33+
3234

3335

3436
Suggestions and bug reporting:
@@ -87,3 +89,5 @@ Suggestions and bug reporting:
8789
- Peter B (barmettl)
8890
- Ash A. (dragonpaw)
8991
- Коптев Роман Викторович (romikforest)
92+
- lei wang (191801737)
93+
- d00m514y3r

CHANGES.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changelog
22
=========
33

4+
Version 7.1.0
5+
-------------
6+
7+
* Adding #255 defer ipython import for large import speed improvements (thanks to Eric Prestat)
8+
* Adding testing for Python 3.12
9+
* Fixing #253 merge_update box list merge types not populated to sub dictionaries (thanks to lei wang)
10+
* Fixing #257 Two test failures due to arguments having incorrect types (thanks to Michał Górny)
11+
* Fixing stub files to match latest code signatures
12+
* Removing #251 support for circular references in lists (thanks to d00m514y3r)
13+
* Removing support for Python 3.7 as it is EOL
14+
415
Version 7.0.1
516
-------------
617

box/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
__author__ = "Chris Griffith"
5-
__version__ = "7.0.1"
5+
__version__ = "7.1.0"
66

77
from box.box import Box
88
from box.box_list import BoxList

box/box.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@
1010
import warnings
1111
from keyword import iskeyword
1212
from os import PathLike
13-
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union
13+
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union, Literal
1414
from inspect import signature
1515

1616
try:
1717
from typing import Callable, Iterable, Mapping
1818
except ImportError:
1919
from collections.abc import Callable, Iterable, Mapping
2020

21-
try:
22-
from IPython import get_ipython
23-
except ImportError:
24-
ipython = False
25-
else:
26-
ipython = True if get_ipython() else False
2721

2822
import box
2923
from box.converters import (
@@ -56,6 +50,17 @@
5650
NO_NAMESPACE = object()
5751

5852

53+
def _is_ipython():
54+
try:
55+
from IPython import get_ipython
56+
except ImportError:
57+
ipython = False
58+
else:
59+
ipython = True if get_ipython() else False
60+
61+
return ipython
62+
63+
5964
def _exception_cause(e):
6065
"""
6166
Unwrap BoxKeyError and BoxValueError errors to their cause.
@@ -201,7 +206,7 @@ def __new__(
201206
box_recast: Optional[Dict] = None,
202207
box_dots: bool = False,
203208
box_class: Optional[Union[Dict, Type["Box"]]] = None,
204-
box_namespace: Tuple[str, ...] = (),
209+
box_namespace: Union[Tuple[str, ...], Literal[False]] = (),
205210
**kwargs: Any,
206211
):
207212
"""
@@ -248,7 +253,7 @@ def __init__(
248253
box_recast: Optional[Dict] = None,
249254
box_dots: bool = False,
250255
box_class: Optional[Union[Dict, Type["Box"]]] = None,
251-
box_namespace: Tuple[str, ...] = (),
256+
box_namespace: Union[Tuple[str, ...], Literal[False]] = (),
252257
**kwargs: Any,
253258
):
254259
super().__init__()
@@ -380,7 +385,7 @@ def __hash__(self):
380385
return hashing
381386
raise BoxTypeError('unhashable type: "Box"')
382387

383-
def __dir__(self):
388+
def __dir__(self) -> List[str]:
384389
items = set(super().__dir__())
385390
# Only show items accessible by dot notation
386391
for key in self.keys():
@@ -483,7 +488,7 @@ def __setstate__(self, state):
483488
self.__dict__.update(state)
484489

485490
def __get_default(self, item, attr=False):
486-
if ipython and item in ("getdoc", "shape"):
491+
if item in ("getdoc", "shape") and _is_ipython():
487492
return None
488493
default_value = self._box_config["default_box_attr"]
489494
if default_value in (self._box_config["box_class"], dict):
@@ -589,6 +594,12 @@ def __getitem__(self, item, _ignore_default=False):
589594
if item == "_box_config":
590595
cause = _exception_cause(err)
591596
raise BoxKeyError("_box_config should only exist as an attribute and is never defaulted") from cause
597+
if isinstance(item, slice):
598+
# In Python 3.12 this changes to a KeyError instead of TypeError
599+
new_box = self._box_config["box_class"](**self.__box_config())
600+
for x in list(super().keys())[item.start : item.stop : item.step]:
601+
new_box[x] = self[x]
602+
return new_box
592603
if self._box_config["box_dots"] and isinstance(item, str) and ("." in item or "[" in item):
593604
try:
594605
first_item, children = _parse_box_dots(self, item)
@@ -823,7 +834,7 @@ def convert_and_set(k, v):
823834
# in the `converted` box_config set
824835
v = self._box_config["box_class"](v, **self.__box_config(extra_namespace=k))
825836
if k in self and isinstance(self[k], dict):
826-
self[k].merge_update(v)
837+
self[k].merge_update(v, box_merge_lists=merge_type)
827838
return
828839
if isinstance(v, list) and not intact_type:
829840
v = box.BoxList(v, **self.__box_config(extra_namespace=k))

0 commit comments

Comments
 (0)