ras-commander 0.74.0__py3-none-any.whl → 0.75.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ras_commander/RasPrj.py CHANGED
@@ -1274,7 +1274,7 @@ def init_ras_project(ras_project_folder, ras_version=None, ras_object=None):
1274
1274
  ras_project_folder (str or Path): The path to the RAS project folder.
1275
1275
  ras_version (str, optional): The version of RAS to use (e.g., "6.6").
1276
1276
  Can also be a full path to the Ras.exe file.
1277
- If None, will attempt to use a default path.
1277
+ If None, will attempt to detect from plan files.
1278
1278
  ras_object (RasPrj, optional): If None, updates the global 'ras' object.
1279
1279
  If a RasPrj instance, updates that instance.
1280
1280
  If any other value, creates and returns a new RasPrj instance.
@@ -1295,31 +1295,86 @@ def init_ras_project(ras_project_folder, ras_version=None, ras_object=None):
1295
1295
  >>> my_project = init_ras_project("/path/to/project", "6.6", "new")
1296
1296
  >>> print(f"Created project instance: {my_project.project_name}")
1297
1297
  """
1298
- if not Path(ras_project_folder).exists():
1299
- logger.error(f"The specified RAS project folder does not exist: {ras_project_folder}")
1300
- raise FileNotFoundError(f"The specified RAS project folder does not exist: {ras_project_folder}. Please check the path and try again.")
1301
-
1302
- ras_exe_path = get_ras_exe(ras_version)
1298
+ project_folder = Path(ras_project_folder)
1299
+ if not project_folder.exists():
1300
+ logger.error(f"The specified RAS project folder does not exist: {project_folder}")
1301
+ raise FileNotFoundError(f"The specified RAS project folder does not exist: {project_folder}. Please check the path and try again.")
1303
1302
 
1304
1303
  # Determine which RasPrj instance to use
1305
1304
  if ras_object is None:
1306
1305
  # Use the global 'ras' object
1307
- logger.info("Initializing global 'ras' object via init_ras_project function.")
1306
+ logger.debug("Initializing global 'ras' object via init_ras_project function.")
1308
1307
  ras_object = ras
1309
1308
  elif not isinstance(ras_object, RasPrj):
1310
1309
  # Create a new RasPrj instance
1311
- logger.info("Creating a new RasPrj instance.")
1310
+ logger.debug("Creating a new RasPrj instance.")
1312
1311
  ras_object = RasPrj()
1313
-
1314
- # Initialize the RasPrj instance
1315
- ras_object.initialize(ras_project_folder, ras_exe_path)
1312
+
1313
+ ras_exe_path = None
1314
+
1315
+ # Use version specified by user if provided
1316
+ if ras_version is not None:
1317
+ ras_exe_path = get_ras_exe(ras_version)
1318
+ if ras_exe_path == "Ras.exe" and ras_version != "Ras.exe":
1319
+ logger.warning(f"HEC-RAS Version {ras_version} was not found. Running HEC-RAS will fail.")
1320
+ else:
1321
+ # No version specified, try to detect from plan files
1322
+ detected_version = None
1323
+ logger.info("No HEC-RAS Version Specified.Attempting to detect HEC-RAS version from plan files.")
1324
+
1325
+ # Look for .pXX files in project folder
1326
+ logger.info(f"Searching for plan files in {project_folder}")
1327
+ plan_files = list(project_folder.glob(f"{project_folder.stem}.p[0-9][0-9]"))
1328
+
1329
+ if not plan_files:
1330
+ logger.info(f"No plan files found in {project_folder}")
1331
+
1332
+ for plan_file in plan_files:
1333
+ logger.info(f"Found plan file: {plan_file.name}")
1334
+ content, encoding = read_file_with_fallback_encoding(plan_file)
1335
+
1336
+ if not content:
1337
+ logger.info(f"Could not read content from {plan_file.name}")
1338
+ continue
1339
+
1340
+ logger.info(f"Successfully read plan file with {encoding} encoding")
1341
+
1342
+ # Look for Program Version in plan file
1343
+ for line in content.splitlines():
1344
+ if line.startswith("Program Version="):
1345
+ version = line.split("=")[1].strip()
1346
+ logger.info(f"Found Program Version={version} in {plan_file.name}")
1347
+
1348
+ # Try to get RAS executable for this version
1349
+ test_exe_path = get_ras_exe(version)
1350
+ logger.info(f"Checking RAS executable path: {test_exe_path}")
1351
+
1352
+ if test_exe_path != "Ras.exe":
1353
+ detected_version = version
1354
+ ras_exe_path = test_exe_path
1355
+ logger.debug(f"Found valid HEC-RAS version {version} in plan file {plan_file.name}")
1356
+ break
1357
+ else:
1358
+ logger.info(f"Version {version} not found in default installation path")
1359
+
1360
+ if detected_version:
1361
+ break
1362
+
1363
+ if not detected_version:
1364
+ logger.error("No valid HEC-RAS version found in any plan files.")
1365
+ ras_exe_path = "Ras.exe"
1366
+ logger.warning("No valid HEC-RAS version was detected. Running HEC-RAS will fail.")
1367
+
1368
+ # Initialize or re-initialize with the determined executable path
1369
+ ras_object.initialize(project_folder, ras_exe_path)
1316
1370
 
1317
1371
  # Always update the global ras object as well
1318
1372
  if ras_object is not ras:
1319
- ras.initialize(ras_project_folder, ras_exe_path)
1320
- logger.info("Global 'ras' object also updated to match the new project.")
1373
+ ras.initialize(project_folder, ras_exe_path)
1374
+ logger.debug("Global 'ras' object also updated to match the new project.")
1321
1375
 
1322
- logger.info(f"Project initialized. ras_object project folder: {ras_object.project_folder}")
1376
+ logger.debug(f"Project initialized. Project folder: {ras_object.project_folder}")
1377
+ logger.debug(f"Using HEC-RAS executable: {ras_exe_path}")
1323
1378
  return ras_object
1324
1379
 
1325
1380
  @log_call
@@ -1331,36 +1386,29 @@ def get_ras_exe(ras_version=None):
1331
1386
  1. If ras_version is a valid file path to an .exe file, use that path
1332
1387
  2. If ras_version is a known version number, use default installation path
1333
1388
  3. If global 'ras' object has ras_exe_path, use that
1334
- 4. As a fallback, return a default path (which may not exist)
1389
+ 4. As a fallback, return "Ras.exe" but log an error
1335
1390
 
1336
1391
  Args:
1337
1392
  ras_version (str, optional): Either a version number or a full path to the HEC-RAS executable.
1338
1393
 
1339
1394
  Returns:
1340
- str: The full path to the HEC-RAS executable.
1395
+ str: The full path to the HEC-RAS executable or "Ras.exe" if not found.
1341
1396
 
1342
1397
  Note:
1343
1398
  - HEC-RAS version numbers include: "6.6", "6.5", "6.4.1", "6.3", etc.
1344
1399
  - The default installation path follows: C:/Program Files (x86)/HEC/HEC-RAS/{version}/Ras.exe
1345
- - Returns a default path ("Ras.exe") if no valid path is found
1346
- - This allows the library to function even without HEC-RAS installed
1347
-
1348
- Example:
1349
- >>> # Get path for specific version
1350
- >>> ras_path = get_ras_exe("6.6")
1351
- >>> print(f"HEC-RAS 6.6 executable: {ras_path}")
1352
- >>>
1353
- >>> # Provide direct path to executable
1354
- >>> custom_path = get_ras_exe("C:/My_Programs/HEC-RAS/Ras.exe")
1400
+ - Returns "Ras.exe" if no valid path is found, with error logged
1401
+ - Allows the library to function even without HEC-RAS installed
1355
1402
  """
