From 58e21db91182b031c1b9e78126da583796f09103 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 5 Nov 2024 17:54:15 -0500 Subject: [PATCH 1/2] try to detect enviro --- bmds_ui/desktop/actions.py | 23 +++++++++++++++++++++++ bmds_ui/desktop/templates/manager-bat.txt | 9 +++++++++ bmds_ui/desktop/templates/manager-sh.txt | 9 +++++++++ 3 files changed, 41 insertions(+) diff --git a/bmds_ui/desktop/actions.py b/bmds_ui/desktop/actions.py index 0eb4657..997808d 100644 --- a/bmds_ui/desktop/actions.py +++ b/bmds_ui/desktop/actions.py @@ -172,8 +172,29 @@ def render_template(template_text: str, context: dict) -> str: return template.render(Context(context)) +def get_activate_script() -> tuple[str, str]: + """Try to determine how to activate the environment. + + First check if we're in a python virtual environment with an activate script, next try to determine if we're in a conda environment. If neither, return unknown. + + Returns: + tuple[str, str]: (environment_type {venv, conda, unknown}, path/name) + """ + python_path = Path(sys.executable) + bin_path = python_path.parent + if (bin_path / "activate").exists(): + return "venv", str(bin_path / "activate") + elif (bin_path / "activate.bat").exists(): + return "venv", str(bin_path / "activate.bat") + elif "CONDA_PREFIX" in os.environ and Path(os.environ["CONDA_PREFIX"]).exists(): + return "conda", Path(os.environ["CONDA_PREFIX"]).name + else: + return "unknown", "" + + def write_startup_script(template: str) -> str: python_path = Path(sys.executable) + env_type, env = get_activate_script() show_prerelease = get_installed_version().is_prerelease return render_template( template, @@ -181,6 +202,8 @@ def write_startup_script(template: str) -> str: "prerelease_url": PRERELEASE_URL, "show_prerelease": show_prerelease, "python_path": python_path, + "env_type": env_type, + "env": env, }, ) diff --git a/bmds_ui/desktop/templates/manager-bat.txt b/bmds_ui/desktop/templates/manager-bat.txt index f2f1225..1988942 100644 --- a/bmds_ui/desktop/templates/manager-bat.txt +++ b/bmds_ui/desktop/templates/manager-bat.txt @@ -75,6 +75,15 @@ echo: echo Python Path: echo {{ python_path }} echo: +{% if env_type == "venv" %} +echo To activate your environment, open a new terminal and run: +echo {{env}} +echo: +{% elif env_type == "conda" %} +echo To activate your environment, open a new terminal and run: +echo conda activate {{env}} +echo: +{% endif %} echo BMDS UI + pybmds Version: "{{ python_path }}" -m pip show bmds-ui pybmds echo: diff --git a/bmds_ui/desktop/templates/manager-sh.txt b/bmds_ui/desktop/templates/manager-sh.txt index daeb01c..f5935bf 100644 --- a/bmds_ui/desktop/templates/manager-sh.txt +++ b/bmds_ui/desktop/templates/manager-sh.txt @@ -74,6 +74,15 @@ echo echo "Python Path:" echo "{{ python_path }}" echo +{% if env_type == "venv" %} +echo To activate your environment, open a new terminal and run: +echo "source \"{{env}}\"" +echo +{% elif env_type == "conda" %} +echo To activate your environment, open a new terminal and run: +echo "conda activate {{env}}" +echo +{% endif %} echo "BMDS UI + pybmds Version:" "{{ python_path }}" -m pip show bmds-ui pybmds echo From 03c9d38c97a677c0403bcbd42df99fa0edd6e191 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Mon, 11 Nov 2024 21:04:13 -0500 Subject: [PATCH 2/2] fix bug on reporting of df --- frontend/src/components/IndividualModel/Summary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/IndividualModel/Summary.js b/frontend/src/components/IndividualModel/Summary.js index a934437..a516a25 100644 --- a/frontend/src/components/IndividualModel/Summary.js +++ b/frontend/src/components/IndividualModel/Summary.js @@ -32,7 +32,7 @@ class Summary extends Component { const isContinuous = outputStore.getModelType === mc.MODEL_CONTINUOUS, results = model.bmd ? model : model.results, p_value = isContinuous ? results.tests.p_values[3] : results.gof.p_value, - df = isContinuous ? results.tests.p_values[3] : results.gof.df; + df = isContinuous ? results.tests.dfs[3] : results.gof.df; data = [ ["BMD", ff(results.bmd), results.bmd], ["BMDL", ff(results.bmdl), results.bmdl],