Repository: astanin/python-tabulate
Pull request #201 (2022-10-06 14:38:55)

Merge dev-pep621 - migrate to pyproject.toml


Patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1904e2a..ac9c525 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -39,6 +39,16 @@ jobs:
             - ./venv
           key: v1-dependencies-{{ checksum ".circleci/requirements.txt" }}
 
+      - run:
+          name: build wheel
+          command: |
+            . venv/bin/activate
+            python -m build -nwx .
+
+      - store_artifacts:
+          path: dist
+          destination: dist
+
       - run:
           name: run tests
           command: |
diff --git a/.circleci/requirements.txt b/.circleci/requirements.txt
index 650d583..ea5e80c 100644
--- a/.circleci/requirements.txt
+++ b/.circleci/requirements.txt
@@ -3,3 +3,8 @@ tox
 numpy
 pandas
 wcwidth
+setuptools
+pip
+build
+wheel
+setuptools_scm
diff --git a/.gitignore b/.gitignore
index 460933e..0495ac7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+/tabulate/version.py
+
 build
 dist
 .tox
diff --git a/HOWTOPUBLISH b/HOWTOPUBLISH
index 6730e8a..5be16ed 100644
--- a/HOWTOPUBLISH
+++ b/HOWTOPUBLISH
@@ -1,8 +1,7 @@
 # update contributors and CHANGELOG in README
+# tag version release
 python3 benchmark.py  # then update README