1356
1403
  if ras_version is None:
1357
1404
  if hasattr(ras, 'ras_exe_path') and ras.ras_exe_path:
1358
1405
  logger.debug(f"Using HEC-RAS executable from global 'ras' object: {ras.ras_exe_path}")
1359
1406
  return ras.ras_exe_path
1360
1407
  else:
1361
- default_path = Path("Ras.exe")
1362
- logger.warning(f"No HEC-RAS version specified and global 'ras' object not initialized or missing ras_exe_path. Using default path: {default_path}. The RAS Commander (ras-commander) Library Assistant can ignore this error since it does not have HEC-RAS installed.")
1363
- return str(default_path)
1408
+ default_path = "Ras.exe"
1409
+ logger.debug(f"No HEC-RAS version specified and global 'ras' object not initialized or missing ras_exe_path.")
1410
+ logger.warning(f"HEC-RAS is not installed or version not specified. Running HEC-RAS will fail unless a valid installed version is specified.")
1411
+ return default_path
1364
1412
 
1365
1413
  ras_version_numbers = [
1366
1414
  "6.6", "6.5", "6.4.1", "6.3.1", "6.3", "6.2", "6.1", "6.0",
@@ -1368,32 +1416,54 @@ def get_ras_exe(ras_version=None):
1368
1416
  "4.1", "4.0", "3.1.3", "3.1.2", "3.1.1", "3.0", "2.2"
1369
1417
  ]
