Skip to content

Commit

Permalink
TVB-2113: fixed activate script and pip python path
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianciu committed Dec 3, 2024
1 parent ae03542 commit 548fd43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion tvb_build/build_from_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def linux64():
'bin/tvb_stop.sh': 'bash ./distribution.sh stop',
'bin/jupyter_notebook.sh': set_path + 'cd ../bin\n../tvb_data/bin/python -m jupyterlab ../demo_scripts',
'demo_scripts/jupyter_notebook.sh': set_path + 'cd ../demo_scripts\n../tvb_data/bin/python -m jupyterlab',
'bin/activate_tvb_env.sh': '# Conda must be installed before running this script \n conda activate ../tvb_data \n $SHELL'
'bin/activate_tvb_env.sh': '# Conda must be installed before running this script; \n # Run this script with source. \n conda activate ../tvb_data \n'
}

return Config("Linux", "/opt/conda/envs/tvb-run", join("lib", Environment.PYTHON_FOLDER, "site-packages"),
Expand Down Expand Up @@ -203,7 +203,26 @@ def _create_windows_script(target_file, command):
os.chmod(target_file, 0o755)


def _replace_first_line_if_pattern(pathname: str, pattern: str, replacement: str):
"""
Replaces the first line of a file with a given string if the pathname contains a specific pattern.
In this case, this method is used to add the correct python path to pip
"""
if pattern in pathname:
if not os.path.isfile(pathname):
raise FileNotFoundError(f"The file {pathname} does not exist.")

with open(pathname, 'r') as file:
lines = file.readlines()
if lines:
lines[0] = replacement + '\n'
with open(pathname, 'w') as file:
file.writelines(lines)
_log(f"First line of {pathname} replaced with: {replacement}")


def _modify_pth(pth_name):
# Log if one of the files pip, pip3 or pip3.11 are missing, but do not stop the execution if it is missing
"""
Replace tvb links with paths
"""
Expand Down Expand Up @@ -231,6 +250,7 @@ def _modify_pth(pth_name):
_log(2, "PTH result: \n" + new_content)
with open(pth_name, 'w') as fw:
fw.write(new_content)
_replace_first_line_if_pattern(pth_name, '/bin/pip', '#!../tvb_data/bin/python')


def _fix_jupyter_kernel(tvb_data_folder, is_windows):
Expand Down
2 changes: 1 addition & 1 deletion tvb_build/docker/Dockerfile-build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN service postgresql start && createdb -O postgres tvb-test && psql --command

USER root
RUN conda update -n base -c defaults conda; conda init bash
RUN conda create -y --name tvb-run python=3.11 nomkl numba scipy numpy cython psycopg2
RUN conda create -y --name tvb-run python=3.11 pip nomkl numba scipy numpy cython psycopg2
RUN conda install -y --name tvb-run -c conda-forge jupyterlab tvb-gdist
RUN /opt/conda/envs/tvb-run/bin/pip install --upgrade pip
RUN /opt/conda/envs/tvb-run/bin/pip install lockfile scikit-build
Expand Down

0 comments on commit 548fd43

Please sign in to comment.