From e522fceb68d07ea55708b2e9dd4988d258e6e525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Fri, 24 Nov 2023 15:03:40 +0100 Subject: [PATCH 1/4] Update setup.py for setuptools 69 --- parsing/glrparser.py | 4 ++-- pyproject.toml | 18 +++++++++++++++++- setup.py | 23 ----------------------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/parsing/glrparser.py b/parsing/glrparser.py index 3cda854..00da41a 100644 --- a/parsing/glrparser.py +++ b/parsing/glrparser.py @@ -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: """ @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 1d5d465..f74994d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,24 @@ [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"] +license = { file = "" } +authors = [{ name = "Jason Evans", email = "jasone@canonware.com" }] +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', +] +dependencies = ['mypy-extensions>=1.0.0'] + +[project.optional-dependencies] +test = ['flake8', 'mypy>=1.4.1'] [build-system] requires = ["setuptools>=42", "wheel"] diff --git a/setup.py b/setup.py index d22ed29..c2c0522 100644 --- a/setup.py +++ b/setup.py @@ -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__ ="): @@ -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="jasone@canonware.com", - 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, @@ -118,6 +96,5 @@ def finalize_options(self) -> None: MYPY_DEPENDENCY, ] }, - install_requires=["mypy-extensions>=1.0.0"], cmdclass={"build_ext": build_ext}, ) From 22a33b1253228dc2edc3f1a1bc870cd74ddc4a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Fri, 24 Nov 2023 15:08:56 +0100 Subject: [PATCH 2/4] fix --- pyproject.toml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f74994d..903cfdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,8 +2,8 @@ name = "parsing" description = "LR(1) parser generator for Python and CFSM and GLR parser drivers" requires-python = ">=3.7.0" -dynamic = ["version"] -license = { file = "" } +dynamic = ["version", "dependencies", "optional-dependencies"] +license = { file = "LICENSE" } authors = [{ name = "Jason Evans", email = "jasone@canonware.com" }] readme = { file = "README.rst", content-type = "text/x-rst" } classifiers = [ @@ -15,10 +15,6 @@ classifiers = [ 'Topic :: Software Development :: Compilers', 'Topic :: Text Processing :: General', ] -dependencies = ['mypy-extensions>=1.0.0'] - -[project.optional-dependencies] -test = ['flake8', 'mypy>=1.4.1'] [build-system] requires = ["setuptools>=42", "wheel"] From 69f88cb46db645619c550af55297e28ee133e097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Fri, 24 Nov 2023 17:49:58 +0100 Subject: [PATCH 3/4] Fix flake8 test regarding type checking --- parsing/automaton.py | 28 ++++++++++++++-------------- parsing/glrparser.py | 6 +++--- parsing/lrparser.py | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/parsing/automaton.py b/parsing/automaton.py index 0f8be6e..8f40da2 100644 --- a/parsing/automaton.py +++ b/parsing/automaton.py @@ -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 @@ -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]" % ( @@ -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) @@ -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 @@ -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: @@ -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" diff --git a/parsing/glrparser.py b/parsing/glrparser.py index 00da41a..3e4459a 100644 --- a/parsing/glrparser.py +++ b/parsing/glrparser.py @@ -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 ( @@ -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] @@ -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: diff --git a/parsing/lrparser.py b/parsing/lrparser.py index 54dcc40..3b7662b 100644 --- a/parsing/lrparser.py +++ b/parsing/lrparser.py @@ -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 @@ -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: From df8d08afaff64f20d9e46f75a5bb63a069b1542a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Fri, 24 Nov 2023 18:53:27 +0100 Subject: [PATCH 4/4] fix --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index c2c0522..b424cc3 100644 --- a/setup.py +++ b/setup.py @@ -96,5 +96,6 @@ def finalize_options(self) -> None: MYPY_DEPENDENCY, ] }, + install_requires=["mypy-extensions>=1.0.0"], cmdclass={"build_ext": build_ext}, )