Skip to content

Commit

Permalink
Removed semantic version dependency. (#574)
Browse files Browse the repository at this point in the history
* Removed semantic version dependency.

* Fix mypy error for Python <= 3.8.

* Add missing copyright header.
  • Loading branch information
luisenp authored Jul 7, 2023
1 parent 9cb9e71 commit 6b446ab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
19 changes: 19 additions & 0 deletions tests/theseus_tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import pytest

from theseus._version import lt_version


def test_lt_version():
assert not lt_version("2.0.0", "0.4.0")
assert not lt_version("1.13.0abcd", "0.4.0")
assert not lt_version("0.4.1+yzx", "0.4.0")
assert lt_version("1.13.0.1.2.3.4", "2.0.0")
assert lt_version("1.13.0.1.2+abc", "2.0.0")
with pytest.raises(ValueError):
lt_version("1.2", "0.4.0")
lt_version("1", "0.4.0")
lt_version("1.", "0.4.0")
25 changes: 22 additions & 3 deletions theseus/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import re
import warnings
from typing import Tuple

from semantic_version import Version
from torch import __version__ as _torch_version
import torch

if Version(_torch_version) < Version("2.0.0"):

# Returns True/False if version string v1 is less than version string v2
def lt_version(v1: str, v2: str) -> bool:
def _as_tuple(s: str) -> Tuple[int, int, int]:
pattern = r"^[\d.]+"
match = re.match(pattern, s)
try:
return tuple(int(x) for x in match.group().split(".")[:3]) # type: ignore
except Exception:
raise ValueError(
f"String {s} cannot be converted to (mayor, minor, micro) format."
)

x1, y1, z1 = _as_tuple(v1)
x2, y2, z2 = _as_tuple(v2)
return x1 < x2 or (x1 == x2 and y1 < y2) or (x1 == x2 and y1 == y2 and z1 < z2)


if lt_version(torch.__version__, "2.0.0"):
warnings.warn(
"Using torch < 2.0 for theseus is deprecated and compatibility will be "
"discontinued in future releases.",
Expand Down
7 changes: 3 additions & 4 deletions theseus/third_party/lml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import numpy as np
import numpy.random as npr
import torch
from semantic_version import Version
from torch.autograd import Function, Variable, grad
from torch.nn import Module

version = Version(".".join(torch.__version__.split(".")[:3]))
old_torch = version < Version("0.4.0")
from theseus._version import lt_version

old_torch = lt_version(torch.__version__, "0.4.0")


def bdot(x, y):
Expand Down

0 comments on commit 6b446ab

Please sign in to comment.