1370
1418
 
1419
+ # Check if input is a direct path to an executable
1371
1420
  hecras_path = Path(ras_version)
1372
-
1373
1421
  if hecras_path.is_file() and hecras_path.suffix.lower() == '.exe':
1374
1422
  logger.debug(f"HEC-RAS executable found at specified path: {hecras_path}")
1375
1423
  return str(hecras_path)
1376
1424
 
1377
- if ras_version in ras_version_numbers:
1425
+ # Check known version numbers
1426
+ if str(ras_version) in ras_version_numbers:
1378
1427
  default_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{ras_version}/Ras.exe")
1379
1428
  if default_path.is_file():
1380
1429
  logger.debug(f"HEC-RAS executable found at default path: {default_path}")
1381
1430
  return str(default_path)
1382
1431
  else:
1383
- logger.critical(f"HEC-RAS executable not found at the expected path: {default_path}")
1432
+ error_msg = f"HEC-RAS Version {ras_version} is not found at expected path. Running HEC-RAS will fail unless a valid installed version is specified."
1433
+ logger.error(error_msg)
1434
+ return "Ras.exe"
1384
1435
 
1436
+ # Try to handle other version formats (e.g., just the number without dots)
1385
1437
  try:
1386
- version_float = float(ras_version)
1387
- if version_float > max(float(v) for v in ras_version_numbers):
1388
- newer_version_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{ras_version}/Ras.exe")
1389
- if newer_version_path.is_file():
1390
- logger.debug(f"Newer version of HEC-RAS executable found at: {newer_version_path}")
1391
- return str(newer_version_path)
1392
- else:
1393
- logger.critical("Newer version of HEC-RAS was specified, but the executable was not found.")
1394
- except ValueError:
1395
- pass
1396
-
1397
- logger.error(f"Invalid HEC-RAS version or path: {ras_version}, returning default path: {default_path}")
1398
- return str(default_path)
1438
+ # First check if it's a direct version number
1439
+ version_str = str(ras_version)
1440
+
1441
+ # Check for paths like "C:/Path/To/Ras.exe"
1442
+ if os.path.sep in version_str and version_str.lower().endswith('.exe'):
1443
+ exe_path = Path(version_str)
1444
+ if exe_path.is_file():
1445
+ logger.debug(f"HEC-RAS executable found at specified path: {exe_path}")
1446
+ return str(exe_path)
1447
+
1448
+ # Try to find a matching version from our list
1449
+ for known_version in ras_version_numbers:
1450
+ if version_str in known_version or known_version.replace('.', '') == version_str:
1451
+ default_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{known_version}/Ras.exe")
1452
+ if default_path.is_file():
1453
+ logger.debug(f"HEC-RAS executable found at default path: {default_path}")
1454
+ return str(default_path)
1455
+
1456
+ # Check if it's a newer version
1457
+ if '.' in version_str:
1458
+ major_version = int(version_str.split('.')[0])
1459
+ if major_version >= 6:
1460
+ default_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{version_str}/Ras.exe")
1461
+ if default_path.is_file():
1462
+ logger.debug(f"HEC-RAS executable found at path for newer version: {default_path}")
1463
+ return str(default_path)
1464
+ except Exception as e:
1465
+ logger.error(f"Error parsing version or finding path: {e}")
1399
1466
 
