Skip to content

Commit

Permalink
Restoring find_datamodel_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Feb 10, 2025
1 parent fd8c08b commit 862a377
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions bam_masterdata/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,18 @@

def find_datamodel_dir():
"""Search for 'datamodel/' in possible locations and return its absolute path."""
# Get current working directory
cwd = Path.cwd()

# Get the script's directory (relevant for installed packages)
script_dir = Path(__file__).parent

# Get the root of the repository if running inside one
possible_roots = [cwd, script_dir]

# If running inside a package, check sys.path for possible project locations
for path in sys.path:
if "/usr/" in path:
continue
possible_roots.append(Path(path))

possible_locations = set()

for root in possible_roots:
possible_locations.update(
[
root / "datamodel", # Directly in the project root
root / "bam_masterdata" / "datamodel", # Inside bam_masterdata
root
/ "src"
/ "bam_masterdata"
/ "datamodel", # Inside src-based structure
*(
p / "datamodel" for p in root.iterdir() if p.is_dir()
), # Any other package/datamodel structures
]
)
possible_locations = [
# Case: Running from a project with `datamodel/`
Path.cwd() / "datamodel",
# Case: Running inside bam-masterdata
Path.cwd() / "bam_masterdata" / "datamodel",
# Case: Running inside installed package
Path(__file__).parent / "datamodel",
]

for path in possible_locations:
if path.exists():
return str(path.resolve())

raise FileNotFoundError("Could not find a valid 'datamodel/' directory.")


Expand Down

1 comment on commit 862a377

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
bam_masterdata
   logger.py80100% 
bam_masterdata/cli
   cli.py1167373 37%
   entities_to_excel.py5433 94%
   entities_to_json.py3655 86%
   entities_to_rdf.py753030 60%
   fill_masterdata.py195181181 7%
bam_masterdata/datamodel
   collection_types.py370100% 
   dataset_types.py184184184 0%
   object_types.py15150100% 
   property_types.py8000100% 
   vocabulary_types.py137210100% 
bam_masterdata/excel
   excel_to_entities.py191167167 13%
bam_masterdata/metadata
   definitions.py870100% 
   entities.py8844 95%
bam_masterdata/openbis
   get_entities.py534343 19%
   login.py633 50%
bam_masterdata/utils
   utils.py8399 89%
TOTAL1724970296% 

Tests Skipped Failures Errors Time
83 1 💤 0 ❌ 0 🔥 20.584s ⏱️

Please sign in to comment.