From 60176a5774182533ab043b24912d388c62a1565a Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Fri, 5 Jan 2024 16:20:45 -0800 Subject: [PATCH 1/5] Remove distutils requirement. Also, we only used it in functions that wrapped pip, which we no longer need to have at all, so I just dropped package.py entirely. Also, fixed some errors and warnings in the other files in this directory. --- tellurium/__init__.py | 7 ---- tellurium/utils/misc.py | 5 ++- tellurium/utils/omex.py | 6 ++-- tellurium/utils/package.py | 63 ---------------------------------- tellurium/utils/uncertainty.py | 1 - 5 files changed, 5 insertions(+), 77 deletions(-) delete mode 100644 tellurium/utils/package.py diff --git a/tellurium/__init__.py b/tellurium/__init__.py index 24d51a1d..812be966 100644 --- a/tellurium/__init__.py +++ b/tellurium/__init__.py @@ -136,13 +136,6 @@ executeInlineOmexFromFile, ) -# Package utilities -from tellurium.utils.package import ( - searchPackage, - installPackage, - upgradePackage, - uninstallPackage, -) from tellurium.utils.misc import( saveToFile, readFromFile, diff --git a/tellurium/utils/misc.py b/tellurium/utils/misc.py index ee39188a..23a0c00f 100644 --- a/tellurium/utils/misc.py +++ b/tellurium/utils/misc.py @@ -85,7 +85,7 @@ def runTool (toolFileName): root, waste = os.path.split(p) toolFileName[0] = root + '\\telluriumTools\\' + toolFileName[0] + '\\' + toolFileName[0] + '.exe' return subprocess.check_output(toolFileName) - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: raise Exception('Tool failed to run correctly or could not be found') # --------------------------------------------------------------------- @@ -98,7 +98,7 @@ def getODEsFromSBMLFile (fileName): >>> te.getODEsFromSBMLFile ('mymodel.xml') """ - sbmlStr = te.readFromFile (fileName) + sbmlStr = readFromFile (fileName) extractor = ODEExtractor (sbmlStr) return extractor.toString() @@ -197,7 +197,6 @@ def __init__(self, sbmlStr): self.use_species_names = False self.use_ids = True - from collections import defaultdict self.accumulators = {} self.accumulator_list = [] diff --git a/tellurium/utils/omex.py b/tellurium/utils/omex.py index 312b0c2c..9721efa2 100644 --- a/tellurium/utils/omex.py +++ b/tellurium/utils/omex.py @@ -57,9 +57,9 @@ def __init__(self, location, format=None, formatKey=None, master=False, descript def __str__(self): if self.master: - return '<*master* Entry {} | {}>'.format(self.master, self.location, self.format) + return '<*master* Entry {} | {}>'.format(self.location, self.format) else: - return ''.format(self.master, self.location, self.format) + return ''.format(self.location, self.format) class Creator(object): @@ -90,7 +90,7 @@ def combineArchiveFromDirectory(directory, omexPath, creators=None, creators_for print(manifest_path) if os.path.exists(manifest_path): - warnings.warn("Manifest file exists in directory, but not used in COMBINE archive creation: %s".format(manifest_path)) + warnings.warn("Manifest file exists in directory {}, but not used in COMBINE archive creation: %s".format(manifest_path)) # add the base entry entries = [ diff --git a/tellurium/utils/package.py b/tellurium/utils/package.py deleted file mode 100644 index ccadbbcb..00000000 --- a/tellurium/utils/package.py +++ /dev/null @@ -1,63 +0,0 @@ -""" -Provides trivial wrappers around pip and functionality -working with packages. -""" - -from __future__ import print_function, absolute_import -import sys, subprocess - -def check_macos_ver(): - import sys,platform - if sys.platform == 'darwin': - vstr, _, _ = platform.mac_ver() - from distutils.version import LooseVersion - import warnings - v = LooseVersion(vstr) - oldest_str = '10.9.0' - if v < LooseVersion(oldest_str): - warnings.warn('Your OS version is older than the oldest supported version ({} < {}). The operation may fail.'.format(vstr,oldest_str)) - -def searchPackage(name): - """ Search pip package for package name. - - :param name: package name - :type name: str - """ - check_macos_ver() - subprocess.check_call([sys.executable, '-m', 'pip', 'search', name]) - - -def installPackage(name): - """ Install pip package. - This has the advantage you don't have to - manually track down the currently running - Python interpreter and switch to the command line - (useful e.g. in the Tellurium notebook viewer). - - :param name: package name - :type name: str - """ - check_macos_ver() - try: - subprocess.check_call([sys.executable, '-m', 'pip', 'install', name]) - except subprocess.CalledProcessError as error: - print ("Error while calling installPackage:", error) - -def upgradePackage(name): - """ Upgrade pip package. - - :param name: package name - :type name: str - """ - check_macos_ver() - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', name]) - - -def uninstallPackage(name): - """ Uninstall pip package. - - :param str name: package name - :type name: str - """ - check_macos_ver() - subprocess.check_call([sys.executable, '-m', 'pip', 'uninstall', '-y', name]) diff --git a/tellurium/utils/uncertainty.py b/tellurium/utils/uncertainty.py index f4e31ed1..a23a5284 100644 --- a/tellurium/utils/uncertainty.py +++ b/tellurium/utils/uncertainty.py @@ -8,7 +8,6 @@ te.setDefaultPlottingEngine("matplotlib") import numpy as np import random -import roadrunner import matplotlib import matplotlib.pyplot as plt import matplotlib.gridspec as gs From 7321932a1f132b4dbfd15a552544d6eb3fef60cd Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Tue, 9 Jan 2024 11:53:49 -0800 Subject: [PATCH 2/5] Update docs a la #581 --- docs/_notebooks/core/tellurium_examples.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_notebooks/core/tellurium_examples.rst b/docs/_notebooks/core/tellurium_examples.rst index ddf64841..66601e3f 100644 --- a/docs/_notebooks/core/tellurium_examples.rst +++ b/docs/_notebooks/core/tellurium_examples.rst @@ -169,12 +169,12 @@ conditions resulting in different steady states reached. print(r.selections) initValue = 0.05 - m = r.simulate (0, 4, 100, selections=["time", "S1"]) + m = r.simulate (0, 4, 100, selections=["time", "[S1]"]) for i in range (0,12): r.reset() r['[S1]'] = initValue - res = r.simulate (0, 4, 100, selections=["S1"]) + res = r.simulate (0, 4, 100, selections=["[S1]"]) m = np.concatenate([m, res], axis=1) initValue += 1 From 35eb206eed8b23dc80d5ca68290043d17b445f1e Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Wed, 31 Jan 2024 12:53:20 -0800 Subject: [PATCH 3/5] Remove unused 'imp' import. (The library is now gone in 3.12, but we didn't use it anyway.) --- tellurium/teconverters/convert_omex.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tellurium/teconverters/convert_omex.py b/tellurium/teconverters/convert_omex.py index 20daba37..7a9e4c5e 100644 --- a/tellurium/teconverters/convert_omex.py +++ b/tellurium/teconverters/convert_omex.py @@ -9,7 +9,6 @@ import getpass -import imp # reloads because numl is overwriting symbols try: import libcombine except ImportError: From cd109e2acae620ae758efd4e353fa17fd9fe98ba Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Wed, 31 Jan 2024 13:25:48 -0800 Subject: [PATCH 4/5] Update test to cover removal of 'imp' from Py3.12 --- tellurium/tests/test_examples.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tellurium/tests/test_examples.py b/tellurium/tests/test_examples.py index 5dd24b05..525de0f5 100644 --- a/tellurium/tests/test_examples.py +++ b/tellurium/tests/test_examples.py @@ -6,8 +6,8 @@ import unittest import os -import imp from tellurium.tests.helpers import filesInDirectory +from importlib.machinery import SourceFileLoader # ---------------------------------------------------------------- # List of python files to test @@ -44,7 +44,7 @@ def test(self=None): """ Test failes if Exception in execution of f. """ if self is not None: print(filePath) - imp.load_source(os.path.basename(filePath)[:-3], filePath) + SourceFileLoader(os.path.basename(filePath)[:-3], filePath).load_module() return test From fcb119e6e255370f5542d04af1b96169054d1c4c Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Wed, 31 Jan 2024 14:05:16 -0800 Subject: [PATCH 5/5] Update version number. --- tellurium/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tellurium/VERSION.txt b/tellurium/VERSION.txt index a6333e40..0d3ad67a 100644 --- a/tellurium/VERSION.txt +++ b/tellurium/VERSION.txt @@ -1 +1 @@ -2.2.9 +2.2.10