Skip to content

Commit 95be22c

Browse files
include partial+full guide for custom pacakges (#122)
* include partial+full manuals * shorten manuals * apply revisions * shorten partial * include suggestions --------- Co-authored-by: Jelle Treep <h.j.treep@uu.nl>
1 parent 6d44922 commit 95be22c

4 files changed

Lines changed: 355 additions & 0 deletions

File tree

_quarto.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
project:
22
type: website
33
output-dir: ./_html
4+
title: "VRE documentation for UU research"
45

56
website:
67
navbar:

docs/imgs/custom-packages.png

139 KB
Loading
Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
---
2+
title: "Pre-installing Python, R and Julia packages on workspaces"
3+
---
4+
5+
## Overview
6+
7+
Certain SURF Research Cloud workspaces allow you to automatically install project dependencies by filling out the URL or DOI of your project during workspace creation.
8+
9+
**Key features:**
10+
11+
- Automatically clones projects from GitHub, GitLab, Zenodo, Dataverse, or DOI links
12+
- Installs dependencies in separate environments (one per project)
13+
- Supports Python, R, Julia, and Conda projects
14+
- Creates a Jupyter kernel when installation succeeds
15+
16+
**Workspaces**
17+
18+
- VRE lab
19+
- VRE lab GPU
20+
21+
## How It Works
22+
23+
## 1. Enabling During Workspace Creation
24+
25+
**Step 1: Select Custom Packages UU**
26+
27+
During workspace creation, select the **"Custom Packages UU"** option under the Optional Components section. Also select Python tools when creating a worksapce with Custom Packages UU.
28+
29+
![Custom Packages UU](../imgs/custom-packages.png){width=400px}
30+
31+
**Step 2: Provide Project Identifiers**
32+
33+
In the "Projects to pre-install" field, enter a comma-separated list of project identifiers.
34+
35+
Accepted formats: GitHub URLs, GitLab URLs, Zenodo URLs, Dataverse URLs, DOIs (must point to a repository)
36+
37+
You can test with setting up python environments using the [`src-python-example repository`](https://github.com/UtrechtUniversity/src-python-example.git). Copy this URL (<https://github.com/UtrechtUniversity/src-python-example.git>) into the "Projects to pre-install" field and proceed to create your workspace.
38+
39+
**Step 3: Continue Workspace Creation**
40+
41+
Continue with workspace creation as normal. The build process may take longer as it installs dependencies, but your environment will be ready when the workspace starts.
42+
43+
## 2. After Workspace Creation
44+
45+
**First Terminal Login**
46+
47+
When you open a terminal for the first time after workspace creation, you may see messages like:
48+
```
49+
Running install scripts at first login: executing /home/username/..._conda.sh
50+
```
51+
52+
This is normal. The workspace is running first-time setup scripts, including initializing conda (***if applicable***). Wait for these scripts to complete before running commands. Subsequent terminal sessions will not run these scripts again and start immediately.
53+
54+
### Finding Your Projects and Environments
55+
56+
57+
#### Projects Location
58+
Projects are located in:
59+
```bash
60+
~/local-share/projects/
61+
```
62+
63+
Each project is in its own directory:
64+
```bash
65+
~/local-share/projects/{project-name}/
66+
```
67+
68+
::: {.callout-warning}
69+
Please note that the `local-share` folder is not located on a persistent storage volume, which means data in this folder will be deleted when the workspace is deleted. Make sure to push changes to GitHub regularly, or move any files to a persistent storage volume if you want to keep them.
70+
:::
71+
72+
::: {.panel-tabset}
73+
74+
## Conda Environments
75+
76+
Location: `/usr/local/uu/env/conda/{project-name}`
77+
78+
To see what's available:
79+
```bash
80+
# List conda environments
81+
conda env list
82+
```
83+
84+
## uv/venv Environments
85+
86+
Location: `/usr/local/uu/env/python/{project-name}`
87+
88+
To see what's available:
89+
```bash
90+
# List Python/uv environments
91+
ls /usr/local/uu/env/python/
92+
```
93+
:::
94+
95+
## 3. Using Your Environments
96+
97+
### Activating an Environment
98+
The activation command differs based on the environment type:
99+
100+
::: {.panel-tabset}
101+
102+
## Conda Environments
103+
104+
```bash
105+
# Activate
106+
conda activate /usr/local/uu/env/conda/{project-name}
107+
108+
# Example (for environment.yml in [`src-python-example repository`](https://github.com/UtrechtUniversity/src-python-example.git))
109+
conda activate /usr/local/uu/env/conda/src-python-example
110+
111+
# Deactivate
112+
conda deactivate
113+
```
114+
115+
## uv/venv environments:
116+
117+
```bash
118+
# Activate
119+
source /usr/local/uu/env/python/{project-name}/bin/activate
120+
121+
# Example (for [`src-python-example repository`](https://github.com/UtrechtUniversity/src-python-example.git))
122+
source /usr/local/uu/env/python/src-python-example/bin/activate
123+
124+
# Deactivate
125+
deactivate
126+
```
127+
:::
128+
129+
Once activated, you can run Python scripts using the environment's packages, install additional packages and work with the project files.
130+
131+
## 4. Using Environments in Jupyter Notebooks
132+
133+
134+
If the kernel was created automatically, select it from the kernel dropdown in the JupyterLab interface (top right).
135+
136+
**Manual Kernel creation**
137+
138+
If the kernel wasn't created automatically (due to dependency installation issues), you can create it manually using the terminal:
139+
140+
::: {.panel-tabset}
141+
142+
## Conda Environments
143+
```bash
144+
# Activate your environment
145+
conda activate /usr/local/uu/env/conda/{project-name}
146+
147+
# Register as Jupyter kernel
148+
python -m ipykernel install --user --name {project-name} --display-name "Python ({project-name})"
149+
150+
# Verify registration
151+
jupyter kernelspec list
152+
```
153+
154+
## For uv/venv environments:
155+
```bash
156+
# Activate your environment
157+
source /usr/local/uu/env/python/{project-name}/bin/activate
158+
159+
# Register as Jupyter kernel
160+
python -m ipykernel install --user --name {project-name} --display-name "Python ({project-name})"
161+
162+
# Verify registration
163+
jupyter kernelspec list
164+
```
165+
:::
166+
167+
After this, refresh your JupyterLab page and the kernel should appear in the kernel selector.
168+
169+
## 5. Installing Additional Packages
170+
171+
You can install more packages into your environment after creation.
172+
173+
If you are installing new packages, update your Jupyter kernel so your notebooks can access them either by manually re-registering the kernel (see above) or refreshing the JupyterLab page.
174+
175+
::: {.panel-tabset}
176+
177+
## Conda Environments
178+
179+
```bash
180+
# Activate environment
181+
conda activate /usr/local/uu/env/conda/{project-name}
182+
183+
# Install packages
184+
conda install package-name
185+
186+
# Or use pip
187+
pip install package-name
188+
```
189+
190+
::: {.callout-tip}
191+
When using both conda and pip in a conda environment, install conda packages first, then pip packages. This helps avoid dependency conflicts.
192+
:::
193+
194+
## uv/venv Environments
195+
196+
```bash
197+
# Activate environment
198+
source /usr/local/uu/env/python/{project-name}/bin/activate
199+
200+
# Install packages with pip
201+
pip install package-name
202+
```
203+
:::
204+
205+
## 6. How Dependencies Are Resolved
206+
207+
Dependency files in your project repository are automatically detected and the appropriate environment manager will be selected:
208+
209+
::: {.panel-tabset}
210+
211+
## Python Projects
212+
213+
**Priority order:**
214+
215+
1. `environment.yml`: Creates conda environment at `/usr/local/uu/env/conda/{name}`
216+
2. `pyproject.toml` or `requirements.txt`: Creates Python/uv environment at `/usr/local/uu/env/python/{name}`
217+
3. `uv.lock`: Uses uv with lockfile
218+
219+
## R Projects
220+
221+
- `renv.lock`: R environment lock file
222+
- `DESCRIPTION`: R package description file
223+
224+
## Julia Project
225+
226+
- `Project.toml`: Julia project file
227+
228+
## Conda Projects
229+
230+
- `environment.yml`: Conda environment specification
231+
:::
232+
233+
::: {.callout-note}
234+
If a project has `environment.yml`, it will use conda regardless of other files present. If no `environment.yml` but has `pyproject.toml` or `requirements.txt`, it will use Python/uv.
235+
:::
236+
237+
## 7. Checking Installation Logs
238+
239+
If something went wrong during installation, you can check the logs:
240+
241+
```bash
242+
cd ~/local-share/projects/{project-name}/
243+
cat repo2kernel.log
244+
```
245+
246+
This log file shows:
247+
248+
- Which dependency files were detected
249+
- What commands were run
250+
- Whether conda or uv was used
251+
- Any errors that occurred
252+
253+
## Troubleshooting
254+
::: {.callout-note collapse="true"}
255+
## 1. Environment Created But Kernel Not Available
256+
257+
Environment exists but doesn't appear in Jupyter kernel list. Then you can register the kernel manually see [Manual Kernel Registration](#using-environments-in-jupyter-notebooks) above.
258+
:::
259+
260+
::: {.callout-note collapse="true"}
261+
## 2. Dependency Installation Failed
262+
263+
Log shows errors during package installation. Then you can:
264+
265+
- Check `repo2kernel.log` for specific errors
266+
- Activate the environment manually
267+
- Try installing failed packages individually:
268+
269+
::: {.panel-tabset}
270+
271+
## Conda environments:
272+
```bash
273+
conda activate /usr/local/uu/env/conda/{project-name}
274+
conda install failed-package-name
275+
```
276+
277+
## uv/venv environments:
278+
```bash
279+
source /usr/local/uu/env/python/{project-name}/bin/activate
280+
pip install failed-package-name
281+
```
282+
:::
283+
:::
284+
285+
::: {.callout-note collapse="true"}
286+
287+
## 4. Cannot Activate Conda Environment
288+
289+
`conda activate` command doesn't work. Then you can:
290+
291+
Initialize conda in your shell:
292+
```bash
293+
conda init bash
294+
# Then close and reopen your terminal
295+
```
296+
297+
Try the full path:
298+
```bash
299+
conda activate /usr/local/uu/env/conda/{project-name}
300+
```
301+
:::
302+
303+
::: {.callout-note collapse="true"}
304+
## 5. Don't Know Which Environment Type Was Created
305+
306+
Not sure if your project created a conda or Python/uv environment, then:
307+
308+
Check both locations:
309+
```bash
310+
# Check conda
311+
conda env list
312+
313+
# Check Python/uv
314+
ls /usr/local/uu/env/python/
315+
316+
# Check the log
317+
cat ~/local-share/projects/{project-name}/repo2kernel.log
318+
```
319+
320+
The log shows which commands were run (conda or uv).
321+
:::
322+
323+
## Tips
324+
325+
To learn more about dependencies, virtual environments, git and GitHub, consider following the [Best Practices for Writing Reproducible code workshop](https://www.uu.nl/en/research/research-data-management/training-workshops/best-practices-for-writing-reproducible-code)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Pre-installing Python, R and Julia packages during workspace creation
2+
3+
#### Setup
4+
5+
1. Check **"Custom Packages UU"** in Optional Components when creating your workspace
6+
2. In the "Projects to pre-install" field, enter your project identifiers as URLs or DOIs (pointing to repositories) separated by commas
7+
3. Wait for workspace to build (may take longer with many dependencies)
8+
4. Projects are cloned to `~/local-share/projects/` and environments are created automatically based on the dependency files
9+
10+
::: {.callout-important}
11+
The project you wish to install must contain valid dependency files (`environment.yml`, `requirements.txt`, `pyproject.toml`, etc.) for automatic installation to work.
12+
:::
13+
14+
After workspace creation, select the Jupyter kernel for your project, or activate the environment in the terminal via:
15+
16+
::: {.panel-tabset}
17+
18+
## conda
19+
```bash
20+
conda activate /usr/local/uu/env/conda/{project-name}
21+
```
22+
## Python/uv
23+
```bash
24+
source /usr/local/uu/env/python/{project-name}/bin/activate
25+
```
26+
:::
27+
28+
For detailed instructions on using and modifying these environments, see the detailed [Custom Packages Manual](../../manuals/custom-packages-manual.qmd).
29+

0 commit comments

Comments
 (0)