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 all 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
8 changes: 4 additions & 4 deletions doc/installation_instructions/platform/olcf-summit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Since SmartSim does not have a built PowerPC build, the build steps for an IBM
system are slightly different than other systems.

Luckily for us, a conda channel with all relevant packages is maintained as part
of the `OpenCE <https://opence.mit.edu>`_ initiative. Users can follow these
instructions to get a working SmartSim build with PyTorch and TensorFlow for GPU
on Summit. Note that SmartSim and SmartRedis will be downloaded to the working
directory from which these instructions are executed.
of the `OpenCE <https://github.com/open-ce/open-ce>`_
initiative. Users can follow these instructions to get a working SmartSim build
with PyTorch and TensorFlow for GPU on Summit. Note that SmartSim and SmartRedis
will be downloaded to the working directory from which these instructions are executed.

Note that the available PyTorch version (1.10.2) does not match
the one expected by RedisAI 1.2.7 (1.11): it is still compatible and should
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/ml_training/surrogate/train_surrogate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"\n",
"The problem can be solved using a finite difference scheme. To this end, a modified version of the code\n",
"written by John Burkardt will be used. Its original version is licensed under LGPL, and so is this example.\n",
"The code was downloaded from [this page](https://people.sc.fsu.edu/~jburkardt/py_src/fd2d_heat_steady/fd2d_heat_steady.html),\n",
"The code was downloaded from [this page](https://github.com/johannesgerer/jburkardt-m/tree/master/fd2d_heat_steady),\n",
"which explains how the problem is discretized and solved.\n",
"\n",
"In the modified version of the code which will be used, a random number (between 1 and 5) of heat sources is placed.\n",
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 @@ -166,6 +166,7 @@ def has_ext_modules(_placeholder):

# Define needed dependencies for the installation
deps = [
"packaging>=24.0",
"psutil>=5.7.2",
"coloredlogs>=10.0",
"tabulate>=0.8.9",
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