ras-commander 0.74.0__py3-none-any.whl → 0.76.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,91 @@ 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
+ # Search for any file with .p01 through .p99 extension, regardless of base name
1328
+ plan_files = list(project_folder.glob("*.p[0-9][0-9]"))
1329
+
1330
+ if not plan_files:
1331
+ logger.info(f"No plan files found in {project_folder}")
1332
+
1333
+ for plan_file in plan_files:
1334
+ logger.info(f"Found plan file: {plan_file.name}")
1335
+ content, encoding = read_file_with_fallback_encoding(plan_file)
1336
+
1337
+ if not content:
1338
+ logger.info(f"Could not read content from {plan_file.name}")
1339
+ continue
1340
+
1341
+ logger.info(f"Successfully read plan file with {encoding} encoding")
1342
+
1343
+ # Look for Program Version in plan file
1344
+ for line in content.splitlines():
1345
+ if line.startswith("Program Version="):
1346
+ version = line.split("=")[1].strip()
1347
+ logger.info(f"Found Program Version={version} in {plan_file.name}")
1348
+
1349
+ # Replace 00 in version string if present
1350
+ if "00" in version:
1351
+ version = version.replace("00", "0")
1352
+
1353
+ # Try to get RAS executable for this version
1354
+ test_exe_path = get_ras_exe(version)
1355
+ logger.info(f"Checking RAS executable path: {test_exe_path}")
1356
+
1357
+ if test_exe_path != "Ras.exe":
1358
+ detected_version = version
1359
+ ras_exe_path = test_exe_path
1360
+ logger.debug(f"Found valid HEC-RAS version {version} in plan file {plan_file.name}")
1361
+ break
1362
+ else:
1363
+ logger.info(f"Version {version} not found in default installation path")
1364
+
1365
+ if detected_version:
1366
+ break
1367
+
1368
+ if not detected_version:
1369
+ logger.error("No valid HEC-RAS version found in any plan files.")
1370
+ ras_exe_path = "Ras.exe"
1371
+ logger.warning("No valid HEC-RAS version was detected. Running HEC-RAS will fail.")
1372
+
1373
+ # Initialize or re-initialize with the determined executable path
1374
+ ras_object.initialize(project_folder, ras_exe_path)
1316
1375
 
1317
1376
  # Always update the global ras object as well
1318
1377
  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.")
1378
+ ras.initialize(project_folder, ras_exe_path)
1379
+ logger.debug("Global 'ras' object also updated to match the new project.")
1321
1380
 
1322
- logger.info(f"Project initialized. ras_object project folder: {ras_object.project_folder}")
1381
+ logger.debug(f"Project initialized. Project folder: {ras_object.project_folder}")
1382
+ logger.debug(f"Using HEC-RAS executable: {ras_exe_path}")
1323
1383
  return ras_object
1324
1384
 
1325
1385
  @log_call
@@ -1331,36 +1391,29 @@ def get_ras_exe(ras_version=None):
1331
1391
  1. If ras_version is a valid file path to an .exe file, use that path
1332
1392
  2. If ras_version is a known version number, use default installation path
1333
1393
  3. If global 'ras' object has ras_exe_path, use that
1334
- 4. As a fallback, return a default path (which may not exist)
1394
+ 4. As a fallback, return "Ras.exe" but log an error
1335
1395
 
1336
1396
  Args:
1337
1397
  ras_version (str, optional): Either a version number or a full path to the HEC-RAS executable.
1338
1398
 
1339
1399
  Returns:
1340
- str: The full path to the HEC-RAS executable.
1400
+ str: The full path to the HEC-RAS executable or "Ras.exe" if not found.
1341
1401
 
1342
1402
  Note:
1343
1403
  - HEC-RAS version numbers include: "6.6", "6.5", "6.4.1", "6.3", etc.
1344
1404
  - 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")