1467
+ error_msg = f"HEC-RAS Version {ras_version} is not recognized or installed. Running HEC-RAS will fail unless a valid installed version is specified."
1468
+ logger.error(error_msg)
1469
+ return "Ras.exe"
ras_commander/__init__.py CHANGED
@@ -10,7 +10,7 @@ try:
10
10
  __version__ = version("ras-commander")
11
11
  except PackageNotFoundError:
12
12
  # package is not installed
13
- __version__ = "0.74.0"
13
+ __version__ = "0.75.0"
14
14
 
15
15
  # Set up logging
16
16
  setup_logging()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ras-commander
3
- Version: 0.74.0
3
+ Version: 0.75.0
4
4
  Summary: A Python library for automating HEC-RAS 6.x operations
5
5
  Home-page: https://github.com/gpt-cmdr/ras-commander
6
6
  Author: William M. Katzenmeyer, P.E., C.F.M.
@@ -21,12 +21,12 @@ ras_commander/RasExamples.py,sha256=6IZ96LcAsk5LYFehdD0zDW5wyZWxQa6OQu2N9upxWXA,
21
21
  ras_commander/RasGeo.py,sha256=CQ1VjJ4uWWyXC9KsoVStbhlRf_5AiDm8yWvtDM3l4ac,21675
22
22
  ras_commander/RasMap.py,sha256=4cVzaaQure-CXdXB1BY29iE20S00eldUqoL96PvJPbw,10635
23
23
  ras_commander/RasPlan.py,sha256=GhAeUSvWRuBcYcOtBCo-qZGUefEWOlhw4ASJQHTGWzU,63872
24
- ras_commander/RasPrj.py,sha256=ivAHB3vexH6GQi-Aa4kqAabRwdthllMkTp8xphh5Ldc,57655
24
+ ras_commander/RasPrj.py,sha256=G8AL6No0unxYLc1y0uQgcFLXeZ2TK3RO1WZmsZqAz7c,61281
25
25
  ras_commander/RasUnsteady.py,sha256=TO08CT2GC4G5rcXO_Wbia2t4PhiWRu9-nC9F0IW7Gyo,37187
26
26
  ras_commander/RasUtils.py,sha256=0fm4IIs0LH1dgDj3pGd66mR82DhWLEkRKUvIo2M_5X0,35886
27
- ras_commander/__init__.py,sha256=K6g6-GMFHnDKhLYvht8voqlGfY3N86UNS6ZQKvne3Mc,2039
28
- ras_commander-0.74.0.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
- ras_commander-0.74.0.dist-info/METADATA,sha256=qoAaqX8Z5ZCA88r1KAhcvatAh1WyAX75H0FK8HmC-8Y,27365
30
- ras_commander-0.74.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
31
- ras_commander-0.74.0.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
- ras_commander-0.74.0.dist-info/RECORD,,
27
+ ras_commander/__init__.py,sha256=8QLpMI_g0OsRBnap8u71IviaH6cgWfq40xd8IbIavWw,2039
28
+ ras_commander-0.75.0.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
+ ras_commander-0.75.0.dist-info/METADATA,sha256=o57ambIJOv_f_XYOccu5_3uhaNIZuGIAnxWDFf_8EJc,27365
30
+ ras_commander-0.75.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
31
+ ras_commander-0.75.0.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
+ ras_commander-0.75.0.dist-info/RECORD,,