From c89c68759abcce8e1410fe3627f97f10a2fde020 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 18 Feb 2024 22:49:32 -0800 Subject: [PATCH 1/4] pyproject.toml: Move metadata here from setup.py --- pyproject.toml | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 3 --- setup.py | 40 +----------------------------------- 3 files changed, 56 insertions(+), 42 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7e8d236 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,55 @@ +[build-system] +requires = [ + "setuptools>=61.2", +] +build-backend = "setuptools.build_meta" + +[project] +name = "Mathics_Scanner" +version = "1.3.0" +description = "Character Tables and Tokenizer for Mathics and the Wolfram Language." +dependencies = [ + "PyYAML", + "chardet", + "click", +] +requires-python = ">=3.8" +readme = "README.rst" +license = {text = "GPL-3.0-only"} +keywords = ["Mathematica", "Wolfram", "Interpreter", "Shell", "Math", "CAS"] +maintainers = [ + {name = "Mathics Group"}, +] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Physics", + "Topic :: Software Development :: Interpreters", +] + +[project.urls] +Homepage = "https://mathics.org/" + +[project.optional-dependencies] +dev = [ + "pytest", +] +full = [ + "ujson", +] + +[project.scripts] +mathics-generate-json-table = "mathics_scanner.generate.build_tables:main" + +[tool.setuptools.dynamic] +version = {attr = "mathics_scanner.version.__version__"} diff --git a/setup.cfg b/setup.cfg index 5ad512b..8dd4c40 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,3 @@ -[metadata] -description_file = README.rst - # Recommended flake8 settings while editing zoom, we use Black for the final # linting/say in how code is formatted # diff --git a/setup.py b/setup.py index f0596f4..448ae1b 100644 --- a/setup.py +++ b/setup.py @@ -50,11 +50,6 @@ def read(*rnames): return open(osp.join(get_srcdir(), *rnames)).read() -from mathics_scanner.version import __version__ - -# Get/set __version__ and long_description from files -long_description = read("README.rst") + "\n" - is_PyPy = platform.python_implementation() == "PyPy" or hasattr( sys, "pypy_version_info" ) @@ -86,16 +81,9 @@ def subdirs(root, file="*.*", depth=10): setup( - name="Mathics_Scanner", - version=__version__, packages=["mathics_scanner", "mathics_scanner.generate"], install_requires=INSTALL_REQUIRES, extras_require=EXTRAS_REQUIRE, - entry_points={ - "console_scripts": [ - "mathics-generate-json-table=mathics_scanner.generate.build_tables:main" - ] - }, package_data={ "mathics_scanner": [ "data/named-characters.yml", @@ -105,34 +93,8 @@ def subdirs(root, file="*.*", depth=10): "data/ExampleData/*", ] }, - long_description=long_description, - long_description_content_type="text/x-rst", # don't pack Mathics in egg because of media files, etc. zip_safe=False, - # metadata for upload to PyPI - maintainer="Mathics Group", - description="Character Tables and Tokenizer for Mathics and the Wolfram Language.", - license="GPL-3.0-only", - url="https://mathics.org/", - keywords=["Mathematica", "Wolfram", "Interpreter", "Shell", "Math", "CAS"], - classifiers=[ - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Scientific/Engineering", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Scientific/Engineering :: Physics", - "Topic :: Software Development :: Interpreters", - ], - # TODO: could also include long_description, download_url, ) @@ -145,4 +107,4 @@ def build_json_table() -> int: return result.returncode -atexit.register(build_json_table) +# atexit.register(build_json_table) ## does not work with build isolation From 4e82ac59af1804a68d0356277600c1da83c81365 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 19 Feb 2024 14:43:21 -0800 Subject: [PATCH 2/4] pyproject.toml: Make version 'dynamic' --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7e8d236..3ad450a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,6 @@ build-backend = "setuptools.build_meta" [project] name = "Mathics_Scanner" -version = "1.3.0" description = "Character Tables and Tokenizer for Mathics and the Wolfram Language." dependencies = [ "PyYAML", @@ -36,6 +35,7 @@ classifiers = [ "Topic :: Scientific/Engineering :: Physics", "Topic :: Software Development :: Interpreters", ] +dynamic = ["version"] [project.urls] Homepage = "https://mathics.org/" From 316c3ae5d5d1df6fb2ee780ddb19d8ef33920f31 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 19 Feb 2024 16:28:40 -0800 Subject: [PATCH 3/4] setup.py: Use custom egg_info command class for building tables --- mathics_scanner/generate/build_tables.py | 6 ++++- pyproject.toml | 3 +++ setup.py | 29 +++++++++++++----------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mathics_scanner/generate/build_tables.py b/mathics_scanner/generate/build_tables.py index be28e46..c7efc5b 100755 --- a/mathics_scanner/generate/build_tables.py +++ b/mathics_scanner/generate/build_tables.py @@ -11,7 +11,11 @@ import os.path as osp from pathlib import Path -from mathics_scanner.version import __version__ +try: + from mathics_scanner.version import __version__ +except ImportError: + # When using build isolation + __version__ = 'unknown' def get_srcdir(): diff --git a/pyproject.toml b/pyproject.toml index 3ad450a..31cb07e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,9 @@ [build-system] requires = [ "setuptools>=61.2", + # needed for building tables for the sdist: + "PyYAML", + "click", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 448ae1b..cf4dfd5 100644 --- a/setup.py +++ b/setup.py @@ -32,8 +32,9 @@ import subprocess import sys -import pkg_resources from setuptools import setup +from setuptools.command.egg_info import egg_info + # Ensure user has the correct Python version if sys.version_info < (3, 7): @@ -80,7 +81,21 @@ def subdirs(root, file="*.*", depth=10): yield root + "*/" * k + file +class table_building_egg_info(egg_info): + # This runs as part of building an sdist + + def finalize_options(self): + """Run program to create JSON tables""" + build_tables_program = osp.join(get_srcdir(), "mathics_scanner", "generate", "build_tables.py") + print(f"Building JSON tables via {build_tables_program}") + result = subprocess.run([sys.executable, build_tables_program]) + if result.returncode: + raise RuntimeError(f"Running {build_tables_program} exited with code {result.returncode}") + super().finalize_options() + + setup( + cmdclass={"egg_info": table_building_egg_info}, packages=["mathics_scanner", "mathics_scanner.generate"], install_requires=INSTALL_REQUIRES, extras_require=EXTRAS_REQUIRE, @@ -96,15 +111,3 @@ def subdirs(root, file="*.*", depth=10): # don't pack Mathics in egg because of media files, etc. zip_safe=False, ) - - -def build_json_table() -> int: - """Run program to create JSON tables""" - ROOT_DIR = pkg_resources.resource_filename("mathics_scanner", "") - build_tables_program = osp.join(ROOT_DIR, "generate", "build_tables.py") - print(f"Building JSON tables via f{build_tables_program}") - result = subprocess.run([sys.executable, build_tables_program]) - return result.returncode - - -# atexit.register(build_json_table) ## does not work with build isolation From 5a4a922fb5c47a92fd81488ac2f0ff5a4a858f27 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 19 Feb 2024 17:41:39 -0800 Subject: [PATCH 4/4] Reformat using black --- mathics_scanner/generate/build_tables.py | 2 +- setup.py | 8 ++++++-- test/test_general_yaml_sanity.py | 2 -- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mathics_scanner/generate/build_tables.py b/mathics_scanner/generate/build_tables.py index c7efc5b..b2f845a 100755 --- a/mathics_scanner/generate/build_tables.py +++ b/mathics_scanner/generate/build_tables.py @@ -15,7 +15,7 @@ from mathics_scanner.version import __version__ except ImportError: # When using build isolation - __version__ = 'unknown' + __version__ = "unknown" def get_srcdir(): diff --git a/setup.py b/setup.py index cf4dfd5..d0c7634 100644 --- a/setup.py +++ b/setup.py @@ -86,11 +86,15 @@ class table_building_egg_info(egg_info): def finalize_options(self): """Run program to create JSON tables""" - build_tables_program = osp.join(get_srcdir(), "mathics_scanner", "generate", "build_tables.py") + build_tables_program = osp.join( + get_srcdir(), "mathics_scanner", "generate", "build_tables.py" + ) print(f"Building JSON tables via {build_tables_program}") result = subprocess.run([sys.executable, build_tables_program]) if result.returncode: - raise RuntimeError(f"Running {build_tables_program} exited with code {result.returncode}") + raise RuntimeError( + f"Running {build_tables_program} exited with code {result.returncode}" + ) super().finalize_options() diff --git a/test/test_general_yaml_sanity.py b/test/test_general_yaml_sanity.py index 00d7fd1..ffa4edc 100644 --- a/test/test_general_yaml_sanity.py +++ b/test/test_general_yaml_sanity.py @@ -30,7 +30,6 @@ def check_has_attr(attr: str): def test_yaml_field_names(): for k, v in yaml_data.items(): - diff = set(v.keys()) - { "amslatex", "ascii", @@ -125,7 +124,6 @@ def test_precedence(): def test_unicode_name(): for k, v in yaml_data.items(): - # Hack to skip characters that are correct but that doesn't show up in # unicodedata.name if "unicode-equivalent-name" not in v: