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

View File

@ -3,10 +3,14 @@ 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)
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.xps_ibw_reader import read_xps_ibw_file_as_dict
from instruments.readers.g5505_text_reader import read_txt_files_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']
# Define the instruments directory (modify this as needed or set to None) # 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 #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,6 +22,12 @@ from datetime import datetime
from itertools import chain from itertools import chain
# Import DIMA modules # 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 src.hdf5_writer as hdf5_lib
import utils.g5505_utils as utils import utils.g5505_utils as utils
from instruments.readers import filereader_registry from instruments.readers import filereader_registry

View File

@ -15,9 +15,14 @@ if dimaPath not in sys.path: # Avoid duplicate entries
import h5py import h5py
import yaml import yaml
try:
from dima.src import hdf5_ops as hdf5_ops
except ModuleNotFoundError:
import src.hdf5_ops as hdf5_ops import src.hdf5_ops as hdf5_ops
def load_yaml(review_yaml_file): def load_yaml(review_yaml_file):
with open(review_yaml_file, 'r') as stream: with open(review_yaml_file, 'r') as stream:
try: try:

View File

@ -1,5 +1,10 @@
import subprocess import subprocess
import os 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 import utils.g5505_utils as utils
from pipelines.metadata_revision import update_hdf5_file_with_review 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 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,13 +1,17 @@
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
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 utils.g5505_utils as utils
import instruments.readers.filereader_registry as filereader_registry 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):