1405
+ - Returns "Ras.exe" if no valid path is found, with error logged
1406
+ - Allows the library to function even without HEC-RAS installed
1355
1407
  """
1356
1408
  if ras_version is None:
1357
1409
  if hasattr(ras, 'ras_exe_path') and ras.ras_exe_path:
1358
1410
  logger.debug(f"Using HEC-RAS executable from global 'ras' object: {ras.ras_exe_path}")
1359
1411
  return ras.ras_exe_path
1360
1412
  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)
1413
+ default_path = "Ras.exe"
1414
+ logger.debug(f"No HEC-RAS version specified and global 'ras' object not initialized or missing ras_exe_path.")
1415
+ logger.warning(f"HEC-RAS is not installed or version not specified. Running HEC-RAS will fail unless a valid installed version is specified.")
1416
+ return default_path
1364
1417
 
1365
1418
  ras_version_numbers = [
1366
1419
  "6.6", "6.5", "6.4.1", "6.3.1", "6.3", "6.2", "6.1", "6.0",
@@ -1368,32 +1421,54 @@ def get_ras_exe(ras_version=None):
1368
1421
  "4.1", "4.0", "3.1.3", "3.1.2", "3.1.1", "3.0", "2.2"
1369
1422
  ]
1370
1423
 
1424
+ # Check if input is a direct path to an executable
1371
1425
  hecras_path = Path(ras_version)
1372
-
1373
1426
  if hecras_path.is_file() and hecras_path.suffix.lower() == '.exe':
1374
1427
  logger.debug(f"HEC-RAS executable found at specified path: {hecras_path}")
1375
1428
  return str(hecras_path)
1376
1429
 
1377
- if ras_version in ras_version_numbers:
1430
+ # Check known version numbers
1431
+ if str(ras_version) in ras_version_numbers:
1378
1432
  default_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{ras_version}/Ras.exe")
1379
1433
  if default_path.is_file():
1380
1434
  logger.debug(f"HEC-RAS executable found at default path: {default_path}")
1381
1435
  return str(default_path)
1382
1436
  else:
1383
- logger.critical(f"HEC-RAS executable not found at the expected path: {default_path}")
1437
+ 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."
1438
+ logger.error(error_msg)
1439
+ return "Ras.exe"
1384
1440
 
1441
+ # Try to handle other version formats (e.g., just the number without dots)
1385
1442
  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)
1443
+ # First check if it's a direct version number
1444
+ version_str = str(ras_version)
1445
+
1446
+ # Check for paths like "C:/Path/To/Ras.exe"
1447
+ if os.path.sep in version_str and version_str.lower().endswith('.exe'):
1448
+ exe_path = Path(version_str)
1449
+ if exe_path.is_file():
1450
+ logger.debug(f"HEC-RAS executable found at specified path: {exe_path}")
1451
+ return str(exe_path)
1452
+
1453
+ # Try to find a matching version from our list
1454
+ for known_version in ras_version_numbers:
1455
+ if version_str in known_version or known_version.replace('.', '') == version_str:
1456
+ default_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{known_version}/Ras.exe")
1457
+ if default_path.is_file():
1458
+ logger.debug(f"HEC-RAS executable found at default path: {default_path}")
1459
+ return str(default_path)
1460
+
1461
+ # Check if it's a newer version
1462
+ if '.' in version_str:
1463
+ major_version = int(version_str.split('.')[0])
1464
+ if major_version >= 6:
1465
+ default_path = Path(f"C:/Program Files (x86)/HEC/HEC-RAS/{version_str}/Ras.exe")
1466
+ if default_path.is_file():
1467
+ logger.debug(f"HEC-RAS executable found at path for newer version: {default_path}")
1468
+ return str(default_path)
1469
+ except Exception as e:
1470
+ logger.error(f"Error parsing version or finding path: {e}")
1399
1471
 
1472
+ 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."
1473
+ logger.error(error_msg)
1474
+ 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.76.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.76.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=XbFWp8Du7mJNSBdeZNqzSQAnKJXXhlIlNAiC4pXCEmY,61532
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=oWD97fwXTwfQ0l3-W3tj65l_fWmd453CWL-TBnK9-Ho,2039
28
+ ras_commander-0.76.0.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
+ ras_commander-0.76.0.dist-info/METADATA,sha256=eEQ2bJt_VyNXNW0OXC-yNXn4QVXPQy2apc9WY7YKtaY,27365
30
+ ras_commander-0.76.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
31
+ ras_commander-0.76.0.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
+ ras_commander-0.76.0.dist-info/RECORD,,