Change import statements with try except to enable explicit import of submodules from import to avoid conflicts with parent project.

This commit is contained in:
2025-02-22 17:10:53 +01:00
parent c28286a626
commit 821d314cb6
10 changed files with 56 additions and 19 deletions

Binary file not shown.

View File

@ -6,7 +6,10 @@ import yaml
#root_dir = os.path.abspath(os.curdir) #root_dir = os.path.abspath(os.curdir)
#sys.path.append(root_dir) #sys.path.append(root_dir)
import utils.g5505_utils as utils try:
from dima.utils import g5505_utils as utils
except ModuleNotFoundError:
import utils.g5505_utils as utils

View File

@ -3,9 +3,13 @@ import sys
#root_dir = os.path.abspath(os.curdir) #root_dir = os.path.abspath(os.curdir)
#sys.path.append(root_dir) #sys.path.append(root_dir)
from instruments.readers.xps_ibw_reader import read_xps_ibw_file_as_dict try:
from instruments.readers.g5505_text_reader import read_txt_files_as_dict from dima.instruments.readers.xps_ibw_reader import read_xps_ibw_file_as_dict
from dima.instruments.readers.g5505_text_reader import read_txt_files_as_dict
except ModuleNotFoundError:
from instruments.readers.xps_ibw_reader import read_xps_ibw_file_as_dict
from instruments.readers.g5505_text_reader import read_txt_files_as_dict
file_extensions = ['.ibw','.txt','.dat','.h5','.TXT','.csv','.pkl','.json','.yaml'] file_extensions = ['.ibw','.txt','.dat','.h5','.TXT','.csv','.pkl','.json','.yaml']

View File

@ -8,7 +8,10 @@ import json
#from instruments.readers import set_dima_path as configpath #from instruments.readers import set_dima_path as configpath
#configpath.set_dima_path() #configpath.set_dima_path()
from utils import g5505_utils try:
from dima.utils import g5505_utils as utils
except ModuleNotFoundError:
import utils.g5505_utils as utils
def read_jsonflag_as_dict(path_to_file): def read_jsonflag_as_dict(path_to_file):

View File

@ -22,9 +22,15 @@ from datetime import datetime
from itertools import chain from itertools import chain
# Import DIMA modules # Import DIMA modules
import src.hdf5_writer as hdf5_lib try:
import utils.g5505_utils as utils from dima.src import hdf5_writer as hdf5_lib
from instruments.readers import filereader_registry from dima.utils import g5505_utils as utils
from dima.instruments.readers import filereader_registry
except ModuleNotFoundError:
print(':)')
import src.hdf5_writer as hdf5_lib
import utils.g5505_utils as utils
from instruments.readers import filereader_registry
allowed_file_extensions = filereader_registry.file_extensions allowed_file_extensions = filereader_registry.file_extensions

View File

@ -15,7 +15,12 @@ if dimaPath not in sys.path: # Avoid duplicate entries
import h5py import h5py
import yaml import yaml
import src.hdf5_ops as hdf5_ops
try:
from dima.src import hdf5_ops as hdf5_ops
except ModuleNotFoundError:
import src.hdf5_ops as hdf5_ops
def load_yaml(review_yaml_file): def load_yaml(review_yaml_file):

View File

@ -1,7 +1,12 @@
import subprocess import subprocess
import os import os
import utils.g5505_utils as utils
from pipelines.metadata_revision import update_hdf5_file_with_review try:
from dima.utils import g5505_utils as utils
from dima.pipelines.metadata_revision import update_hdf5_file_with_review
except ModuleNotFoundError:
import utils.g5505_utils as utils
from pipelines.metadata_revision import update_hdf5_file_with_review
def perform_git_operations(hdf5_upload): def perform_git_operations(hdf5_upload):
status_command = ['git', 'status'] status_command = ['git', 'status']

View File

@ -17,9 +17,6 @@ if dimaPath not in sys.path: # Avoid duplicate entries
import h5py import h5py
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import utils.g5505_utils as utils
import src.hdf5_writer as hdf5_lib
import logging import logging
import datetime import datetime
@ -29,6 +26,13 @@ import yaml
import json import json
import copy import copy
try:
from dima.utils import g5505_utils as utils
from dima.src import hdf5_writer as hdf5_lib
except ModuleNotFoundError:
import utils.g5505_utils as utils
import src.hdf5_writer as hdf5_lib
class HDF5DataOpsManager(): class HDF5DataOpsManager():
""" """

View File

@ -1,15 +1,19 @@
import sys import sys
import os import os
root_dir = os.path.abspath(os.curdir) #root_dir = os.path.abspath(os.curdir)
sys.path.append(root_dir) #sys.path.append(root_dir)
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import h5py import h5py
import logging import logging
import utils.g5505_utils as utils try:
import instruments.readers.filereader_registry as filereader_registry from dima.utils import g5505_utils as utils
from dima.instruments.readers import filereader_registry as filereader_registry
except ModuleNotFoundError:
import utils.g5505_utils as utils
import instruments.readers.filereader_registry as filereader_registry

View File

@ -13,8 +13,11 @@ from plotly.subplots import make_subplots
import plotly.graph_objects as go import plotly.graph_objects as go
import plotly.express as px import plotly.express as px
#import plotly.io as pio #import plotly.io as pio
from src.hdf5_ops import get_parent_child_relationships
try:
from dima.src.hdf5_ops import get_parent_child_relationships
except ModuleNotFoundError:
from src.hdf5_ops import get_parent_child_relationships
def display_group_hierarchy_on_a_treemap(filename: str): def display_group_hierarchy_on_a_treemap(filename: str):