From 9b49ae8e31008e7863c45626a38f5f8948b869c9 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Fri, 20 Sep 2019 23:28:35 +0700 Subject: [PATCH 1/4] MANIFEST.in: Add license and tests to sdist --- MANIFEST.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index d27808a..1a54f9b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,5 @@ +include LICENSE.txt include requirements/* include README.md - +recursive-include docs *.md +recursive-include tests *.py From 4be9e332b5e84ad406e654d55e74d239ee1764dc Mon Sep 17 00:00:00 2001 From: nsheff Date: Fri, 20 Sep 2019 13:00:56 -0400 Subject: [PATCH 2/4] license string --- setup.py | 2 +- ubiquerg/_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index dfce46c..13d4aa6 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ def read_reqs(reqs_name): keywords="utility, utilities, tools", url="https://github.com/pepkit/{}/".format(PKG), author=u"Vince Reuter", - license="BSD2", + license="BSD-2-Clause", scripts=None, include_package_data=True, test_suite="tests", diff --git a/ubiquerg/_version.py b/ubiquerg/_version.py index 574c066..e26d9e9 100644 --- a/ubiquerg/_version.py +++ b/ubiquerg/_version.py @@ -1 +1 @@ -__version__ = "0.4.9" +__version__ = "0.4.10-dev" From a0c69c31291e6098ade9e23e8476b6341354ca19 Mon Sep 17 00:00:00 2001 From: Michal Stolarczyk Date: Mon, 14 Oct 2019 13:57:33 -0400 Subject: [PATCH 3/4] add asciify_dict function --- docs/changelog.md | 5 +++++ tests/test_collection.py | 9 +++++++++ ubiquerg/collection.py | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index b4484d7..804340b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,10 @@ # Changelog +## [0.5.0] - 2019-10-XX +### Added +- add `asciify_dict` function + + ## [0.4.9] - 2019-09-17 ### Added - add `--version` argument in `VersionInHelpParser` diff --git a/tests/test_collection.py b/tests/test_collection.py index 32d4af7..9a1a3cb 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -205,3 +205,12 @@ def test_powerset_illegal_input(arbwrap, kwargs, exp_err, pool): format(powerset.__name__, ", ".join(invalid_kwargs)) with pytest.raises(exp_err): powerset(arbwrap(pool), **kwargs) + + +@pytest.mark.parametrize("dict", [{"a": 1}, {"b": None}]) +def test_asciifying_dicts(dict): + if sys.version_info[0] <= 3: + with pytest.warns(UserWarning): + assert dict == asciify_dict(dict) + else: + asciify_dict(dict) diff --git a/ubiquerg/collection.py b/ubiquerg/collection.py index f0aad13..efd8503 100644 --- a/ubiquerg/collection.py +++ b/ubiquerg/collection.py @@ -2,6 +2,7 @@ import itertools import sys +from warnings import warn if sys.version_info < (3, 3): from collections import Iterable else: @@ -11,7 +12,7 @@ __email__ = "vreuter@virginia.edu" -__all__ = ["is_collection_like", "powerset"] +__all__ = ["is_collection_like", "powerset", "asciify_dict"] def is_collection_like(c): @@ -60,3 +61,36 @@ def powerset(items, min_items=None, include_full_pop=True, nonempty=False): return list(itertools.chain.from_iterable( itertools.combinations(items, k) for k in range(min_items, max_items))) + + +def asciify_dict(data): + """ https://gist.github.com/chris-hailstorm/4989643 """ + + def _asciify_list(lst): + ret = [] + for item in lst: + if isinstance(item, unicode): + item = item.encode('utf-8') + elif isinstance(item, list): + item = _asciify_list(item) + elif isinstance(item, dict): + item = asciify_dict(item) + ret.append(item) + return ret + + if sys.version_info[0] <= 3: + warn("This operation is supported only in Python2", UserWarning) + return data + + ret = {} + for key, value in data.iteritems(): + if isinstance(key, unicode): + key = key.encode('utf-8') + if isinstance(value, unicode): + value = value.encode('utf-8') + elif isinstance(value, list): + value = _asciify_list(value) + elif isinstance(value, dict): + value = asciify_dict(value) + ret[key] = value + return ret \ No newline at end of file From e480f1fc5a6aa4d7b7deb8e3f870146079fb8193 Mon Sep 17 00:00:00 2001 From: Michal Stolarczyk Date: Tue, 15 Oct 2019 11:26:07 -0400 Subject: [PATCH 4/4] Update _version.py --- ubiquerg/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubiquerg/_version.py b/ubiquerg/_version.py index e26d9e9..3d18726 100644 --- a/ubiquerg/_version.py +++ b/ubiquerg/_version.py @@ -1 +1 @@ -__version__ = "0.4.10-dev" +__version__ = "0.5.0"