Skip to content

Commit

Permalink
Version 7.1.0 (#256)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
cdgriffith and ericpre authored Aug 26, 2023
1 parent 9a4b108 commit e61a7d2
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 213 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install Dependencies
run: |
Expand All @@ -39,7 +39,7 @@ jobs:
strategy:
matrix:
os: [macos-11, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine Cython --upgrade
pip install setuptools wheel twine Cython==3.0.0 --upgrade
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand All @@ -64,24 +64,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

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

- name: Install dependencies
- name: Build wheels
run: |
python -m pip install --upgrade pip
pip install twine --upgrade
pip install cibuildwheel
python -m cibuildwheel --output-dir dist
env:
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp311-macosx_x86_64
CIBW_BEFORE_BUILD: pip install Cython==3.0.0
CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine
CIBW_TEST_COMMAND: pytest {package}/test -vv

- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*-manylinux*.whl
twine upload dist/*-macosx*.whl
45 changes: 19 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
package-checks:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy-3.8"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy-3.8"]
os: [ubuntu-latest, macos-11, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -31,7 +31,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install coveralls flake8 flake8-print mypy setuptools wheel twine Cython
pip install coveralls flake8 flake8-print mypy setuptools wheel twine Cython==3.0.0
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors, undefined names or print statements
Expand All @@ -49,16 +49,16 @@ jobs:
run: |
pip install dist/*.whl
rm -rf box
python -m pytest
python -m pytest -vv
- name: Test packaged wheel on Windows
if: matrix.os == 'windows-latest'
run: |
$wheel = (Get-ChildItem dist\*.whl | Sort lastWriteTime | Select-Object -last 1).Name
pip install dist\${wheel}
Remove-item box -recurse -force
python -m pytest
python -m pytest -vv
- name: Upload wheel artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: python_box
path: dist/*.whl
Expand All @@ -67,44 +67,37 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

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

- name: Install dependencies
- name: Build wheels
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install coveralls flake8 flake8-print mypy setuptools wheel twine Cython
- uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310'
build-requirements: 'cython'

- name: Test packaged wheel on linux
run: |
pip install dist/*cp310-manylinux*.whl
rm -rf box
python -m pytest
pip install cibuildwheel
python -m cibuildwheel --output-dir dist
env:
CIBW_BUILD: cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp311-macosx_x86_64
CIBW_BEFORE_BUILD: pip install Cython==3.0.0
CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine
CIBW_TEST_COMMAND: pytest {package}/test -vv

- name: Upload wheel artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: python_box
path: dist/*-manylinux*.whl

test:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-11, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -122,10 +115,10 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install setuptools wheel Cython
pip install setuptools wheel Cython==3.0.0
python setup.py build_ext --inplace
- name: Test with pytest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pytest --cov=box test/
pytest --cov=box -vv test/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
exclude: ^test/data/.+

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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.0.1'
rev: 'v1.4.1'
hooks:
- id: mypy
types: [python]
Expand Down
4 changes: 4 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Code contributions:
- Ivan Pepelnjak (ipspace)
- Michał Górny (mgorny)
- Serge Lu (Serge45)
- Eric Prestat (ericpre)



Suggestions and bug reporting:
Expand Down Expand Up @@ -87,3 +89,5 @@ Suggestions and bug reporting:
- Peter B (barmettl)
- Ash A. (dragonpaw)
- Коптев Роман Викторович (romikforest)
- lei wang (191801737)
- d00m514y3r
11 changes: 11 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
=========

Version 7.1.0
-------------

* 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)
* Removing support for Python 3.7 as it is EOL

Version 7.0.1
-------------

Expand Down
2 changes: 1 addition & 1 deletion box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

__author__ = "Chris Griffith"
__version__ = "7.0.1"
__version__ = "7.1.0"

from box.box import Box
from box.box_list import BoxList
Expand Down
35 changes: 23 additions & 12 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
import warnings
from keyword import iskeyword
from os import PathLike
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union, Literal
from inspect import signature

try:
from typing import Callable, Iterable, Mapping
except ImportError:
from collections.abc import Callable, Iterable, Mapping

try:
from IPython import get_ipython
except ImportError:
ipython = False
else:
ipython = True if get_ipython() else False

import box
from box.converters import (
Expand Down Expand Up @@ -56,6 +50,17 @@
NO_NAMESPACE = object()


def _is_ipython():
try:
from IPython import get_ipython
except ImportError:
ipython = False
else:
ipython = True if get_ipython() else False

return ipython


def _exception_cause(e):
"""
Unwrap BoxKeyError and BoxValueError errors to their cause.
Expand Down Expand Up @@ -201,7 +206,7 @@ def __new__(
box_recast: Optional[Dict] = None,
box_dots: bool = False,
box_class: Optional[Union[Dict, Type["Box"]]] = None,
box_namespace: Tuple[str, ...] = (),
box_namespace: Union[Tuple[str, ...], Literal[False]] = (),
**kwargs: Any,
):
"""
Expand Down Expand Up @@ -248,7 +253,7 @@ def __init__(
box_recast: Optional[Dict] = None,
box_dots: bool = False,
box_class: Optional[Union[Dict, Type["Box"]]] = None,
box_namespace: Tuple[str, ...] = (),
box_namespace: Union[Tuple[str, ...], Literal[False]] = (),
**kwargs: Any,
):
super().__init__()
Expand Down Expand Up @@ -380,7 +385,7 @@ def __hash__(self):
return hashing
raise BoxTypeError('unhashable type: "Box"')

def __dir__(self):
def __dir__(self) -> List[str]:
items = set(super().__dir__())
# Only show items accessible by dot notation
for key in self.keys():
Expand Down Expand Up @@ -483,7 +488,7 @@ def __setstate__(self, state):
self.__dict__.update(state)

def __get_default(self, item, attr=False):
if ipython and item in ("getdoc", "shape"):
if item in ("getdoc", "shape") and _is_ipython():
return None
default_value = self._box_config["default_box_attr"]
if default_value in (self._box_config["box_class"], dict):
Expand Down Expand Up @@ -589,6 +594,12 @@ def __getitem__(self, item, _ignore_default=False):
if item == "_box_config":
cause = _exception_cause(err)
raise BoxKeyError("_box_config should only exist as an attribute and is never defaulted") from cause
if isinstance(item, slice):
# In Python 3.12 this changes to a KeyError instead of TypeError
new_box = self._box_config["box_class"](**self.__box_config())
for x in list(super().keys())[item.start : item.stop : item.step]:
new_box[x] = self[x]
return new_box
if self._box_config["box_dots"] and isinstance(item, str) and ("." in item or "[" in item):
try:
first_item, children = _parse_box_dots(self, item)
Expand Down Expand Up @@ -823,7 +834,7 @@ def convert_and_set(k, v):
# in the `converted` box_config set
v = self._box_config["box_class"](v, **self.__box_config(extra_namespace=k))
if k in self and isinstance(self[k], dict):
self[k].merge_update(v)
self[k].merge_update(v, box_merge_lists=merge_type)
return
if isinstance(v, list) and not intact_type:
v = box.BoxList(v, **self.__box_config(extra_namespace=k))
Expand Down
Loading

0 comments on commit e61a7d2

Please sign in to comment.