From 6d81370bb043bd96f1a9cafc0779579807299c3c Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 26 Nov 2024 15:34:49 +0100 Subject: [PATCH] Don't modify sys.path for amici model imports Not necessary when using `amici.import_model_module`. --- pypesto/petab/objective_creator.py | 5 ----- test/petab/test_amici_predictor.py | 6 ------ test/petab/test_sbml_conversion.py | 3 --- 3 files changed, 14 deletions(-) diff --git a/pypesto/petab/objective_creator.py b/pypesto/petab/objective_creator.py index 72f98cf03..697c0f9a3 100644 --- a/pypesto/petab/objective_creator.py +++ b/pypesto/petab/objective_creator.py @@ -7,7 +7,6 @@ import os import re import shutil -import sys import warnings from abc import ABC, abstractmethod from collections.abc import Iterable, Sequence @@ -145,10 +144,6 @@ def create_model( f"compilation: Not a folder." ) - # add module to path - if self.output_folder not in sys.path: - sys.path.insert(0, self.output_folder) - # compile if self._must_compile(force_compile): logger.info( diff --git a/test/petab/test_amici_predictor.py b/test/petab/test_amici_predictor.py index 2d23620a4..d99fa7d52 100644 --- a/test/petab/test_amici_predictor.py +++ b/test/petab/test_amici_predictor.py @@ -2,7 +2,6 @@ import os import shutil -import sys import amici import libsbml @@ -34,13 +33,10 @@ def conversion_reaction_model(): # try to import the exisiting model, if possible try: - sys.path.insert(0, os.path.abspath(model_output_dir)) model_module = amici.import_model_module(model_name, model_output_dir) model = model_module.getModel() except ValueError: # read in and adapt the sbml slightly - if os.path.abspath(model_output_dir) in sys.path: - sys.path.remove(os.path.abspath(model_output_dir)) sbml_importer = amici.SbmlImporter(sbml_file) # add observables to sbml model @@ -95,7 +91,6 @@ def create_intial_assignment(sbml_model, spec_id): ) # Importing the module and loading the model - sys.path.insert(0, os.path.abspath(model_output_dir)) model_module = amici.import_model_module(model_name, model_output_dir) model = model_module.getModel() except RuntimeError as err: @@ -107,7 +102,6 @@ def create_intial_assignment(sbml_model, spec_id): "Delete the conversion_reaction_enhanced model from your python " "path and retry. Your python path is currently:" ) - print(sys.path) print("Original error message:") raise err diff --git a/test/petab/test_sbml_conversion.py b/test/petab/test_sbml_conversion.py index 22653a0a6..7284fb8a7 100644 --- a/test/petab/test_sbml_conversion.py +++ b/test/petab/test_sbml_conversion.py @@ -1,6 +1,5 @@ import os import re -import sys import unittest import warnings @@ -11,8 +10,6 @@ from ..util import load_amici_objective -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - optimizers = { "scipy": [ "Nelder-Mead",