From 810ce5c5d95b12ce590106c56e060e34e3f70f16 Mon Sep 17 00:00:00 2001 From: Umberto Date: Thu, 30 Jan 2025 15:23:46 +0000 Subject: [PATCH 1/4] Aggiungi configurazione del contenitore di sviluppo e script di setup --- .devcontainer/devcontainer.json | 22 +++++++++++++ .devcontainer/setup.sh | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/setup.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..56ce9d309 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +{ + "name": "My Dev Container", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": {}, + "customizations": { + "vscode": { + "extensions": [ + "github.copilot", + "github.copilot-chat", + "github.github-vscode-theme", + "github.vscode-pull-request-github", + "ms-ceintl.vscode-language-pack-it", + "ms-python.python", + "ms-vscode.vscode-typescript-next" + ] + } + }, + "postCreateCommand": "bash .devcontainer/setup.sh", + "mounts": [ + "source=${localWorkspaceFolder},target=/workspace,type=bind" + ] +} \ No newline at end of file diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100644 index 000000000..053152e5a --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,55 @@ +#!/bin/bash +set -e # Exit on error + +# Update and install dependencies +sudo apt update +sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \ + wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git + +# Install pyenv +curl https://pyenv.run | bash + +# Add pyenv to shell profile +echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc +echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc +echo 'eval "$(pyenv init --path)"' >> ~/.bashrc +echo 'eval "$(pyenv init -)"' >> ~/.bashrc + +# Apply changes +source ~/.bashrc + +# Install Python 3.10 using pyenv +pyenv install 3.10.0 +pyenv global 3.10.0 +pyenv local 3.10 + +# Install Poetry +curl -sSL https://install.python-poetry.org | python3 - +export PATH="$HOME/.local/bin:$PATH" + +# Initialize Poetry environment +poetry shell #source /workspaces/darwin-py/.venv/bin/activate +poetry install + +# Install additional Python dependencies +pip install darwin-py[test] +pip install darwin-py[ml] + +# Authenticate and verify Darwin CLI +pip install connected-components-3d + +# FFmpeg +FFMPEG_VERSION="6.0" # Ensure this is version 5 or higher +mkdir -p $HOME/.local/bin +echo "Downloading FFmpeg $FFMPEG_VERSION..." +cd $HOME/.local/bin +wget -O ffmpeg.tar.xz "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" +tar -xf ffmpeg.tar.xz --strip-components=1 +rm ffmpeg.tar.xz +echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc +export PATH="$HOME/.local/bin:$PATH" +cd - + +#Run tests to verify all is good +pytest +echo "Setup complete!" \ No newline at end of file From 0af56ecda63cbd495a2f7839e847fa3890197f8c Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Fri, 31 Jan 2025 16:53:16 +0000 Subject: [PATCH 2/4] Update development container setup script to improve dependency installation and configuration --- .devcontainer/setup.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 053152e5a..6e40f19fe 100644 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -1,22 +1,25 @@ #!/bin/bash + set -e # Exit on error # Update and install dependencies -sudo apt update +sudo apt update -y +sudo apt upgrade -y +sudo apt-get install -y python3-openssl sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \ - wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git + wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git # Install pyenv curl https://pyenv.run | bash # Add pyenv to shell profile -echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc -echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc -echo 'eval "$(pyenv init --path)"' >> ~/.bashrc -echo 'eval "$(pyenv init -)"' >> ~/.bashrc +echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile +echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile +echo 'eval "$(pyenv init --path)"' >> ~/.profile +echo 'eval "$(pyenv init -)"' >> ~/.profile # Apply changes -source ~/.bashrc +source ~/.profile # Install Python 3.10 using pyenv pyenv install 3.10.0 @@ -28,15 +31,16 @@ curl -sSL https://install.python-poetry.org | python3 - export PATH="$HOME/.local/bin:$PATH" # Initialize Poetry environment -poetry shell #source /workspaces/darwin-py/.venv/bin/activate +source /workspaces/darwin-py/.venv/bin/activate #poetry shell poetry install # Install additional Python dependencies pip install darwin-py[test] pip install darwin-py[ml] +pip install darwin-py[ocv] -# Authenticate and verify Darwin CLI pip install connected-components-3d +pip install nibabel # FFmpeg FFMPEG_VERSION="6.0" # Ensure this is version 5 or higher @@ -52,4 +56,5 @@ cd - #Run tests to verify all is good pytest + echo "Setup complete!" \ No newline at end of file From 404b2b1b2b0a9bc3c43f636d1a9d132fe197a278 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Mon, 3 Feb 2025 14:32:51 +0000 Subject: [PATCH 3/4] Refactor development container setup to use in-project virtual environments and update documentation for clarity --- .devcontainer/setup.sh | 14 +++++--------- docs/DEV.md | 15 ++++++++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 6e40f19fe..57fd5dc1d 100644 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -31,16 +31,12 @@ curl -sSL https://install.python-poetry.org | python3 - export PATH="$HOME/.local/bin:$PATH" # Initialize Poetry environment -source /workspaces/darwin-py/.venv/bin/activate #poetry shell -poetry install +PROJECT_DIR="$(pwd)" +export VENV_PATH="$PROJECT_DIR/.venv" +poetry config virtualenvs.in-project true -# Install additional Python dependencies -pip install darwin-py[test] -pip install darwin-py[ml] -pip install darwin-py[ocv] - -pip install connected-components-3d -pip install nibabel +poetry install --all-extras +source "$VENV_PATH/bin/activate" #poetry shell # FFmpeg FFMPEG_VERSION="6.0" # Ensure this is version 5 or higher diff --git a/docs/DEV.md b/docs/DEV.md index 6dc4d239f..85b655b20 100644 --- a/docs/DEV.md +++ b/docs/DEV.md @@ -1,18 +1,23 @@ # Development Environment This doesn't represent the only way to develop on darwin-py, but does represent an easy and configurable way to manage things like underlying dependencies and python versions -## Shell environment +## Devcontainer - One click approach +Just use the devcontainer config, either in Github codespaces or in using the [VSCode extension](https://code.visualstudio.com/docs/devcontainers/tutorial). +NB the config is [here](../.devcontainer/devcontainer.json) + +## Manual setup +### Shell environment No requirement for any particular shell, [zsh](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH) + [oh my zsh](https://ohmyz.sh/) is a good setup commonly used, but whatever environment you use make sure to install the recommended alias's and path exports that the below systems require for your particular shell environment, particularly pertinent for poetry which has an added step that it prints to console but isn't included on the webpage. -## Pyenv +### Pyenv Pyenv manages system python versions, install instructions can be found [here](https://github.com/pyenv/pyenv). After installation of pyenv, install a python version that is compatible with darwin-py (3.9-3.12 as of writing) `pyenv install 3.10` If the command `pyenv` isn't recognized, it hasn't installed to your shell environemnt config file correctly .zshrc .bashrc etc. -## Poetry +### Poetry Poetry manages project level dependencies and local python versions. Install instructions [here](https://python-poetry.org/docs/). Make sure to follow the printed instructions and add the path to your shell environment, if running the command `poetry --version` after installation doesn't work, it means your path hasn't been updated -## New Folder Setup +### New Folder Setup To Start from scratch and get a development/QA environemnt setup. This process means you will have a fresh python version with only the dependencies required by darwin-py that is uncorrupted by other packages installed on the system python - clone darwin py repo - navigate to downloaded repo @@ -22,7 +27,7 @@ To Start from scratch and get a development/QA environemnt setup. This process m Pyenv + Poetry here get used in conjuction, with pyenv telling the system whenever `python` is called in a folder that has been set with `pyenv local ` that it should use that local version. Poetry is then set to prefer that local version of python, and to create a per project copy of python to use, it will clone `` into a .venv folder locally, and install dependencies there. If new environment is required, run `rm -rf .venv` while inside the project folder, set a new pyenv version if needed and re-run poetry commands -## Subsequent Uses +### Subsequent Uses Once a folder is setup, it can easily be reused - navigate to folder - run `poetry shell` From 8fd91d3eb2056adf04d5f9379958f01816e46d85 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Mon, 3 Feb 2025 14:40:28 +0000 Subject: [PATCH 4/4] better readme --- docs/DEV.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/DEV.md b/docs/DEV.md index 85b655b20..601b8a309 100644 --- a/docs/DEV.md +++ b/docs/DEV.md @@ -2,8 +2,10 @@ This doesn't represent the only way to develop on darwin-py, but does represent an easy and configurable way to manage things like underlying dependencies and python versions ## Devcontainer - One click approach Just use the devcontainer config, either in Github codespaces or in using the [VSCode extension](https://code.visualstudio.com/docs/devcontainers/tutorial). + NB the config is [here](../.devcontainer/devcontainer.json) +Remember to activate the _venv_ after the container boots `source .venv/bin/activate` ## Manual setup ### Shell environment No requirement for any particular shell, [zsh](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH) + [oh my zsh](https://ohmyz.sh/) is a good setup commonly used, but whatever environment you use make sure to install the recommended alias's and path exports that the below systems require for your particular shell environment, particularly pertinent for poetry which has an added step that it prints to console but isn't included on the webpage.