Skip to content

Commit

Permalink
Update setup.py for setuptools 69 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen authored Nov 24, 2023
1 parent 8e24eec commit bfdf958
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 46 deletions.
28 changes: 14 additions & 14 deletions parsing/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __hash__(self) -> int:
return self._hash

def __eq__(self, other: Any) -> bool:
if type(other) == ItemSet:
if type(other) is ItemSet:
return self._kernel.keys() == other._kernel.keys()
else:
return NotImplemented
Expand Down Expand Up @@ -589,7 +589,7 @@ def __repr__(self) -> str:
conflict = "XXX"
break

if type(action) == ShiftAction:
if type(action) is ShiftAction:
lines.append(
"%s %15r : %-6s %d [%s]"
% (
Expand All @@ -601,7 +601,7 @@ def __repr__(self) -> str:
)
)
else:
assert type(action) == ReduceAction
assert type(action) is ReduceAction
lines.append(
"%s %15r : %-6s %r"
% (conflict, sym, "reduce", action.production)
Expand Down Expand Up @@ -1715,16 +1715,16 @@ def _resolve(
) -> ConflictResolution:
ret: ConflictResolution

if type(oldAct) == ShiftAction:
if type(oldAct) is ShiftAction:
oldPrec = sym.prec
elif type(oldAct) == ReduceAction:
elif type(oldAct) is ReduceAction:
oldPrec = oldAct.production.prec
else:
assert False

if type(newAct) == ShiftAction:
if type(newAct) is ShiftAction:
newPrec = sym.prec
elif type(newAct) == ReduceAction:
elif type(newAct) is ReduceAction:
newPrec = newAct.production.prec
else:
assert False
Expand All @@ -1740,9 +1740,9 @@ def _resolve(

if oldPrec.assoc == "split" or newPrec.assoc == "split":
ret = "both"
elif type(newAct) == type(oldAct):
assert type(newAct) == ReduceAction
assert type(oldAct) == ReduceAction
elif type(newAct) is type(oldAct):
assert type(newAct) is ReduceAction
assert type(oldAct) is ReduceAction
# Fatal reduce/reduce conflict.
ret = "err"
else:
Expand All @@ -1765,16 +1765,16 @@ def _resolve(
if assoc == "fail":
ret = "err"
elif assoc == "left":
if type(oldAct) == ShiftAction:
if type(oldAct) is ShiftAction:
ret = "new"
else:
assert type(newAct) == ShiftAction
assert type(newAct) is ShiftAction
ret = "old"
elif assoc == "right":
if type(oldAct) == ShiftAction:
if type(oldAct) is ShiftAction:
ret = "old"
else:
assert type(newAct) == ShiftAction
assert type(newAct) is ShiftAction
ret = "new"
elif assoc == "nonassoc":
ret = "neither"
Expand Down
10 changes: 5 additions & 5 deletions parsing/glrparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def token(self, token: Token) -> None:
tokenSpec = self._spec.sym_spec(token)
self._act(token, tokenSpec) # type: ignore
if len(self._gss) == 0:
raise UnexpectedToken("Unexpected token: %r" % token)
raise UnexpectedToken(f"Unexpected token: {token:r}")

def eoi(self) -> None:
"""
Expand All @@ -141,7 +141,7 @@ def eoi(self) -> None:
for path in top.paths():
assert len(path) == 5
if self.verbose:
print(" --> accept %r" % path)
print(f" --> accept {path:r}")
edge = path[1]
assert isinstance(edge, Gsse)
assert isinstance(edge.value, Nonterm)
Expand Down Expand Up @@ -181,7 +181,7 @@ def _reductions(self, sym: Token, symSpec: TokenSpec) -> None:
self._gss.pop(i)
else:
for action in self._action[top.nextState][symSpec]:
if type(action) == ReduceAction:
if type(action) is ReduceAction:
if len(action.production.rhs) == 0:
if action.production not in epsilons:
assert (
Expand Down Expand Up @@ -324,7 +324,7 @@ def _enqueueLimitedReductions(
for top in self._gss:
if symSpec in self._action[top.nextState]:
for action in self._action[top.nextState][symSpec]:
if type(action) == ReduceAction:
if type(action) is ReduceAction:
if len(action.production.rhs) == 0:
if (
gotos[top.nextState][action.production.lhs]
Expand Down Expand Up @@ -377,7 +377,7 @@ def _shifts(self, sym: Token, symSpec: TokenSpec) -> None:
for topA in prevGss:
if symSpec in self._action[topA.nextState]:
for action in self._action[topA.nextState][symSpec]:
if type(action) == ShiftAction:
if type(action) is ShiftAction:
merged = False
for topB in self._gss:
if topB.nextState == topA.nextState:
Expand Down
6 changes: 3 additions & 3 deletions parsing/lrparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Lr(Parser):

def __init__(self, spec: Spec) -> None:
if __debug__:
if type(self) == Lr:
if type(self) is Lr:
assert spec.pureLR
assert spec.conflicts == 0
self._spec = spec
Expand Down Expand Up @@ -86,11 +86,11 @@ def _act(self, sym: Token, symSpec: TokenSpec) -> None:

if self.verbose:
print(" --> %r" % action)
if type(action) == ShiftAction:
if type(action) is ShiftAction:
self._stack.append((sym, action.nextState))
break
else:
assert type(action) == ReduceAction
assert type(action) is ReduceAction
self._reduce(action.production)

if self.verbose:
Expand Down
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
[project]
name = "parsing"
description = "LR(1) parser generator for Python"
description = "LR(1) parser generator for Python and CFSM and GLR parser drivers"
requires-python = ">=3.7.0"
dynamic = ["version"]
dynamic = ["version", "dependencies", "optional-dependencies"]
license = { file = "LICENSE" }
authors = [{ name = "Jason Evans", email = "[email protected]" }]
readme = { file = "README.rst", content-type = "text/x-rst" }
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Compilers',
'Topic :: Text Processing :: General',
]

[build-system]
requires = ["setuptools>=42", "wheel"]
Expand Down
22 changes: 0 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
_ROOT = pathlib.Path(__file__).parent


with open(str(_ROOT / "README.rst")) as f:
readme = f.read()


with open(str(_ROOT / "parsing" / "_version.py")) as f:
for line in f:
if line.startswith("__version__ ="):
Expand Down Expand Up @@ -88,26 +84,8 @@ def finalize_options(self) -> None:


setup(
name="parsing",
version=VERSION,
python_requires=">=3.7.0",
url="http://www.canonware.com/Parsing/",
license="MIT",
author="Jason Evans",
author_email="[email protected]",
description="A pure-Python module that implements an LR(1) "
"parser generator, as well as CFSM and GLR parser drivers.",
long_description=readme,
long_description_content_type="text/x-rst",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Compilers",
"Topic :: Text Processing :: General",
],
packages=["parsing", "parsing.tests", "parsing.tests.specs"],
package_data={"parsing": ["py.typed"]},
setup_requires=setup_requires,
Expand Down

0 comments on commit bfdf958

Please sign in to comment.