Skip to content

Commit 7c38a8c

Browse files
committed
reworked installation for toml usage. updated readme.
1 parent 3384f77 commit 7c38a8c

8 files changed

Lines changed: 308 additions & 172 deletions

File tree

.github/workflows/notebook-test.yml

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,57 @@ jobs:
1010

1111
steps:
1212
- name: Check out repository
13-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1414

1515
- name: Install Act dependencies
1616
if: ${{ env.ACT }}
1717
run: |
1818
apt-get update && apt-get install sudo -y
1919
20+
- name: Install CA cert tools and trust internal CA
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y ca-certificates
24+
sudo update-ca-certificates
25+
2026
- name: Install ping utility
2127
run: |
2228
sudo apt-get update
2329
sudo apt-get install -y iputils-ping
2430
2531
- name: Set timezone to UTC
2632
run: |
27-
export DEBIAN_FRONTEND=noninteractive
28-
if [ -n "$ACT" ]; then
29-
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
30-
echo "Etc/UTC" > /etc/timezone
31-
apt-get update
32-
apt-get install -y tzdata
33-
dpkg-reconfigure -f noninteractive tzdata
34-
else
35-
sudo ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
36-
echo "Etc/UTC" | sudo tee /etc/timezone
37-
sudo apt-get update
38-
sudo apt-get install -y tzdata
39-
sudo dpkg-reconfigure -f noninteractive tzdata
40-
fi
33+
# Use sudo for all commands to ensure permissions in all runner environments
34+
sudo ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
35+
echo "Etc/UTC" | sudo tee /etc/timezone
36+
sudo apt-get update
37+
sudo apt-get install -y tzdata
38+
sudo dpkg-reconfigure -f noninteractive tzdata
4139
42-
- name: Install Python 3.10 and Git
40+
- name: Install Python 3.10, Git, and set CA environment
4341
run: |
44-
export DEBIAN_FRONTEND=noninteractive
4542
sudo apt-get update
46-
sudo apt-get install -y gnupg lsb-release software-properties-common curl git
43+
sudo apt-get install -y lsb-release software-properties-common gnupg curl git
4744
48-
echo "deb [trusted=yes] http://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/deadsnakes-ppa.list
45+
# Properly and securely add the GPG key for the deadsnakes PPA
46+
sudo gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BA6932366A755776
47+
sudo gpg --export BA6932366A755776 | sudo gpg --dearmor -o /usr/share/keyrings/deadsnakes-archive-keyring.gpg
48+
49+
# Add the PPA repository, signed by the new key
50+
echo "deb [signed-by=/usr/share/keyrings/deadsnakes-archive-keyring.gpg] http://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/deadsnakes-ppa.list
51+
4952
sudo apt-get update
5053
sudo apt-get install -y python3.10 python3.10-venv python3.10-distutils
5154
52-
# Set Python 3.10 as default
53-
ln -sf /usr/bin/python3.10 /usr/local/bin/python
54-
ln -sf /usr/bin/python3.10 /usr/local/bin/python3
55-
56-
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
57-
python3.10 -m ensurepip --upgrade
58-
ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip
59-
ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip3
55+
# Set Python 3.10 as default using symbolic links
56+
sudo ln -sf /usr/bin/python3.10 /usr/local/bin/python
57+
sudo ln -sf /usr/bin/python3.10 /usr/local/bin/python3
6058
6159
python --version
62-
pip --version
63-
64-
- name: Set environment variables
65-
run: |
66-
echo "PYTHONHTTPSVERIFY=0" >> $GITHUB_ENV
67-
echo "CURL_CA_BUNDLE=" >> $GITHUB_ENV
68-
echo "SSL_CERT_FILE=" >> $GITHUB_ENV
69-
echo "GIT_SSL_NO_VERIFY=true" >> $GITHUB_ENV
60+
61+
# Set the certificate path for all subsequent steps in the job
62+
echo "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt" >> $GITHUB_ENV
63+
echo "REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt" >> $GITHUB_ENV
7064
7165
- name: Setup ML project
7266
run: |
@@ -89,4 +83,4 @@ jobs:
8983
set -e
9084
cd $GITHUB_WORKSPACE
9185
source "$VENV_PATH/bin/activate"
92-
pytest --nbmake-timeout=1200 notebooks/unit_test_synthetic.ipynb
86+
pytest --nbmake --nbmake-timeout=1200 notebooks/unit_test_synthetic.ipynb

README.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,45 +81,55 @@ Designed for usage with a numeric data matrix for binary classification. Single
8181

8282
## Installation
8383

84-
### Windows:
84+
This project includes convenient installation scripts for Unix/Linux/macOS and Windows. These scripts will create a virtual environment, install all necessary dependencies, and register a Jupyter kernel for you.
8585

