Skip to content

Replace pkg_resources usage with importlib.metadata.#315

Merged
robwoolley merged 1 commit intomasterfrom
nuclearsandwich/remove-pkg-resources
Jul 7, 2025
Merged

Replace pkg_resources usage with importlib.metadata.#315
robwoolley merged 1 commit intomasterfrom
nuclearsandwich/remove-pkg-resources

Conversation

@nuclearsandwich
Copy link
Contributor

pkg_resources is only used to fetch and provide the current superflore version.

In fact, there's very little need to parse this version at all (which would also require adding the packaging module as a dependency. Instead of parsing the version for the test, I used a cursed regexp that will test the value is greater than the current release when present.

Resolves #314.

__version__ = 'unset'
except (ImportError, OSError):
__version__ = 'unset'
from superflore.version import VERSION
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This convoluted indirection was an attempt to work around local import trouble with the RepoInstance. It may be we don't need the superflore.version module if the tests are better behaved in general than they are in my local workspace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the unit tests aren't well behaved. They don't cover OpenEmbedded and the Gentoo support is working but showing it's age.

I did run the following as a test:
sed -i "s/lunar/noetic/g" tests/test_ebuild.py tests/test_generate_installers.py tests/ebuild/simple_expected.ebuild

python -m unittest tests.test_ebuild
python -m unittest tests.test_generate_installers

as well as this to do some limited testing on the new version changes:
python -m unittest tests.test_utils

This seems sufficient for now.

@robwoolley robwoolley force-pushed the nuclearsandwich/remove-pkg-resources branch from 1e557a3 to 4ea3897 Compare July 7, 2025 16:15
@robwoolley
Copy link
Contributor

robwoolley commented Jul 7, 2025

Thanks @nuclearsandwich for tackling this.

It seems that the new lines have a new Flake8 error:

superflore/utils.py:29:1: I100 Import statements are in the wrong order. 'from superflore.exceptions import UnknownPlatform' should be before 'from superflore.version import VERSION'
superflore/utils.py:29:1: I202 Additional newline in a group of imports. 'from superflore.exceptions import UnknownPlatform' is identified as Third Party and 'from superflore.version import VERSION' is identified as Third Party.
superflore/version.py:11:1: W391 blank line at end of file

It seemed to be happy with this modification:

git diff superflore/utils.py
diff --git a/superflore/utils.py b/superflore/utils.py
index b549beb..b19500d 100644
--- a/superflore/utils.py
+++ b/superflore/utils.py
@@ -24,10 +24,9 @@ import time
 from typing import Dict
 import urllib.request

-from superflore.version import VERSION
-
 from superflore.exceptions import UnknownPlatform
 from superflore.rosdep_support import get_cached_index, resolve_rosdep_key
+from superflore.version import VERSION
 from termcolor import colored

In addition to removing the extra line at the end of version.py.

pkg_resources is only used to fetch and provide the current superflore
version.

In fact, there's very little need to parse this version at all (which
would also require adding the `packaging` module as a dependency.
Instead of parsing the version for the test, I used a cursed regexp that
will test the value is greater than the current release when present.
@robwoolley robwoolley force-pushed the nuclearsandwich/remove-pkg-resources branch from 4ea3897 to d3cc649 Compare July 7, 2025 16:47
@robwoolley robwoolley self-requested a review July 7, 2025 16:49
__version__ = 'unset'
except (ImportError, OSError):
__version__ = 'unset'
from superflore.version import VERSION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the unit tests aren't well behaved. They don't cover OpenEmbedded and the Gentoo support is working but showing it's age.

I did run the following as a test:
sed -i "s/lunar/noetic/g" tests/test_ebuild.py tests/test_generate_installers.py tests/ebuild/simple_expected.ebuild

python -m unittest tests.test_ebuild
python -m unittest tests.test_generate_installers

as well as this to do some limited testing on the new version changes:
python -m unittest tests.test_utils

This seems sufficient for now.

@robwoolley robwoolley merged commit 816eb6a into master Jul 7, 2025
10 checks passed
parse_version('0.2.1'))
if VERSION != 'unset':
self.assertRegex(get_superflore_version(),
r"^(\d{2}|[1-9]|0\.(\d{2}|[4-9]|3\.(\d{2}|[4-9]|3)))",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised (and a little disappointed) that my use of a cursed regexp to do the version parsing went unremarked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nuclearsandwich nuclearsandwich deleted the nuclearsandwich/remove-pkg-resources branch January 15, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace pkg_resources usage with importlib

2 participants