Repository: certbot/certbot (language: python)

Issue:
Stop using pkg_resources
[`pkg_resources` is deprecated](https://setuptools.pypa.io/en/latest/history.html#v67-5-0) and we started pinning back `setuptools` to avoid problems here in https://github.com/certbot/certbot/pull/9657. We should stop using `pkg_resources` and unpin `setuptools`.

I took a crack at fixing this for the `josepy` repo at https://github.com/certbot/josepy/pull/158. I suspect a similar approach could be taken here, however, there's significantly more work to be done and `importlib_metadata` will need to be used to deal with plugins. After further scoping out the work here, I think there's a good chance this should probably be done over multiple PRs. Perhaps one PR could focus on testing and another could focus on plugins.

I'm also throwing this in the current milestone for visibility for now at least.


Discussion / hints:
As of a recent setuptools, this is now causing tests to fail:

```
============================= test session starts ==============================
platform linux -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /build/certbot/src/github.com-certbot-certbot
configfile: pytest.ini
collected 0 items / 1 error

==================================== ERRORS ====================================
________________________ ERROR collecting test session _________________________
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1206: in _gcd_import
    ???
<frozen importlib._bootstrap>:1178: in _find_and_load
    ???
<frozen importlib._bootstrap>:1149: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
/usr/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:172: in exec_module
    exec(co, module.__dict__)
certbot/_internal/tests/conftest.py:3: in <module>
    from certbot._internal import cli
certbot/_internal/cli/__init__.py:13: in <module>
    from certbot._internal import constants
certbot/_internal/constants.py:6: in <module>
    import pkg_resources
/usr/lib/python3.11/site-packages/pkg_resources/__init__.py:121: in <module>
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
E   DeprecationWarning: pkg_resources is deprecated as an API
=========================== short test summary info ============================
ERROR .. - DeprecationWarning: pkg_resources is deprecated as an API
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.07s ===============================
```

Fix patch:
diff --git a/.pylintrc b/.pylintrc
index 05f34fb1fea..e37ba1fc7fc 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -524,7 +524,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace,
 # List of module names for which member attributes should not be checked
 # (useful for modules/projects where namespaces are manipulated during runtime
 # and thus existing member attributes cannot be deduced by static analysis
-ignored-modules=pkg_resources,confargparse,argparse
+ignored-modules=confargparse,argparse
 
 # Show a hint with possible names when a member name was not found. The aspect
 # of finding the hint is based on edit distance.
diff --git a/certbot/docs/contributing.rst b/certbot/docs/contributing.rst
index 296ccf2fbba..1a6c402af2e 100644
--- a/certbot/docs/contributing.rst
+++ b/certbot/docs/contributing.rst
@@ -328,8 +328,8 @@ Writing your own plugin
     for one example of that.
 
 Certbot client supports dynamic discovery of plugins through the
-`setuptools entry points`_ using the `certbot.plugins` group. This
-way you can, for example, create a custom implementation of
+`importlib.metadata entry points`_ using the `certbot.plugins` group.
+This way you can, for example, create a custom implementation of
 `~certbot.interfaces.Authenticator` or the
 `~certbot.interfaces.Installer` without having to merge it
 with the core upstream source code. An example is provided in
@@ -352,8 +352,8 @@ users install it system-wide with `pip install`. Note that this will
 only work for users who have Certbot installed from OS packages or via
 pip.
 
-.. _`setuptools entry points`:
-    https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
+.. _`importlib.metadata entry points`:
+    https://importlib-metadata.readthedocs.io/en/latest/using.html#entry-points
 
 Writing your own plugin snap
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/tools/pinning/current/pyproject.toml b/tools/pinning/current/pyproject.toml
index 2d908679c19..74547a1a5d5 100644
--- a/tools/pinning/current/pyproject.toml
+++ b/tools/pinning/current/pyproject.toml
@@ -70,11 +70,6 @@ cryptography = "!= 37.0.3"
 # https://github.com/python-poetry/poetry-plugin-export/issues/168 is resolved.
 poetry = "<1.3.0"
 
-# setuptools 67.5.0 deprecated pkg_resources which we still use. Let's pin it
-# back until this is fixed. Doing this work is being tracked by
-# https://github.com/certbot/certbot/issues/9606.
-setuptools = "<67.5.0"
-
 # Branch 4.x of tox introduces backward incompatibility changes. The tox.ini
 # file in the project must be adapted accordingly before moving out of the 3.x
 # branch. Once done, the following constraint should become tox >= 4 to keep
diff --git a/tools/requirements.txt b/tools/requirements.txt
index 1ed0ca0ee78..e424f278213 100644
--- a/tools/requirements.txt
+++ b/tools/requirements.txt
@@ -147,7 +147,7 @@ s3transfer==0.7.0 ; python_version >= "3.8" and python_version < "4.0"
 secretstorage==3.3.3 ; python_version >= "3.8" and python_version < "4.0" and sys_platform == "linux"
 semantic-version==2.10.0 ; python_version >= "3.8" and python_version < "4.0"
 setuptools-rust==1.7.0 ; python_version >= "3.8" and python_version < "4.0"
-setuptools==67.4.0 ; python_version >= "3.8" and python_version < "4.0"
+setuptools==68.2.2 ; python_version >= "3.8" and python_version < "4.0"
 shellingham==1.5.3 ; python_version >= "3.8" and python_version < "4.0"
 six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
 snowballstemmer==2.2.0 ; python_version >= "3.8" and python_version < "4.0"


Test patch:
diff --git a/certbot-dns-gehirn/certbot_dns_gehirn/_internal/tests/dns_gehirn_test.py b/certbot-dns-gehirn/certbot_dns_gehirn/_internal/tests/dns_gehirn_test.py
index 3df3c543190..331059a6098 100644
--- a/certbot-dns-gehirn/certbot_dns_gehirn/_internal/tests/dns_gehirn_test.py
+++ b/certbot-dns-gehirn/certbot_dns_gehirn/_internal/tests/dns_gehirn_test.py
@@ -1,7 +1,6 @@
 """Tests for certbot_dns_gehirn._internal.dns_gehirn."""
 
 import sys
-import unittest
 from unittest import mock
 
 import pytest
diff --git a/certbot-dns-ovh/certbot_dns_ovh/_internal/tests/dns_ovh_test.py b/certbot-dns-ovh/certbot_dns_ovh/_internal/tests/dns_ovh_test.py
index a5d553cd9e1..15ae728f234 100644
--- a/certbot-dns-ovh/certbot_dns_ovh/_internal/tests/dns_ovh_test.py
+++ b/certbot-dns-ovh/certbot_dns_ovh/_internal/tests/dns_ovh_test.py
@@ -22,6 +22,7 @@ class AuthenticatorTest(test_util.TempDirTestCase,
 
     DOMAIN_NOT_FOUND = Exception('Domain example.com not found')
     LOGIN_ERROR = HTTPError('403 Client Error: Forbidden for url: https://eu.api.ovh.com/1.0/...', response=Response())
+    
     def setUp(self):
         super().setUp()
 
diff --git a/pytest.ini b/pytest.ini
index c2bfe4da901..699902177b9 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -21,13 +21,7 @@
 #    updated.
 # 4) Ignore our own PendingDeprecationWarning about update_symlinks soon to be dropped.
 #    See https://github.com/certbot/certbot/issues/6284.
-# 5) Ignore pkg_resources.declare_namespace used in a large number of Google's Python
-#    libs. e.g. https://github.com/googleapis/google-auth-library-python/issues/1229.
-#    It is also is used in sphinxcontrib-devhelp 1.0.2 which as of writing this
-#    is the latest version of that library. See
-#    https://github.com/sphinx-doc/sphinxcontrib-devhelp/blob/1.0.2/setup.py#L69.
-# 6) Ignore DeprecationWarning from using pkg_resources API
-# 7) Ignore DeprecationWarning for datetime.utcfromtimestamp() triggered
+# 5) Ignore DeprecationWarning for datetime.utcfromtimestamp() triggered
 #    when importing the pytz.tzinfo module
 #    https://github.com/stub42/pytz/issues/105
 filterwarnings =
@@ -36,6 +30,4 @@ filterwarnings =
     ignore:.*rsyncdir:DeprecationWarning
     ignore:'urllib3.contrib.pyopenssl:DeprecationWarning:requests_toolbelt
     ignore:update_symlinks is deprecated:PendingDeprecationWarning
-    ignore:.*declare_namespace\(':DeprecationWarning
-    ignore:pkg_resources is deprecated as an API:DeprecationWarning
     ignore:.*datetime.utcfromtimestamp\(\) is deprecated:DeprecationWarning:pytz.tzinfo