86-
1. **Clone the repository:**
87-
```shell
88-
git clone https://github.com/SamoraHunter/ml_binary_classification_gridsearch_hyperOpt.git
89-
cd ml_binary_classification_gridsearch_hyperOpt
90-
```
91-
92-
2. **Run the installation script:**
93-
```shell
94-
install.bat
95-
```
96-
97-
### Unix/Linux:
86+
### Quick Install using Scripts
9887

9988
1. **Clone the repository:**
10089
```shell
10190
git clone https://github.com/SamoraHunter/ml_binary_classification_gridsearch_hyperOpt.git
10291
cd ml_binary_classification_gridsearch_hyperOpt
10392
```
10493

105-
2. **Run the installation script:**
106-
```shell
107-
chmod +x install.sh
108-
./install.sh
109-
```
94+
2. **Run the installation script:**
95+
96+
* **For a standard installation:**
97+
* On Unix/Linux/macOS:
98+
```bash
99+
chmod +x install.sh
100+
./install.sh
101+
```
102+
* On Windows:
103+
```bat
104+
install.bat
105+
```
106+
This will create a virtual environment named `ml_grid_env`.
107+
108+
* **For a time-series installation (includes all standard dependencies):**
109+
* On Unix/Linux/macOS:
110+
```bash
111+
chmod +x install.sh
112+
./install.sh ts
113+
```
114+
* On Windows:
115+
```bat
116+
install.bat ts
117+
```
118+
This will create a virtual environment named `ml_grid_ts_env`.
110119

120+
## Usage
111121

112-
```python
113-
import sys
114-
sys.path.append('/path/to/ml_grid')
115-
import ml_grid
116-
122+
After installation, activate the virtual environment to run your code or notebooks.
117123

118-
```
124+
* **To activate the standard environment:**
125+
* On Unix/Linux/macOS: `source ml_grid_env/bin/activate`
126+
* On Windows: `.\ml_grid_env\Scripts\activate`
119127

120-
## Usage
128+
* **To activate the time-series environment:**
129+
* On Unix/Linux/macOS: `source ml_grid_ts_env/bin/activate`
130+
* On Windows: `.\ml_grid_ts_env\Scripts\activate`
121131

122-
See Appendix
132+
If you are using Jupyter, you can also select the kernel created during installation (e.g., `Python (ml_grid_env)`) directly from the Jupyter interface.
123133

124134
## Examples
125135

install.bat

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,78 @@
11
@echo off
2+
setlocal
3+
4+
rem Default values for standard installation
5+
set "ENV_NAME=ml_grid_env"
6+
set "EXTRAS=[test]"
7+
set "INSTALL_TYPE=standard"
8+
9+
rem Check for 'ts' argument for time-series installation
10+
if /i "%1" == "ts" (
11+
set "ENV_NAME=ml_grid_ts_env"
12+
set "EXTRAS=[test,ts]"
13+
set "INSTALL_TYPE=time-series"
14+
)
15+
16+
echo Starting %INSTALL_TYPE% installation...
17+
echo Environment will be created at: .\%ENV_NAME%
18+
19+
rem Function-like behavior with goto
20+
:error
21+
echo ERROR: %~1
22+
echo Installation failed. Please try deleting the existing ".\%ENV_NAME%" directory and run the script again.
23+
exit /b 1
224

325
rem Check if Python is installed and on path
426
where python >nul 2>nul
527
if %errorlevel% equ 0 (
6-
set PYTHON_COMMAND=python
28+
set "PYTHON_CMD=python"
729
) else (
830
where python3 >nul 2>nul
931
if %errorlevel% equ 0 (
10-
set PYTHON_COMMAND=python3
32+
set "PYTHON_CMD=python3"
1133
) else (
12-
echo Python is not installed or not on path.
13-
exit /b
34+
call :error "Python is not installed or not on path."
1435
)
1536
)
1637

17-
echo %PYTHON_COMMAND% is installed and on path.
18-
1938
rem Check if "ml_grid_env" folder exists in the current directory
20-
if exist "ml_grid_env" (
21-
echo ml_grid_env folder exists in the current directory.
22-
) else (
23-
echo ml_grid_env folder does not exist in the current directory.
24-
echo Creating ml_grid_env folder...
25-
%PYTHON_COMMAND% -m venv ml_grid_env
39+
if not exist "%ENV_NAME%\" (
40+
echo Creating virtual environment...
41+
%PYTHON_CMD% -m venv "%ENV_NAME%"
2642
if %errorlevel% neq 0 (
27-
echo Failed to create virtual environment. Exiting...
28-
exit /b
43+
call :error "Failed to create virtual environment."
2944
)
30-
echo ml_grid_env folder created.
3145
)
3246

3347
rem Activate the virtual environment
34-
call ml_grid_env\Scripts\activate.bat
35-
36-
if errorlevel 1 (
37-
echo Warning: Failed to activate virtual environment.
38-
exit /b
39-
)
40-
48+
call "%ENV_NAME%\Scripts\activate.bat" || call :error "Failed to activate virtual environment."
4149
echo Virtual environment activated successfully.
4250

