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,6 +6,9 @@ import yaml
#root_dir = os.path.abspath(os.curdir)
#sys.path.append(root_dir)
try:
from dima.utils import g5505_utils as utils
except ModuleNotFoundError:
import utils.g5505_utils as utils

View File

@ -3,10 +3,14 @@ import sys
#root_dir = os.path.abspath(os.curdir)
#sys.path.append(root_dir)
try:
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']
# Define the instruments directory (modify this as needed or set to None)

View File

@ -8,7 +8,10 @@ import json
#from instruments.readers import set_dima_path as configpath
#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):

View File

@ -22,6 +22,12 @@ from datetime import datetime
from itertools import chain
# Import DIMA modules
try:
from dima.src import hdf5_writer as hdf5_lib
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

View File

@ -15,9 +15,14 @@ if dimaPath not in sys.path: # Avoid duplicate entries
import h5py
import yaml
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):
with open(review_yaml_file, 'r') as stream:
try:

View File

@ -1,5 +1,10 @@
import subprocess
import os
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

View File

@ -17,9 +17,6 @@ if dimaPath not in sys.path: # Avoid duplicate entries
import h5py
import pandas as pd
import numpy as np
import utils.g5505_utils as utils
import src.hdf5_writer as hdf5_lib
import logging
import datetime
@ -29,6 +26,13 @@ import yaml
import json
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():
"""

View File

@ -1,13 +1,17 @@
import sys
import os
root_dir = os.path.abspath(os.curdir)
sys.path.append(root_dir)
#root_dir = os.path.abspath(os.curdir)
#sys.path.append(root_dir)
import pandas as pd
import numpy as np
import h5py
import logging
try:
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.express as px
#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):