|
48 | 48 | import taichi as ti |
49 | 49 | except ImportError: |
50 | 50 | print('Taichi is not installed. Please install it using "pip install taichi".') # noqa: T201 |
| 51 | + print('Attempting to install taichi automatically for you...') # noqa: T201 |
51 | 52 | print() # noqa: T201 |
52 | | - subprocess.run([sys.executable, '-m', 'pip', 'install', 'taichi'], check=False) # noqa: S603 |
| 53 | + # SYSEXECUTABLE = sys.executable # noqa: N806 |
| 54 | + # PYTHONPATH = os.environ.get('PYTHONPATH', '') # noqa: N806 |
| 55 | + # PYTHONHOME = os.environ.get('PYTHONHOME', '') # noqa: N806 |
| 56 | + # PYTHONSTARTUP = os.environ.get('PYTHONSTARTUP', '') # noqa: N806 |
| 57 | + # VIRTUAL_ENV = os.environ.get('VIRTUAL_ENV', '') # noqa: N806 |
| 58 | + # PIP_REQUIRE_VIRTUALENV = os.environ.get('PIP_REQUIRE_VIRTUALENV', '') # noqa: N806 |
| 59 | + # print('If you are using a virtual environment, make sure it is activated.') # noqa: T201 |
| 60 | + # print('Python executable being used to install taichi (i.e., sys.excutable):', SYSEXECUTABLE) # noqa: T201 |
| 61 | + # print('PYTHONPATH:', PYTHONPATH) |
| 62 | + # print('PYTHONHOME:', PYTHONHOME) # noqa: T201 |
| 63 | + # print('PYTHONSTARTUP:', PYTHONSTARTUP) |
| 64 | + |
| 65 | + # if VIRTUAL_ENV: |
| 66 | + # print('VIRTUAL_ENV:', VIRTUAL_ENV) |
| 67 | + # else: |
| 68 | + # print('No virtual environment detected. If you are using one, please activate it before running this script.') |
| 69 | + |
| 70 | + # if PIP_REQUIRE_VIRTUALENV: |
| 71 | + # print('PIP_REQUIRE_VIRTUALENV:', PIP_REQUIRE_VIRTUALENV) |
| 72 | + # else: |
| 73 | + # print('No PIP_REQUIRE_VIRTUALENV environment variable detected. If you are using a virtual environment, please activate it before running this script.') |
| 74 | + |
| 75 | + print() |
| 76 | + |
53 | 77 | try: |
54 | | - import taichi as ti |
55 | | - except ImportError: |
56 | | - print('Taichi installation failed. Please install it manually.') # noqa: T201 |
57 | | - sys.exit(1) |
58 | | - print('Taichi is installed successfully.') # noqa: T201 |
| 78 | + print('Try to install with $ python -m pip install taichi') |
| 79 | + subprocess.run([sys.executable, '-m', 'pip', 'install', 'taichi'], check=False) # noqa: S603 |
| 80 | + try: |
| 81 | + import taichi as ti |
| 82 | + except ImportError: |
| 83 | + print('Taichi installation failed. Please install it manually.') # noqa: T201 |
| 84 | + # sys.exit(1) |
| 85 | + except: |
| 86 | + # Might be user permission issue |
| 87 | + print('Try to install with $ python -m pip install --user taichi') # noqa: T201 |
| 88 | + try: |
| 89 | + subprocess.run([sys.executable, '-m', 'pip', 'install', '--user', 'taichi'], check=False) # noqa: S603 |
| 90 | + try: |
| 91 | + import taichi as ti |
| 92 | + except ImportError: |
| 93 | + print('Taichi installation failed. Please install it manually.') |
| 94 | + # sys.exit(1) |
| 95 | + except: |
| 96 | + print('Try to install with $ pip install taichi') # noqa: T201 |
| 97 | + try: |
| 98 | + subprocess.run(['pip', 'install', 'taichi'], check=False) # noqa: S603 |
| 99 | + try: |
| 100 | + import taichi as ti |
| 101 | + except ImportError: |
| 102 | + print('Taichi installation failed. Please install it manually.') |
| 103 | + # sys.exit(1) |
| 104 | + except: |
| 105 | + print('ERROR: Cannot install taichi. There is likely an issue with you Python environment, OS, GLIBC, or pip installation.') # noqa: T201 |
| 106 | + print('INFO: Please manually install taichi into the Python environment specified in the desktop applications Files > Preferences tab') |
| 107 | + sys.exit(1) |
59 | 108 | print() # noqa: T201 |
60 | 109 |
|
61 | 110 |
|
@@ -350,10 +399,52 @@ def main(): |
350 | 399 | for event in evt['Events']: |
351 | 400 | # Redesign the input structure in backend CelerisAi later. |
352 | 401 | # For now assume waveFile, bathymetryFile, configFile, etc. are in the same directory. |
353 | | - caseDirectory = event['configFilePath'] # noqa: N816 |
| 402 | + # caseDirectory = event['configFilePath'] # noqa: N816 |
| 403 | + caseDirectory = '.' |
| 404 | + configDirectory = event['configFilePath'] # noqa: N816 |
354 | 405 | configFilename = event['configFile'] # noqa: N816 |
| 406 | + bathymetryDirectory = event['bathymetryFilePath'] # noqa: N816 |
355 | 407 | bathymetryFilename = event['bathymetryFile'] # noqa: N816 |
| 408 | + waveDirectory = event['waveFilePath'] # noqa: N816 |
356 | 409 | waveFilename = event['waveFile'] # noqa: N816 |
| 410 | + |
| 411 | + # configFilename = os.path.join( # noqa: PTH118 |
| 412 | + # configDirectory, configFilename |
| 413 | + # ) # noqa: N816, PTH118 |
| 414 | + # bathymetryFilename = os.path.join( # noqa: PTH118 |
| 415 | + # bathymetryDirectory, bathymetryFilename |
| 416 | + # ) # noqa: N816, PTH118 |
| 417 | + # waveFilename = os.path.join( # noqa: PTH118 |
| 418 | + # waveDirectory, waveFilename |
| 419 | + # ) # noqa: N816, PTH118 |
| 420 | + |
| 421 | + # Check if the config file exists |
| 422 | + if not os.path.exists(configFilename): # noqa: PTH110 |
| 423 | + print('Config file does not exist:', configFilename) |
| 424 | + # Use default config file |
| 425 | + configFilename = os.path.join( # noqa: PTH118 |
| 426 | + caseDirectory, 'config.json' |
| 427 | + ) # noqa: N816, PTH118 |
| 428 | + print('Using default config file:', configFilename) # noqa: T201 |
| 429 | + |
| 430 | + # Check if the bathymetry file exists |
| 431 | + if not os.path.exists(bathymetryFilename): |
| 432 | + print('Bathymetry file does not exist:', bathymetryFilename) # noqa: T201 |
| 433 | + # Use default bathymetry file |
| 434 | + bathymetryFilename = os.path.join( # noqa: PTH118 |
| 435 | + caseDirectory, 'bathy.txt' |
| 436 | + ) # noqa: N816, PTH118 |
| 437 | + print('Using default bathymetry file:', bathymetryFilename) |
| 438 | + |
| 439 | + # Check if the wave file exists |
| 440 | + if not os.path.exists(waveFilename): # noqa: PTH110 |
| 441 | + print('Wave file does not exist:', waveFilename) # noqa: T201 |
| 442 | + # Use default wave file |
| 443 | + waveFilename = os.path.join( # noqa: PTH118 |
| 444 | + caseDirectory, 'waves.txt' |
| 445 | + ) |
| 446 | + print('Using default wave file:', waveFilename) # noqa: T201 |
| 447 | + |
357 | 448 | # Determine dt for the force time series |
358 | 449 | # Try to compute using Courant_num (CFL), otherwise look for dt in the config |
359 | 450 | if 'Courant_num' in event['config']: |
|
0 commit comments