4351
rem Upgrade pip
4452
echo Upgrading pip...
45-
call ml_grid_env\Scripts\python.exe -m pip install --upgrade pip
46-
47-
rem Install requirements
48-
echo Installing requirements...
49-
pip install -r requirements.txt
53+
pip install --upgrade pip
5054

51-
rem Install ipykernel and add ml_grid_env to the kernel spec
52-
echo Installing ipykernel...
53-
pip install ipykernel
55+
rem Install the project in editable mode along with testing dependencies.
56+
rem This reads all dependencies from pyproject.toml.
57+
echo Installing project dependencies (%EXTRAS%)...
58+
pip install -e .%EXTRAS%
59+
if %errorlevel% neq 0 (
60+
call :error "Failed to install project dependencies."
61+
)
5462

55-
echo Adding ml_grid_env to the kernel spec...
56-
call ml_grid_env\Scripts\python.exe -m ipykernel install --user --name=ml_grid_env
63+
rem Add kernel spec for Jupyter
64+
echo Registering Jupyter kernel...
65+
python -m ipykernel install --user --name="%ENV_NAME%" --display-name="Python (%ENV_NAME%)"
5766

5867
rem Deactivate the virtual environment
5968
echo Deactivating virtual environment...
6069
deactivate
61-
6270
echo Virtual environment deactivated.
6371

64-
echo All operations completed.
65-
exit /b
72+
echo.
73+
echo [SUCCESS] Installation complete!
74+
echo To activate the '%INSTALL_TYPE%' environment, run:
75+
echo .\%ENV_NAME%\Scripts\activate.bat
76+
77+
endlocal
78+
exit /b 0

install.sh

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
#!/bin/bash
22

3+
# Default values for standard installation
4+
ENV_NAME="ml_grid_env"
5+
EXTRAS="[test]"
6+
INSTALL_TYPE="standard"
7+
8+
# Check for 'ts' argument for time-series installation
9+
if [ "$1" == "ts" ]; then
10+
ENV_NAME="ml_grid_ts_env"
11+
EXTRAS="[test,ts]"
12+
INSTALL_TYPE="time-series"
13+
fi
14+
315
# Function to print error message and exit
416
print_error_and_exit() {
5-
echo "$1"
6-
echo "Please try deleting the existing 'ml_grid_env' directory and run the script again."
17+
echo "ERROR: $1"
18+
echo "Installation failed. Please try deleting the existing './$ENV_NAME' directory and run the script again."
719
exit 1
820
}
921

@@ -13,29 +25,40 @@ if command -v python3 &>/dev/null; then
1325
elif command -v python &>/dev/null; then
1426
PYTHON_CMD="python"
1527
else
16-
print_error_and_exit "Python is not installed. Please install Python and try again."
28+
print_error_and_exit "Python is not installed. Please install it and try again."
1729
fi
1830

1931
# Check if virtual environment exists
20-
if [ ! -d "ml_grid_env" ]; then
32+
if [ ! -d "$ENV_NAME" ]; then
2133
# Create virtual environment
22-
$PYTHON_CMD -m venv ml_grid_env || print_error_and_exit "Failed to create virtual environment"
34+
echo "Creating virtual environment..."
35+
$PYTHON_CMD -m venv "$ENV_NAME" || print_error_and_exit "Failed to create virtual environment."
2336
fi
2437

2538
# Activate virtual environment
26-
source ml_grid_env/bin/activate || print_error_and_exit "Failed to activate virtual environment"
39+
# shellcheck source=/dev/null
40+
source "$ENV_NAME/bin/activate" || print_error_and_exit "Failed to activate virtual environment"
2741

28-
# Upgrade pip
29-
$PYTHON_CMD -m pip install --upgrade pip
42+
echo "Virtual environment activated."
3043

31-
# Install ipykernel
32-
pip install ipykernel
44+
# Upgrade pip
45+
echo "Upgrading pip..."
46+
pip install --upgrade pip
3347

34-
# Add kernel spec
35-
$PYTHON_CMD -m ipykernel install --user --name=ml_grid_env
48+
# Install the project in editable mode along with testing dependencies.
49+
# This reads all dependencies from pyproject.toml.
50+
echo "Installing project dependencies ($EXTRAS)..."
51+
pip install -e ."$EXTRAS" || print_error_and_exit "Failed to install project dependencies."
3652

37-
# Install requirements from requirements.txt
38-
pip install -r requirements.txt
53+
# Add kernel spec for Jupyter
54+
echo "Registering Jupyter kernel..."
55+
python -m ipykernel install --user --name="$ENV_NAME" --display-name="Python ($ENV_NAME)"
3956

4057
# Deactivate virtual environment
4158
deactivate
59+
echo "Virtual environment deactivated."
60+
61+
echo ""
62+
echo "✅ Installation complete!"
63+
echo "To activate the '$INSTALL_TYPE' environment, run:"
64+
echo "source $ENV_NAME/bin/activate"

0 commit comments

Comments
 (0)