Repository: Knio/dominate (language: python)

Issue:
Replace deprecated imp module with importlib
This project uses the [`imp` module](https://docs.python.org/3/library/imp.html) which has been deprecated since Python 3.4 and set for removal in 3.12:

* Raised `PendingDeprecationWarning` since [3.4 (2014)](https://github.com/python/cpython/commit/e4f41deccf94ccc798b1eb1f44657ade66669a60)
* Raised `DeprecationWarning` since [3.5 (2015)](https://github.com/python/cpython/commit/c0d91aff9a3b91307b26e8b7c34dfbf27bbdd43a)
* Updated `DeprecationWarning` to say removal in 3.12 since [3.10 (2021)](https://github.com/python/cpython/commit/dc6d3e1e4c0c1e4b2210edab8fb4762569dc2936)
* Removal planned for [3.12](https://github.com/python/cpython/issues/98040) [(2023)](https://github.com/python/cpython/pull/98573)

Python 3.12 is [set for release on 2023-10-02](https://devguide.python.org/versions/) and this library is one of the [top 5,000 most-downloaded from PyPI](https://hugovk.github.io/top-pypi-packages/).

Please could you upgrade to use `importlib`? The [`imp` docs](https://docs.python.org/3.11/library/imp.html) have suggestions on what to use to replace each function and constant.




Discussion / hints:
Ping. This is blocking Python 3.12 support on flask-nav.
Ping.

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0fa9b93..950b500 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -17,45 +17,44 @@ jobs:
        python: ["3"]
        os: ["ubuntu-latest"]
        include:
-          - {python: "2.7", os: "ubuntu-22.04"}
-          # https://github.blog/changelog/2022-08-09-github-actions-the-ubuntu-18-04-actions-runner-image-is-being-deprecated-and-will-be-removed-by-12-1-22/
-          # - {python: "3.4", os: "ubuntu-18.04"}
-          - {python: "3.5", os: "ubuntu-20.04"}
-          - {python: "3.6", os: "ubuntu-20.04"}
           - {python: "3.7", os: "ubuntu-22.04"}
           - {python: "3.8", os: "ubuntu-22.04"}
           - {python: "3.9", os: "ubuntu-22.04"}
           - {python: "3.10", os: "ubuntu-22.04"}
           - {python: "3.11", os: "ubuntu-22.04"}
+          - {python: "3.12", os: "ubuntu-22.04"}
     steps:
     - uses: actions/checkout@v3
-    - name: Set up Python ${{ matrix.python }}
+    - name: "Set up Python ${{ matrix.python }}"
       uses: actions/setup-python@v3
       with:
         python-version: ${{ matrix.python }}
-    - name: Install dependencies
+    - name: "Install dependencies"
       run: |
-        python -m pip install --upgrade pip
+        # python -m pip install --upgrade pip
         python -m pip install pytest
         python -m pip install mock
         python -m pip install flake8
-        python -m pip install importlib_metadata 
-    - name: Lint with flake8
+        python -m pip install importlib_metadata
+        python -m pip install "setuptools>=62"
+        python -m pip install wheel
+        python -m pip install build
+    - name: "Lint with flake8"
       run: |
         # stop the build if there are Python syntax errors or undefined names
         flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
         flake8 . --count --exit-zero --max-complexity=10 --max-line-length=80 --statistics
-    - name: Build and test
+    - name: "Build and test"
       run: |
-        python setup.py sdist --formats=zip
-        pip install dist/dominate*.zip
+        python -m build --no-isolation
+        pip install dist/dominate*.tar.gz
         pytest
     - name: Coveralls
-      env: 
+      env:
         COVERAGE_RCFILE: ".github/workflows/.coveragerc"
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
       run: |
-        python -m pip install "coverage"
-        python -m pip install "coveralls"
+        python -m pip install coverage
+        python -m pip install coveralls
         coverage run --source=dominate -m pytest
         python -m coveralls --service=github || true
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 44b5dcb..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-language: python
-
-python:
-  - "2.7"
-  - "3.4"
-  - "3.5"
-  - "3.6"
-  - "3.7"
-  - "3.8"
-  - "3.9"
-  - "3.10-dev"
-  - "pypy"
-  - "pypy3"
-
-# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
-install:
-    - pip install pip --upgrade
-    - pip install importlib_metadata --upgrade # fix for broken py3.7
-    - pip install pytest>=2.7.3 --upgrade
-    - pip install mock --upgrade
-
-# command to run tests, e.g. python setup.py test
-script:
-    - python setup.py sdist --formats=zip
-    - pip install dist/dominate*.zip
-    - py.test
-
-after_success:
-    - pip install coveralls coverage
-    - PYTHONPATH=. coverage run --source=dominate -m pytest
-    - coverage report
-    - coveralls
-
-sudo: false
diff --git a/MANIFEST.in b/MANIFEST.in
index e9a430a..11521c7 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,5 +1,7 @@
 include README.md
 include LICENSE.txt
+include pyproject.toml
+include setup/setup.py
 recursive-include tests *
 global-exclude __pycache__
 global-exclude *.pyc
diff --git a/Makefile b/Makefile
index be3476e..1fe0cc0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,17 @@
 test:
-	python2 -m pytest .
+	-python2 -m pytest .
 	python3 -m pytest .
 
-publish: test
-	rm dist/ -r
-	python3 setup.py sdist
-	python3 setup.py bdist_wheel
+publish_old: clean test
+	python3 setup/setup.py sdist
+	python3 setup/setup.py bdist_wheel
 	python3 -m twine upload dist/*
 
+publish: clean test
+	python3 -m build --no-isolation
+	python3 -m twine upload dist/*
+
+clean:
+	-rm dist/ -r
+	-rm build/ -r
+	-rm *.egg-info/ -r
diff --git a/dominate/_version.py b/dominate/_version.py
index f2df444..387cfac 100644
--- a/dominate/_version.py
+++ b/dominate/_version.py
@@ -1,1 +1,1 @@
-__version__ = '2.8.0'
+__version__ = '2.9.0'
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..8aadde0
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,43 @@
+[build-system]
+requires = ["setuptools>=62"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "dominate"
+description = "Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API."
+readme = {file = "README.md", content-type = "text/markdown"}
+authors = [
+    {name = "Tom Flanagan", email = "tom@zkpq.ca"},
+    {name = "Jake Wharton"},
+]
+requires-python = ">=3.4"
+keywords = ["framework", "templating", "template", "html", "xhtml", "python", "html5"]
+license = {text = "LGPL-3.0-or-newer"}
+classifiers = [
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
+    "Operating System :: OS Independent",
+    "Programming Language :: Python",
+    "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.11",
+    "Programming Language :: Python :: 3.12",
+    "Programming Language :: Python :: Implementation :: PyPy",
+    "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+    "Topic :: Text Processing :: Markup :: HTML",
+]
+dynamic = ["version"]
+
+[project.urls]
+Homepage = "https://github.com/Knio/dominate"
+Source = "https://github.com/Knio/dominate"
+
+[tool.setuptools]
+packages = ["dominate"]
+
+[tool.setuptools.dynamic]
+version = {attr = "dominate._version.__version__"}
diff --git a/setup.cfg b/setup.cfg
index 6e2d29f..568d094 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,5 @@
 [metadata]
-license_file = LICENSE.txt
+license_files = ["LICENSE.txt"]
 
 [bdist_wheel]
 universal=1
-
diff --git a/setup.py b/setup/setup.py
similarity index 97%
rename from setup.py
rename to setup/setup.py
index f83890f..31d6c48 100644
--- a/setup.py
+++ b/setup/setup.py
@@ -36,7 +36,7 @@
   long_description_content_type='text/markdown',
   keywords         = 'framework templating template html xhtml python html5',
 
-  python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
+  python_requires='>=2.7, <3',
   classifiers = [
     'Intended Audience :: Developers',
     'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',


Test patch:
diff --git a/tests/test_dominate.py b/tests/test_dominate.py
index bc0016e..1622760 100644
--- a/tests/test_dominate.py
+++ b/tests/test_dominate.py
@@ -1,18 +1,6 @@
-import pytest
-
-import dominate
-from dominate import tags
-from dominate import util
 
 def test_version():
   import dominate
-  version = '2.8.0'
+  version = '2.9.0'
   assert dominate.version == version
   assert dominate.__version__ == version
-
-
-def test_context():
-  id1 = dominate.dom_tag._get_thread_context()
-  id2 = dominate.dom_tag._get_thread_context()
-  assert id1 == id2
-
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 6066301..5a36afe 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,9 +1,13 @@
-import pytest
-
+import dominate
 from dominate.tags import *
 from dominate import util
 
 
+def test_context():
+  id1 = dominate.dom_tag._get_thread_context()
+  id2 = dominate.dom_tag._get_thread_context()
+  assert id1 == id2
+
 def test_include():
   import os
   try:
@@ -53,4 +57,3 @@ def test_container():
 '''<div>
   <h1>a</h1>
 </div>'''
-