Skip to content

Commit d012c1d

Browse files
committed
set env variables through command line
1 parent b528e63 commit d012c1d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/compas_fea2/cli.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
import sys
88

99
import click
10+
import importlib
11+
import dotenv
1012

11-
from compas_fea2 import HOME
13+
from compas_fea2 import HOME, VERBOSE
1214

1315
try:
1416
from fea2_extension.main import init_plugin # type: ignore
1517
except Exception:
16-
print("WARNING: fea2_extension module not installed.")
18+
if VERBOSE:
19+
print("WARNING: fea2_extension module not installed.")
1720

1821

1922
# -------------------------------- MAIN ----------------------------------#
@@ -46,28 +49,25 @@ def init_backend(backend, clean):
4649

4750

4851
@main.command()
49-
# @click.option('--clean', default='False', help='remove existing directories')
5052
@click.argument("backend")
5153
@click.argument("setting")
5254
@click.argument("value")
53-
def change_settings(backend, setting, value):
55+
def change_setting(backend, setting, value):
5456
"""Change a setting for the specified backend.\n
5557
backend : txt\n
5658
The name of the backend.
5759
setting : txt\n
5860
The setting to be changed.
5961
value : txt\n
6062
The new value for the setting.
61-
"""
62-
backend_settings = os.path.join(HOME, "src", "compas_fea2", "backends", backend.lower(), "settings.json")
63-
64-
with open(backend_settings, "r") as f:
65-
settings = json.load(f)
66-
67-
with open(backend_settings, "w") as f:
68-
settings[setting] = value
69-
json.dump(settings, f)
7063
64+
Example usage:\n
65+
fea2 change-setting opensees exe "Applications/OpenSees3.5.0/bin/OpenSees"
66+
"""
67+
m = importlib.import_module("compas_fea2_"+backend.lower())
68+
env = os.path.join(m.HOME,"src", "compas_fea2_"+backend.lower(),".env")
69+
dotenv.set_key(env, setting.upper(), value)
70+
print(f"{setting.upper()} set to {value} for compas_fea2_{backend.lower()}")
7171

7272
# -------------------------------- DEBUG ----------------------------------#
7373
if __name__ == "__main__":

0 commit comments

Comments
 (0)