diff --git a/Makefile b/Makefile index 95f52f6..faeb099 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,6 @@ check: ## Run code quality tools. @poetry lock --check @echo "🚀 Linting code: Running pre-commit" @poetry run pre-commit run -a - @echo "🚀 Checking for obsolete dependencies: Running deptry" - @poetry run deptry . .PHONY: test test: ## Test the code with pytest diff --git a/json_explorer/explore.py b/json_explorer/explore.py index 18f973f..55cdba1 100644 --- a/json_explorer/explore.py +++ b/json_explorer/explore.py @@ -29,6 +29,20 @@ def oxford_join(items, pluralize=False): return "{}, or {}".format(", ".join(items[:-1]), items[-1]) +class Counter(collections.Counter): + """The 'total' method is only available on a collections.Counter + in python >= 3.10, so add the method to be compatible with earlier + versions. + + """ + + def total(self): + try: + return super().total() + except AttributeError: + return sum(self.values()) + + class TripleCounter(dict): def increment(self, keys, amount): try: @@ -40,13 +54,13 @@ def increment(self, keys, amount): if a not in self: self[a] = {} if b not in self[a]: - self[a][b] = collections.Counter() + self[a][b] = Counter() self[a][b][c] += amount def tree(self): result = {} for a, sub_dict in self.items(): - sub_counter = collections.Counter() + sub_counter = Counter() for b, c_counter in sub_dict.items(): sub_counter[b] += c_counter.total() diff --git a/poetry.lock b/poetry.lock index c4be43e..edc1aaa 100644 --- a/poetry.lock +++ b/poetry.lock @@ -18,6 +18,17 @@ soupsieve = ">1.2" html5lib = ["html5lib"] lxml = ["lxml"] +[[package]] +name = "cached-property" +version = "1.5.2" +description = "A decorator for caching properties in classes." +optional = false +python-versions = "*" +files = [ + {file = "cached-property-1.5.2.tar.gz", hash = "sha256:9fa5755838eecbb2d234c3aa390bd80fbd3ac6b6869109bfc1b499f7bd89a130"}, + {file = "cached_property-1.5.2-py2.py3-none-any.whl", hash = "sha256:df4f613cf7ad9a588cc381aaf4a512d26265ecebd5eb9e1ba12f1319eb85a6a0"}, +] + [[package]] name = "certifi" version = "2023.5.7" @@ -40,17 +51,6 @@ files = [ {file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"}, ] -[[package]] -name = "chardet" -version = "5.1.0" -description = "Universal encoding detector for Python 3" -optional = false -python-versions = ">=3.7" -files = [ - {file = "chardet-5.1.0-py3-none-any.whl", hash = "sha256:362777fb014af596ad31334fde1e8c327dfdb076e1960d1694662d46a6917ab9"}, - {file = "chardet-5.1.0.tar.gz", hash = "sha256:0d62712b956bc154f85fb0a266e2a3c5913c2967e00348701b32411d6def31e5"}, -] - [[package]] name = "charset-normalizer" version = "3.1.0" @@ -148,6 +148,7 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} [[package]] name = "colorama" @@ -235,22 +236,6 @@ tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.1 [package.extras] toml = ["tomli"] -[[package]] -name = "deptry" -version = "0.6.6" -description = "A command line utility to check for obsolete, missing and transitive dependencies in a Python project." -optional = false -python-versions = ">=3.7,<4.0" -files = [ - {file = "deptry-0.6.6-py3-none-any.whl", hash = "sha256:38c03085899339a43374ba51c845d6d1e3d3d2d003d8270d85f0c67f19775e36"}, - {file = "deptry-0.6.6.tar.gz", hash = "sha256:b968b459929ede5428d695c801f39d03c058de7fa7f855585ca8620a1ec3ae62"}, -] - -[package.dependencies] -chardet = ">=4.0.0" -click = ">=8.0.0,<9.0.0" -tomli = {version = ">=2.0.1,<3.0.0", markers = "python_version < \"3.11\""} - [[package]] name = "distlib" version = "0.3.6" @@ -320,6 +305,7 @@ files = [ ] [package.dependencies] +cached-property = {version = "*", markers = "python_version < \"3.8\""} colorama = ">=0.4" [[package]] @@ -359,6 +345,7 @@ files = [ ] [package.dependencies] +typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] @@ -503,6 +490,7 @@ mergedeep = ">=1.3.4" packaging = ">=20.5" pyyaml = ">=5.1" pyyaml-env-tag = ">=0.1" +typing-extensions = {version = ">=3.10", markers = "python_version < \"3.8\""} watchdog = ">=2.0" [package.extras] @@ -631,6 +619,9 @@ files = [ {file = "platformdirs-3.5.1.tar.gz", hash = "sha256:412dae91f52a6f84830f39a8078cecd0e866cb72294a5c66808e74d5e88d251f"}, ] +[package.dependencies] +typing-extensions = {version = ">=4.5", markers = "python_version < \"3.8\""} + [package.extras] docs = ["furo (>=2023.3.27)", "proselint (>=0.13)", "sphinx (>=6.2.1)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"] @@ -646,6 +637,9 @@ files = [ {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, ] +[package.dependencies] +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} + [package.extras] dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] @@ -664,6 +658,7 @@ files = [ [package.dependencies] cfgv = ">=2.0.0" identify = ">=1.0.0" +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} nodeenv = ">=0.11.1" pyyaml = ">=5.1" virtualenv = ">=20.10.0" @@ -722,6 +717,7 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "sys_platform == \"win32\""} exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} iniconfig = "*" packaging = "*" pluggy = ">=0.12,<2.0" @@ -909,6 +905,7 @@ files = [ [package.dependencies] colorama = {version = ">=0.4.1", markers = "platform_system == \"Windows\""} filelock = ">=3.0.0" +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} packaging = ">=14" pluggy = ">=0.12.0" py = ">=1.4.17" @@ -920,6 +917,17 @@ virtualenv = ">=16.0.0,<20.0.0 || >20.0.0,<20.0.1 || >20.0.1,<20.0.2 || >20.0.2, docs = ["pygments-github-lexers (>=0.0.5)", "sphinx (>=2.0.0)", "sphinxcontrib-autoprogram (>=0.1.5)", "towncrier (>=18.5.0)"] testing = ["flaky (>=3.4.0)", "freezegun (>=0.3.11)", "pathlib2 (>=2.3.3)", "psutil (>=5.6.1)", "pytest (>=4.0.0)", "pytest-cov (>=2.5.1)", "pytest-mock (>=1.10.0)", "pytest-randomly (>=1.0.0)"] +[[package]] +name = "typing-extensions" +version = "4.6.3" +description = "Backported and Experimental Type Hints for Python 3.7+" +optional = false +python-versions = ">=3.7" +files = [ + {file = "typing_extensions-4.6.3-py3-none-any.whl", hash = "sha256:88a4153d8505aabbb4e13aacb7c486c2b4a33ca3b3f807914a9b4c844c471c26"}, + {file = "typing_extensions-4.6.3.tar.gz", hash = "sha256:d91d5919357fe7f681a9f2b5b4cb2a5f1ef0a1e9f59c4d8ff0d3491e05c0ffd5"}, +] + [[package]] name = "urllib3" version = "2.0.2" @@ -951,6 +959,7 @@ files = [ [package.dependencies] distlib = ">=0.3.6,<1" filelock = ">=3.11,<4" +importlib-metadata = {version = ">=6.4.1", markers = "python_version < \"3.8\""} platformdirs = ">=3.2,<4" [package.extras] @@ -1013,5 +1022,5 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" -python-versions = ">=3.8,<4.0" -content-hash = "465c368f25da133d7e7257e2df45512ef2756b4e00f50a2507ebc27975b6e837" +python-versions = ">=3.7,<4.0" +content-hash = "57645037ea0f29f6e9770808db1b6f86ec3397ca8ceb544e95976b1497a8d9bf" diff --git a/pyproject.toml b/pyproject.toml index 6cc732d..84d4488 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,12 +14,11 @@ packages = [ greet = "json_explorer.explore:main" [tool.poetry.dependencies] -python = ">=3.8,<4.0" +python = ">=3.7,<4.0" [tool.poetry.group.dev.dependencies] pytest = "^7.2.0" pytest-cov = "^4.0.0" -deptry = "^0.6.4" pre-commit = "^2.20.0" tox = "^3.25.1" beautifulsoup4 = "^4.12.2" diff --git a/tox.ini b/tox.ini index 6953a07..a004993 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,10 @@ [tox] skipsdist = true -envlist = py38, py39, py310, py311 +envlist = py37, py38, py39, py310, py311 [gh-actions] python = + 3.7: py37 3.8: py38 3.9: py39 3.10: py310