From dbb3b39ab4bee1b5554876838530b42a1d741acf Mon Sep 17 00:00:00 2001
From: Alec Delaney <tekktrik@gmail.com>
Date: Tue, 9 Aug 2022 14:27:12 -0400
Subject: [PATCH] Switched to pyproject.toml

---
 .github/workflows/build.yml   | 19 +++++------
 .github/workflows/release.yml | 16 ++++-----
 optional_requirements.txt     |  3 ++
 pyproject.toml                | 50 ++++++++++++++++++++++++---
 setup.py                      | 64 -----------------------------------
 5 files changed, 65 insertions(+), 87 deletions(-)
 create mode 100644 optional_requirements.txt
 delete mode 100644 setup.py

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b39da4a..22f6582 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -59,22 +59,19 @@ jobs:
       with:
         name: bundles
         path: ${{ github.workspace }}/bundles/
-    - name: Check for docs folder
-      id: need-docs
-      run: |
-        echo ::set-output name=docs::$( find . -wholename './docs' )
     - name: Build docs
-      if: contains(steps.need-docs.outputs.docs, 'docs')
       working-directory: docs
       run: sphinx-build -E -W -b html . _build/html
-    - name: Check For setup.py
+    - name: Check For pyproject.toml
       id: need-pypi
       run: |
-        echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
+        echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' )
     - name: Build Python package
-      if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
+      if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml')
       run: |
-        pip install --upgrade setuptools wheel twine readme_renderer testresources
-        python setup.py sdist
-        python setup.py bdist_wheel --universal
+        pip install --upgrade build twine
+        for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do
+            sed -i -e "s/0.0.0-auto.0/1.2.3/" $file;
+        done;
+        python -m build
         twine check dist/*
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b279a99..d1b4f8d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -61,28 +61,28 @@ jobs:
     runs-on: ubuntu-latest
     steps:
     - uses: actions/checkout@v1
-    - name: Check For setup.py
+    - name: Check For pyproject.toml
       id: need-pypi
       run: |
-        echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
+        echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' )
     - name: Set up Python
-      if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
+      if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml')
       uses: actions/setup-python@v2
       with:
         python-version: '3.x'
     - name: Install dependencies
-      if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
+      if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml')
       run: |
         python -m pip install --upgrade pip
-        pip install setuptools wheel twine
+        pip install --upgrade build twine
     - name: Build and publish
-      if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
+      if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml')
       env:
         TWINE_USERNAME: ${{ secrets.pypi_username }}
         TWINE_PASSWORD: ${{ secrets.pypi_password }}
       run: |
-        for file in $(find -not -path "./.*" -not -path "./docs*" -name "*.py"); do
+        for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do
             sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file;
         done;
-        python setup.py sdist
+        python -m build
         twine upload dist/*
diff --git a/optional_requirements.txt b/optional_requirements.txt
new file mode 100644
index 0000000..d4e27c4
--- /dev/null
+++ b/optional_requirements.txt
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
+#
+# SPDX-License-Identifier: Unlicense
diff --git a/pyproject.toml b/pyproject.toml
index f3c35ae..48a83f2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,48 @@
-# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
+# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries
 #
-# SPDX-License-Identifier: Unlicense
+# SPDX-License-Identifier: MIT
 
-[tool.black]
-target-version = ['py35']
+[build-system]
+requires = [
+    "setuptools",
+    "wheel",
+    "setuptools-scm",
+]
+
+[project]
+name = "adafruit-circuitpython-ags02ma"
+description = "CircuitPython / Python library for AGS02MA gas sensor"
+version = "0.0.0-auto.0"
+readme = "README.rst"
+authors = [
+    {name = "Adafruit Industries", email = "circuitpython@adafruit.com"}
+]
+urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_AGS02MA"}
+keywords = [
+    "adafruit",
+    "blinka",
+    "circuitpython",
+    "micropython",
+    "ags02ma",
+    "tvoc",
+    "gas",
+    "resistance",
+    "sensor",
+]
+license = {text = "MIT"}
+classifiers = [
+    "Intended Audience :: Developers",
+    "Topic :: Software Development :: Libraries",
+    "Topic :: Software Development :: Embedded Systems",
+    "Topic :: System :: Hardware",
+    "License :: OSI Approved :: MIT License",
+    "Programming Language :: Python :: 3",
+]
+dynamic = ["dependencies", "optional-dependencies"]
+
+[tool.setuptools]
+py-modules = ["adafruit_ags02ma"]
+
+[tool.setuptools.dynamic]
+dependencies = {file = ["requirements.txt"]}
+optional-dependencies = {optional = {file = ["optional_requirements.txt"]}}
diff --git a/setup.py b/setup.py
deleted file mode 100644
index d6ec38b..0000000
--- a/setup.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
-# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
-#
-# SPDX-License-Identifier: MIT
-
-"""A setuptools based setup module.
-
-See:
-https://packaging.python.org/en/latest/distributing.html
-https://github.com/pypa/sampleproject
-"""
-
-from setuptools import setup, find_packages
-
-# To use a consistent encoding
-from codecs import open
-from os import path
-
-here = path.abspath(path.dirname(__file__))
-
-# Get the long description from the README file
-with open(path.join(here, "README.rst"), encoding="utf-8") as f:
-    long_description = f.read()
-
-setup(
-    # Adafruit Bundle Information
-    name="adafruit-circuitpython-ags02ma",
-    use_scm_version={
-        # This is needed for the PyPI version munging in the Github Actions release.yml
-        "git_describe_command": "git describe --tags --long",
-        "local_scheme": "no-local-version",
-    },
-    setup_requires=["setuptools_scm"],
-    description="AGS02MA TVOC / Gas sensor",
-    long_description=long_description,
-    long_description_content_type="text/x-rst",
-    # The project's main homepage.
-    url="https://github.com/adafruit/Adafruit_CircuitPython_AGS02MA.git",
-    # Author details
-    author="Adafruit Industries",
-    author_email="circuitpython@adafruit.com",
-    install_requires=[
-        "Adafruit-Blinka",
-        "adafruit-circuitpython-busdevice",
-    ],
-    # Choose your license
-    license="MIT",
-    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
-    classifiers=[
-        "Development Status :: 3 - Alpha",
-        "Intended Audience :: Developers",
-        "Topic :: Software Development :: Libraries",
-        "Topic :: System :: Hardware",
-        "License :: OSI Approved :: MIT License",
-        "Programming Language :: Python :: 3",
-    ],
-    # What does your project relate to?
-    keywords="adafruit blinka circuitpython micropython ags02ma tvoc gas resistance sensor",
-    # You can just specify the packages manually here if your project is
-    # simple. Or you can use find_packages().
-    # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
-    #       CHANGE `py_modules=['...']` TO `packages=['...']`
-    py_modules=["adafruit_ags02ma"],
-)