From 12c89770e83500d13e2de29d428cc7821695eab1 Mon Sep 17 00:00:00 2001 From: William Dye Date: Tue, 19 Sep 2023 16:16:51 -0400 Subject: [PATCH] Migrate from setuptools to poetry; fix issue with Python 3.11; bump version to 1.0.3 --- .gitignore | 1 + poetry.lock | 182 +++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 38 +++++----- sudoku/solver.py | 25 +++---- 4 files changed, 213 insertions(+), 33 deletions(-) create mode 100644 poetry.lock diff --git a/.gitignore b/.gitignore index f263a6b..d90cc4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build/ dist/ __pycache__/ +.pytest_cache/ *.egg-info/ diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..d0b0510 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,182 @@ +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. + +[[package]] +name = "atomicwrites" +version = "1.4.1" +description = "Atomic file writes." +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "atomicwrites-1.4.1.tar.gz", hash = "sha256:81b2c9071a49367a7f770170e5eec8cb66567cfbbc8c73d20ce5ca4a8d71cf11"}, +] + +[[package]] +name = "attrs" +version = "23.1.0" +description = "Classes Without Boilerplate" +optional = false +python-versions = ">=3.7" +files = [ + {file = "attrs-23.1.0-py3-none-any.whl", hash = "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04"}, + {file = "attrs-23.1.0.tar.gz", hash = "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015"}, +] + +[package.dependencies] +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} + +[package.extras] +cov = ["attrs[tests]", "coverage[toml] (>=5.3)"] +dev = ["attrs[docs,tests]", "pre-commit"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope-interface"] +tests = ["attrs[tests-no-zope]", "zope-interface"] +tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "importlib-metadata" +version = "6.7.0" +description = "Read metadata from Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "importlib_metadata-6.7.0-py3-none-any.whl", hash = "sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5"}, + {file = "importlib_metadata-6.7.0.tar.gz", hash = "sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4"}, +] + +[package.dependencies] +typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} +zipp = ">=0.5" + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +perf = ["ipython"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"] + +[[package]] +name = "more-itertools" +version = "9.1.0" +description = "More routines for operating on iterables, beyond itertools" +optional = false +python-versions = ">=3.7" +files = [ + {file = "more-itertools-9.1.0.tar.gz", hash = "sha256:cabaa341ad0389ea83c17a94566a53ae4c9d07349861ecb14dc6d0345cf9ac5d"}, + {file = "more_itertools-9.1.0-py3-none-any.whl", hash = "sha256:d2bc7f02446e86a68911e58ded76d6561eea00cddfb2a91e7019bbb586c799f3"}, +] + +[[package]] +name = "pluggy" +version = "1.2.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, + {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, +] + +[package.dependencies] +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "py" +version = "1.11.0" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +files = [ + {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, + {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, +] + +[[package]] +name = "pytest" +version = "3.10.1" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "pytest-3.10.1-py2.py3-none-any.whl", hash = "sha256:3f193df1cfe1d1609d4c583838bea3d532b18d6160fd3f55c9447fdca30848ec"}, + {file = "pytest-3.10.1.tar.gz", hash = "sha256:e246cf173c01169b9617fc07264b7b1316e78d7a650055235d6d897bc80d9660"}, +] + +[package.dependencies] +atomicwrites = ">=1.0" +attrs = ">=17.4.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +more-itertools = ">=4.0.0" +pluggy = ">=0.7" +py = ">=1.5.0" +setuptools = "*" +six = ">=1.10.0" + +[[package]] +name = "setuptools" +version = "68.0.0" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "setuptools-68.0.0-py3-none-any.whl", hash = "sha256:11e52c67415a381d10d6b462ced9cfb97066179f0e871399e006c4ab101fc85f"}, + {file = "setuptools-68.0.0.tar.gz", hash = "sha256:baf1fdb41c6da4cd2eae722e135500da913332ab3f2f5c7d33af9b492acb5235"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + +[[package]] +name = "typing-extensions" +version = "4.7.1" +description = "Backported and Experimental Type Hints for Python 3.7+" +optional = false +python-versions = ">=3.7" +files = [ + {file = "typing_extensions-4.7.1-py3-none-any.whl", hash = "sha256:440d5dd3af93b060174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36"}, + {file = "typing_extensions-4.7.1.tar.gz", hash = "sha256:b75ddc264f0ba5615db7ba217daeb99701ad295353c45f9e95963337ceeeffb2"}, +] + +[[package]] +name = "zipp" +version = "3.15.0" +description = "Backport of pathlib-compatible object wrapper for zip files" +optional = false +python-versions = ">=3.7" +files = [ + {file = "zipp-3.15.0-py3-none-any.whl", hash = "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556"}, + {file = "zipp-3.15.0.tar.gz", hash = "sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.7" +content-hash = "2a84246ad5714809b06c15c1636eca7c186ce099d84a43deee4228a7168262d3" diff --git a/pyproject.toml b/pyproject.toml index a701baf..200dda7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,31 +1,27 @@ [build-system] -requires = ['setuptools'] -build-backend = 'setuptools.build_meta' +requires = ['poetry-core'] +build-backend = 'poetry.core.masonry.api' -[project] +[tool.poetry] name = 'sudoku-ui' -version = '1.0.2' +version = '1.0.3' description = 'Solve sudoku puzzles using various algorithms' -license = {file = 'LICENSE'} +license = 'MIT' readme = 'README.md' -authors = [ - {name = 'William Dye'}, -] +authors = ['William Dye'] keywords = ['dancing links', 'dlx', 'sudoku', 'sudoku solver'] -requires-python = '>=3.7' +repository = 'https://github.com/will2dye4/sudoku.git' +packages = [{include = 'sudoku'}] -[project.optional-dependencies] -test = [ - 'pytest ~= 3.7.2', -] +[tool.poetry.dependencies] +python = '^3.7' -[project.scripts] -ku = 'sudoku.__main__:ku' -sudoku = 'sudoku.__main__:main' +[tool.poetry.group.dev] +optional = true -[project.urls] -Repository = 'https://github.com/will2dye4/sudoku.git' +[tool.poetry.group.dev.dependencies] +pytest = '^3.7.2' -[tool.setuptools.packages.find] -include = ['sudoku*'] -namespaces = false +[tool.poetry.scripts] +ku = 'sudoku.__main__:ku' +sudoku = 'sudoku.__main__:main' diff --git a/sudoku/solver.py b/sudoku/solver.py index 27354c5..3d97c7e 100644 --- a/sudoku/solver.py +++ b/sudoku/solver.py @@ -3,7 +3,7 @@ import abc import logging -from collections import namedtuple +from dataclasses import dataclass from enum import Enum from typing import ( AnyStr, @@ -14,6 +14,7 @@ List, Optional, TypeVar, + Type, ) from sudoku.dlx import DLX @@ -235,7 +236,10 @@ def solve(self) -> Optional[Sudoku]: return self.get_solved_sudoku(solution) -AlgorithmConfig = namedtuple('AlgorithmConfig', ['sudoku_type', 'solver_type']) +@dataclass +class AlgorithmConfig: + sudoku_type: Type[Sudoku] + solver_type: Type[SudokuSolver] class SolutionAlgorithm(Enum): @@ -252,23 +256,20 @@ def solve(sudoku: Optional[Sudoku] = None, sudoku_string: Optional[AnyStr] = Non if sudoku is None and sudoku_string is None: raise ValueError('Must provide a Sudoku instance or a sudoku string') - sudoku_type, solver_type = algorithm.value - if sudoku is None: - sudoku = sudoku_type.from_string(sudoku_string) - elif not isinstance(sudoku, sudoku_type): - raise ValueError(f'Algorithm {algorithm.name} requires an instance of {sudoku_type}') + sudoku = algorithm.value.sudoku_type.from_string(sudoku_string) + elif not isinstance(sudoku, algorithm.value.sudoku_type): + raise ValueError(f'Algorithm {algorithm.name} requires an instance of {algorithm.value.sudoku_type}') - solver = solver_type(sudoku, event_listener=event_listener) + solver = algorithm.value.solver_type(sudoku, event_listener=event_listener) return solver.solve() def get_solver(sudoku: Sudoku, algorithm: SolutionAlgorithm) -> SudokuSolver: """Return a SudokuSolver instance suitable for the given sudoku and algorithm.""" - sudoku_type, solver_type = algorithm.value - if not isinstance(sudoku, sudoku_type): - raise ValueError(f'Algorithm {algorithm.name} requires an instance of {sudoku_type}') - return solver_type(sudoku) + if not isinstance(sudoku, algorithm.value.sudoku_type): + raise ValueError(f'Algorithm {algorithm.name} requires an instance of {algorithm.value.sudoku_type}') + return algorithm.value.solver_type(sudoku) if __name__ == '__main__':