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

Add Python 3.7 compatibility #301

Merged
merged 6 commits into from
May 23, 2022
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
2 changes: 2 additions & 0 deletions scico/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import sys

from . import _python37 # python 3.7 compatibility

# isort: off
from ._autograd import grad, jacrev, linear_adjoint, value_and_grad

Expand Down
24 changes: 24 additions & 0 deletions scico/_python37.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2021-2022 by SCICO Developers
# All rights reserved. BSD 3-clause License.
# This file is part of the SCICO package. Details of the copyright and
# user license can be found in the 'LICENSE' file distributed with the
# package.

""" Alter the behavior of (monkey patch) several modules so that SCICO
is compatible with Python 3.7, allowing it to run on Google Colab.
This file should be removed when/if Colab upgrades to Python 3.8.
"""

import sys

if sys.version_info.major == 3 and sys.version_info.minor == 7:
import typing

typing.Literal = typing.Any # type: ignore

import math
from functools import reduce
from operator import mul

# math.prod = (lambda fun, op: lambda iterable: fun(op, iterable, 1))(reduce, mul) # type: ignore
math.prod = lambda iterable: reduce(mul, iterable, 1) # type: ignore
9 changes: 7 additions & 2 deletions scico/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

"""Support functions for determining the package version."""


import os
import re
import sys
from ast import parse
from subprocess import PIPE, Popen
from typing import Any, Optional, Tuple, Union
Expand Down Expand Up @@ -41,7 +41,12 @@ def variable_assign_value(path: str, var: str) -> Any:
with open(path) as f:
try:
# See http://stackoverflow.com/questions/2058802
value = parse(next(filter(lambda line: line.startswith(var), f))).body[0].value.s # type: ignore
value_obj = parse(next(filter(lambda line: line.startswith(var), f))).body[0].value # type: ignore
if sys.version_info.major == 3 and sys.version_info.minor == 7:
value = value_obj.n # type: ignore
else:
value = value_obj.s # type: ignore

except StopIteration:
raise RuntimeError(f"Could not find initialization of variable {var}")
return value
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
f"requirements.txt ({req_jax_ver}) do not match"
)

python_requires = ">=3.8"
python_requires = ">=3.7"
tests_require = ["pytest", "pytest-runner"]

extra_require_files = [
Expand Down