-tox -e py33,py34,py36-extra
-python3 setup.py sdist bdist_wheel
+tox -e py37-extra,py38-extra,py39-extra,py310-extra
+python3 -m build -nswx .
 twine upload --repository-url https://test.pypi.org/legacy/ dist/*
 twine upload dist/*
-# tag version release
-# bump version number in setup.py in tabulate.py
diff --git a/appveyor.yml b/appveyor.yml
index ddf7b3c..e7aae8e 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -17,8 +17,11 @@ environment:
     - PYTHON: "C:\\Python310-x64"
 
 install:
+  # Newer setuptools is needed for proper support of pyproject.toml
+  - "%PYTHON%\\python.exe -m pip install setuptools --upgrade"
   # We need wheel installed to build wheels
-  - "%PYTHON%\\python.exe -m pip install wheel"
+  - "%PYTHON%\\python.exe -m pip install wheel --upgrade"
+  - "%PYTHON%\\python.exe -m pip install build setuptools_scm"
   - "%PYTHON%\\python.exe -m pip install pytest numpy pandas"
 
 build: off
@@ -40,7 +43,7 @@ after_test:
   # 64-bit Python 3.3/3.4. And you need to use %PYTHON% to get the correct
   # interpreter
   #- "build.cmd %PYTHON%\\python.exe setup.py bdist_wheel"
-  - "%PYTHON%\\python.exe setup.py sdist bdist_wheel"
+  - "%PYTHON%\\python.exe -m build -nswx ."
 
 artifacts:
   # bdist_wheel puts your built wheel in the dist directory
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..85ede02
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,38 @@
+[build-system]
+requires = ["setuptools>=61.2.0", "wheel", "setuptools_scm[toml]>=3.4.3"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "tabulate"
+authors = [{name = "Sergey Astanin", email = "s.astanin@gmail.com"}]
+license = {text = "MIT"}
+description = "Pretty-print tabular data"
+readme = "README.md"
+classifiers = [
+    "Development Status :: 4 - Beta",
+    "License :: OSI Approved :: MIT License",
+    "Operating System :: OS Independent",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3.7",
+    "Programming Language :: Python :: 3.8",
+    "Programming Language :: Python :: 3.9",
+    "Programming Language :: Python :: 3.10",
+    "Topic :: Software Development :: Libraries",
+]
+requires-python = ">=3.7"
+dynamic = ["version"]
+
+[project.urls]
+Homepage = "https://github.com/astanin/python-tabulate"
+
+[project.optional-dependencies]
+widechars = ["wcwidth"]
+
+[project.scripts]
+tabulate = "tabulate:_main"
+
+[tool.setuptools]
+packages = ["tabulate"]
+
+[tool.setuptools_scm]
+write_to = "tabulate/version.py"
diff --git a/setup.py b/setup.py
deleted file mode 100644
index bbff185..0000000
--- a/setup.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python
-
-try:
-    from setuptools import setup
-except ImportError:
-    from distutils.core import setup
-
-
-from platform import python_implementation
-import os
-import re
-
-# strip links from the description on the PyPI
-LONG_DESCRIPTION = open("README.md", encoding="utf-8").read()
-
-# strip Build Status from the PyPI package
-try:
-    status_re = "^Build status\n(.*\n){7}"
-    LONG_DESCRIPTION = re.sub(status_re, "", LONG_DESCRIPTION, flags=re.M)
-except TypeError:
-    if python_implementation() == "IronPython":
-        # IronPython doesn't support flags in re.sub (IronPython issue #923)
-        pass
-    else:
-        raise
-
-install_options = os.environ.get("TABULATE_INSTALL", "").split(",")
-libonly_flags = {"lib-only", "libonly", "no-cli", "without-cli"}
-if libonly_flags.intersection(install_options):
-    console_scripts = []
-else:
-    console_scripts = ["tabulate = tabulate:_main"]
-
-
-setup(
-    name="tabulate",
-    version="0.8.11",
-    description="Pretty-print tabular data",
-    long_description=LONG_DESCRIPTION,
-    long_description_content_type="text/markdown",
-    author="Sergey Astanin",
-    author_email="s.astanin@gmail.com",
-    url="https://github.com/astanin/python-tabulate",
-    license="MIT",
-    python_requires=">=3.7",
-    classifiers=[
-        "Development Status :: 4 - Beta",
-        "License :: OSI Approved :: MIT License",
-        "Operating System :: OS Independent",
-        "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.7",
-        "Programming Language :: Python :: 3.8",
-        "Programming Language :: Python :: 3.9",
-        "Programming Language :: Python :: 3.10",
-        "Programming Language :: Python :: 3 :: Only",
-        "Topic :: Software Development :: Libraries",
-    ],
-    py_modules=["tabulate"],
-    entry_points={"console_scripts": console_scripts},
-    extras_require={"widechars": ["wcwidth"]},
-)
diff --git a/tabulate.py b/tabulate/__init__.py
similarity index 99%
rename from tabulate.py
rename to tabulate/__init__.py
index 46f2e0d..503df34 100644
--- a/tabulate.py
+++ b/tabulate/__init__.py
@@ -22,7 +22,10 @@ def _is_file(f):
 
 
 __all__ = ["tabulate", "tabulate_formats", "simple_separated_format"]
-__version__ = "0.8.11"
+try:
+    from .version import version as __version__  # noqa: F401
+except ImportError:
+    pass  # running __init__.py as a script, AppVeyor pytests
 
 
 # minimum extra space in headers
diff --git a/tox.ini b/tox.ini
index 891912a..619f447 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,6 +9,7 @@
 
 [tox]
 envlist = lint, py{37, 38, 39, 310}
+isolated_build = True
 
 [testenv]
 commands = pytest -v --doctest-modules --ignore benchmark.py {posargs}


Test patch:
diff --git a/test/test_cli.py b/test/test_cli.py
index 8c0c9da..ce85f19 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -113,7 +113,7 @@ class TemporaryTextFile:
 
 def test_script_from_stdin_to_stdout():
     """Command line utility: read from stdin, print to stdout"""
-    cmd = [sys.executable, "tabulate.py"]
+    cmd = [sys.executable, "tabulate/__init__.py"]
     out = run_and_capture_stdout(cmd, input=sample_input())
     expected = SAMPLE_SIMPLE_FORMAT
     print("got:     ", repr(out))
@@ -126,7 +126,7 @@ def test_script_from_file_to_stdout():
     with TemporaryTextFile() as tmpfile:
         tmpfile.write(sample_input())
         tmpfile.seek(0)
-        cmd = [sys.executable, "tabulate.py", tmpfile.name]
+        cmd = [sys.executable, "tabulate/__init__.py", tmpfile.name]
         out = run_and_capture_stdout(cmd)
         expected = SAMPLE_SIMPLE_FORMAT
         print("got:     ", repr(out))
@@ -142,7 +142,7 @@ def test_script_from_file_to_file():
             input_file.seek(0)
             cmd = [
                 sys.executable,
-                "tabulate.py",
+                "tabulate/__init__.py",
                 "-o",
                 output_file.name,
                 input_file.name,
@@ -165,7 +165,7 @@ def test_script_from_file_to_file():
 def test_script_header_option():
     """Command line utility: -1, --header option"""
     for option in ["-1", "--header"]:
-        cmd = [sys.executable, "tabulate.py", option]
+        cmd = [sys.executable, "tabulate/__init__.py", option]
         raw_table = sample_input(with_headers=True)
         out = run_and_capture_stdout(cmd, input=raw_table)
         expected = SAMPLE_SIMPLE_FORMAT_WITH_HEADERS
@@ -178,7 +178,7 @@ def test_script_header_option():
 def test_script_sep_option():
     """Command line utility: -s, --sep option"""
     for option in ["-s", "--sep"]:
-        cmd = [sys.executable, "tabulate.py", option, ","]
+        cmd = [sys.executable, "tabulate/__init__.py", option, ","]
         raw_table = sample_input(sep=",")
         out = run_and_capture_stdout(cmd, input=raw_table)
         expected = SAMPLE_SIMPLE_FORMAT
@@ -190,7 +190,14 @@ def test_script_sep_option():
 def test_script_floatfmt_option():
     """Command line utility: -F, --float option"""
     for option in ["-F", "--float"]:
-        cmd = [sys.executable, "tabulate.py", option, ".1e", "--format", "grid"]
+        cmd = [
+            sys.executable,
+            "tabulate/__init__.py",
+            option,
+            ".1e",
+            "--format",
+            "grid",
+        ]
         raw_table = sample_input()
         out = run_and_capture_stdout(cmd, input=raw_table)
         expected = SAMPLE_GRID_FORMAT_WITH_DOT1E_FLOATS
@@ -202,7 +209,7 @@ def test_script_floatfmt_option():
 def test_script_format_option():
     """Command line utility: -f, --format option"""
     for option in ["-f", "--format"]:
-        cmd = [sys.executable, "tabulate.py", "-1", option, "grid"]
+        cmd = [sys.executable, "tabulate/__init__.py", "-1", option, "grid"]
         raw_table = sample_input(with_headers=True)
         out = run_and_capture_stdout(cmd, input=raw_table)
         expected = SAMPLE_GRID_FORMAT_WITH_HEADERS