Skip to content

Commit

Permalink
Migrate from setuptools to poetry; fix issue with Python 3.11; bump v…
Browse files Browse the repository at this point in the history
…ersion to 1.0.3
  • Loading branch information
will2dye4 committed Sep 19, 2023
1 parent b5163eb commit 12c8977
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build/
dist/
__pycache__/
.pytest_cache/

*.egg-info/

Expand Down
182 changes: 182 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 17 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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'
25 changes: 13 additions & 12 deletions sudoku/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import logging

from collections import namedtuple
from dataclasses import dataclass
from enum import Enum
from typing import (
AnyStr,
Expand All @@ -14,6 +14,7 @@
List,
Optional,
TypeVar,
Type,
)

from sudoku.dlx import DLX
Expand Down Expand Up @@ -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):
Expand All @@ -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__':
Expand Down

0 comments on commit 12c8977

Please sign in to comment.