Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build error caused by use of deprecated pkg_resources #598

Merged
merged 7 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ Jump to:

## SmartSim

### Development branch

To be released at some future point in time

Description

- Update packaging dependency

Detailed Notes

- Fix packaging failures due to deprecated `pkg_resources`. ([SmartSim-PR598](https://github.com/CrayLabs/SmartSim/pull/598))

### 0.7.0

Released on 14 May, 2024
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


[build-system]
requires = ["setuptools", "wheel", "cmake>=3.13"]
requires = ["packaging>=24.0", "setuptools>=70.0", "wheel", "cmake>=3.13"]
build-backend = "setuptools.build_meta"

[tool.black]
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ classifiers =

[options]
packages = find:
setup_requires =
setuptools>=39.2
cmake>=3.13
include_package_data = True
python_requires = >=3.9,<3.12

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def has_ext_modules(_placeholder):

extras_require = {
"dev": [
"packaging>=24.0",
ankona marked this conversation as resolved.
Show resolved Hide resolved
"black==24.1a1",
"isort>=5.6.4",
"pylint>=2.10.0,<3",
Expand Down
31 changes: 6 additions & 25 deletions smartsim/_core/_install/buildenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,8 @@
from pathlib import Path
from typing import Iterable

# NOTE: This will be imported by setup.py and hence no
# smartsim related items or non-standand library
# items should be imported here.
from packaging.version import InvalidVersion, Version, parse

# TODO: pkg_resources has been deprecated by PyPA. Currently we use it for its
# packaging implementation, as we cannot assume a user will have `packaging`
# prior to `pip install` time. We really only use pkg_resources for their
# vendored version of `packaging.version.Version` so we should probably try
# to remove
# https://setuptools.pypa.io/en/latest/pkg_resources.html

# isort: off
import pkg_resources
from pkg_resources import packaging # type: ignore

# isort: on

Version = packaging.version.Version
InvalidVersion = packaging.version.InvalidVersion
DbEngine = t.Literal["REDIS", "KEYDB"]


Expand Down Expand Up @@ -105,9 +88,7 @@ class Version_(str):

@staticmethod
def _convert_to_version(
vers: t.Union[
str, Iterable[packaging.version.Version], packaging.version.Version
],
vers: t.Union[str, Iterable[Version], Version],
) -> t.Any:
if isinstance(vers, Version):
return vers
Expand All @@ -122,20 +103,20 @@ def _convert_to_version(
def major(self) -> int:
# Version(self).major doesn't work for all Python distributions
# see https://github.com/lebedov/python-pdfbox/issues/28
return int(pkg_resources.parse_version(self).base_version.split(".")[0])
return int(parse(self).base_version.split(".", maxsplit=1)[0])

@property
def minor(self) -> int:
return int(pkg_resources.parse_version(self).base_version.split(".")[1])
return int(parse(self).base_version.split(".", maxsplit=2)[1])

@property
def micro(self) -> int:
return int(pkg_resources.parse_version(self).base_version.split(".")[2])
return int(parse(self).base_version.split(".", maxsplit=3)[2])

@property
def patch(self) -> str:
# return micro with string modifier i.e. 1.2.3+cpu -> 3+cpu
return str(pkg_resources.parse_version(self)).split(".")[2]
return str(parse(self)).split(".")[2]

def __gt__(self, cmp: t.Any) -> bool:
try:
Expand Down
31 changes: 22 additions & 9 deletions tests/install/test_buildenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import packaging
import pytest
from pkg_resources import packaging # type: ignore

from smartsim._core._install.buildenv import Version_

Expand Down Expand Up @@ -71,19 +71,32 @@ def test_version_equality_ne():

assert v1 != v2


def test_version_bad_input():
# def test_version_bad_input():
"""Test behavior when passing an invalid version string"""
v1 = Version_("abcdefg")
version = Version_("1")
assert version.major == 1
with pytest.raises((IndexError, packaging.version.InvalidVersion)) as ex:
version.minor

# todo: fix behavior to ensure versions are valid.
assert v1
version = Version_("2.")
with pytest.raises((IndexError, packaging.version.InvalidVersion)) as ex:
version.major

version = Version_("3.0.")

with pytest.raises((IndexError, packaging.version.InvalidVersion)) as ex:
version.major

version = Version_("3.1.a")
assert version.major == 3
assert version.minor == 1
with pytest.raises((IndexError, packaging.version.InvalidVersion)) as ex:
version.patch


def test_version_bad_parse_fail():
"""Test behavior when trying to parse with an invalid input string"""
v1 = Version_("abcdefg")

# todo: ensure we can't take invalid input and have this IndexError occur.
version = Version_("abcdefg")
with pytest.raises((IndexError, packaging.version.InvalidVersion)) as ex:
_ = v1.minor
version.major
Loading