Skip to content

Commit 9750b00

Browse files
authored
Merge pull request #227 from DoubleML/dev
Update `main` according to latest changes on `dev`
2 parents 5f7344d + 291d6a2 commit 9750b00

File tree

94 files changed

+17012
-986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+17012
-986
lines changed

.devcontainer/Dockerfile.dev

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ RUN apt-get update && \
1414
apt-transport-https \
1515
ca-certificates \
1616
git \
17-
cmake
18-
19-
# Install locale packages
20-
RUN apt-get update && \
21-
apt-get install -y locales && \
17+
cmake \
18+
locales && \
2219
locale-gen en_US.UTF-8 && \
23-
update-locale LANG=en_US.UTF-8
20+
update-locale LANG=en_US.UTF-8 && \
21+
apt-get clean && \
22+
rm -rf /var/lib/apt/lists/*
2423

2524
# Set environment variables for locale
2625
ENV LANG=en_US.UTF-8
@@ -31,37 +30,43 @@ ENV LC_ALL=en_US.UTF-8
3130
RUN add-apt-repository ppa:deadsnakes/ppa && \
3231
apt-get update && \
3332
apt-get install -y python3.12 python3.12-venv python3.12-dev python3-pip python3-full && \
34-
apt-get clean && rm -rf /var/lib/apt/lists/*
35-
36-
# Set Python 3.12 as the default for both python and python3
37-
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
38-
update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
33+
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
34+
update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \
35+
apt-get clean && \
36+
rm -rf /var/lib/apt/lists/*
3937

4038
# Add R repository and install R
4139
RUN wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc && \
4240
add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/' && \
4341
apt-get update && \
44-
apt-get install -y r-base r-base-dev zlib1g-dev libicu-dev pandoc make libcurl4-openssl-dev libssl-dev
42+
apt-get install -y r-base r-base-dev zlib1g-dev libicu-dev pandoc make libcurl4-openssl-dev libssl-dev && \
43+
apt-get clean && \
44+
rm -rf /var/lib/apt/lists/*
4545

46-
# Install Python packages
47-
COPY requirements.txt /tmp/requirements.txt
48-
RUN python -m venv /opt/venv && \
49-
/opt/venv/bin/python -m pip install --upgrade pip && \
50-
/opt/venv/bin/pip install -r /tmp/requirements.txt
51-
52-
# Set the virtual environment as the default Python environment
53-
ENV PATH="/opt/venv/bin:$PATH"
46+
# Reuse existing 'ubuntu' user (UID 1000)
47+
ARG USERNAME=ubuntu
5448

55-
# Check out the repo containing the Python package DoubleML (dev)
56-
RUN git clone https://github.com/DoubleML/doubleml-for-py.git /doubleml-for-py
57-
WORKDIR /doubleml-for-py
58-
RUN /opt/venv/bin/pip uninstall -y DoubleML && \
59-
/opt/venv/bin/pip install -e .[rdd]
49+
RUN mkdir -p /workspace && \
50+
chown -R $USERNAME:$USERNAME /workspace
6051

61-
# Create a directory for R user libraries and set the default R user library path
62-
RUN mkdir -p /usr/local/lib/R/site-library
52+
# Create a directory for R user libraries
53+
RUN mkdir -p /usr/local/lib/R/site-library && \
54+
chown -R $USERNAME:$USERNAME /usr/local/lib/R/site-library
6355
ENV R_LIBS_USER=/usr/local/lib/R/site-library
6456

57+
# Switch to non-root user for remaining operations
58+
USER $USERNAME
59+
60+
# Install Python packages in the virtual environment
61+
COPY --chown=$USERNAME:$USERNAME requirements.txt /tmp/requirements.txt
62+
RUN python -m venv /home/$USERNAME/.venv && \
63+
/home/$USERNAME/.venv/bin/python -m pip install --upgrade pip && \
64+
/home/$USERNAME/.venv/bin/pip install --no-cache-dir -r /tmp/requirements.txt && \
65+
/home/$USERNAME/.venv/bin/pip install --no-cache-dir git+https://github.com/DoubleML/doubleml-for-py.git@main#egg=DoubleML[rdd]
66+
67+
# Set the virtual environment as the default Python environment
68+
ENV PATH="/home/$USERNAME/.venv/bin:$PATH"
69+
6570
# Install R packages and Jupyter kernel
6671
RUN Rscript -e "install.packages('remotes')" && \
6772
Rscript -e "remotes::install_github('DoubleML/doubleml-for-r', dependencies = TRUE)" && \
@@ -70,4 +75,3 @@ RUN Rscript -e "install.packages('remotes')" && \
7075

7176
# Set the working directory
7277
WORKDIR /workspace
73-

.devcontainer/build_image_guide.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Building and Publishing the Docker Image
2+
3+
This guide shows how to build the DoubleML documentation development container locally and publish it to Docker Hub.
4+
5+
## Prerequisites
6+
7+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running
8+
- Access to the `svenklaassen` [Docker Hub](https://www.docker.com/products/docker-hub/) account
9+
- [doubleml-docs](https://github.com/DoubleML/doubleml-docs) repository cloned to your local machine
10+
11+
## Step 1: Login to Docker Hub
12+
13+
Open a terminal and login to Docker Hub:
14+
15+
```bash
16+
docker login
17+
```
18+
19+
Enter the Docker Hub username (`svenklaassen`) and password (or token) when prompted.
20+
21+
## Step 2: Build the Docker Image
22+
23+
Navigate to your project root directory and build the image (using the `latest`-tag):
24+
25+
```bash
26+
docker build -t svenklaassen/doubleml-docs:latest -f .devcontainer/Dockerfile.dev .
27+
```
28+
29+
To force a complete rebuild without using cache:
30+
31+
```bash
32+
docker build --no-cache -t svenklaassen/doubleml-docs:latest -f .devcontainer/Dockerfile.dev .
33+
```
34+
35+
## Step 3 (Optional): Verify the image
36+
37+
### Open the repository in VS Code
38+
39+
1. Ensure your `.devcontainer/devcontainer.json` is configured to use your local image:
40+
41+
```json
42+
"image": "svenklaassen/doubleml-docs:latest"
43+
```
44+
Note: The `.devcontainer/devcontainer.json` file is configured to use the pre-built image. If you want to build the container from scratch, uncomment the `dockerFile` and `context` lines and comment out the `image` line.
45+
46+
2. Open the `doubleml-docs` repository in VS Code:
47+
48+
```bash
49+
code /path/to/doubleml-docs
50+
```
51+
52+
3. Open the Command Palette (`Ctrl+Shift+P`) and select `Dev Containers: Reopen in Container`.
53+
VS Code will use your locally built image.
54+
55+
### Build the documentation
56+
57+
Once inside the container, verify that you can successfully build the documentation:
58+
59+
1. Open a terminal in VS Code (`Terminal > New Terminal`)
60+
61+
2. Build the documentation:
62+
63+
```bash
64+
cd doc
65+
make html
66+
```
67+
68+
3. Check the output for any errors or warnings
69+
70+
4. View the built documentation by opening the output files:
71+
72+
```bash
73+
# On Windows
74+
explorer.exe _build/html
75+
76+
# On Linux
77+
xdg-open _build/html
78+
79+
# On macOS
80+
open _build/html
81+
```
82+
83+
If the documentation builds successfully and looks correct, your Docker image is working properly and ready to be pushed to Docker Hub.
84+
85+
## Step 4: Push to Docker Hub
86+
87+
Push your built image to Docker Hub:
88+
89+
```bash
90+
docker push svenklaassen/doubleml-docs:latest
91+
```
92+
93+
## Step 5: Using the Published Image
94+
95+
After publishing, there are two ways to use the image:
96+
97+
### Option 1: Manual Container Management
98+
Pull and run the container manually:
99+
100+
```bash
101+
docker pull svenklaassen/doubleml-docs:latest
102+
# Then run commands to create a container from this image
103+
```
104+
105+
### Option 2: VS Code Integration (Recommended)
106+
Simply reference the image in your `devcontainer.json` file:
107+
108+
```json
109+
"image": "svenklaassen/doubleml-docs:latest"
110+
```
111+
112+
VS Code will automatically pull the image when opening the project in a container - no separate `docker pull` command needed.
113+
114+
## Troubleshooting
115+
116+
### Clear Docker Cache
117+
118+
If you're experiencing issues with cached layers:
119+
120+
```bash
121+
# Remove build cache
122+
docker builder prune
123+
124+
# For a more thorough cleanup
125+
docker system prune -a
126+
```
127+
128+
### Check Image Size
129+
130+
To verify the image size before pushing:
131+
132+
```bash
133+
docker images svenklaassen/doubleml-docs
134+
```

.devcontainer/devcontainer.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "DoubleML Documentation Development",
3-
"dockerFile": "Dockerfile.dev", // Path to your Dockerfile
4-
"context": "..", // Context for the build (root of your project)
3+
"image": "svenklaassen/doubleml-docs:latest",
4+
// "dockerFile": "Dockerfile.dev",
5+
// "context": "..",
56
"workspaceFolder": "/workspace", // Folder inside the container for your project
67
// Customizations for VS Code
78
"customizations": {
@@ -12,23 +13,27 @@
1213
"njpwerner.autodocstring", // Optional: Auto-generate docstrings
1314
"ms-python.black-formatter", // Optional: Black formatter
1415
"streetsidesoftware.code-spell-checker", // Optional: Spell checker
15-
"github.copilot" // Add GitHub Copilot extension
16+
"github.copilot", // Add GitHub Copilot extension
1617
"GitHub.github-vscode-theme", // GitHub theme
17-
"github.vscode-github-actions" // GitHub Actions extension
18+
"github.vscode-github-actions", // GitHub Actions extension
1819
"ms-toolsai.jupyter", // Jupyter extension
1920
"charliermarsh.ruff" // Ruff extension
2021
],
2122
"settings": {
22-
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python", // Poetry virtual environment path
23+
"python.defaultInterpreterPath": "/home/ubuntu/.venv/bin/python",
2324
"editor.formatOnSave": true, // Auto-format code when saving
2425
"editor.codeActionsOnSave": {
2526
"source.organizeImports": true // Auto-organize imports on save
2627
},
2728
"python.linting.enabled": true, // Enable linting
2829
"python.linting.flake8Enabled": false, // Disable Flake8 for linting
2930
"python.linting.ruffEnabled": true, // Enable Ruff for linting
30-
"python.formatting.provider": "black", // Use Black for formatting
31-
"python.testing.pytestEnabled": false, // Enable Pytest for testing
31+
"python.formatting.provider": "none",
32+
"[python]": {
33+
"editor.defaultFormatter": "ms-python.black-formatter",
34+
"editor.formatOnSave": true
35+
},
36+
"python.testing.pytestEnabled": true, // Enable Pytest for testing
3237
"python.testing.pytestArgs": [],
3338
"python.testing.unittestEnabled": false,
3439
"files.exclude": {
@@ -40,7 +45,8 @@
4045
}
4146
},
4247
"mounts": [
43-
"source=${localWorkspaceFolder},target=/workspace,type=bind" // Mount your local workspace into the container
48+
"source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached" // Mount your local workspace into the container
4449
],
45-
"remoteUser": "root" // Set the user inside the container
50+
"remoteUser": "ubuntu",
51+
"postCreateCommand": "id && ls -la /workspace && echo 'Container is ready!'"
4652
}

.devcontainer/docker_guide.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Build Documentation with Development Container
2+
3+
This guide shows how to use WSL2 (Windows Subsystem for Linux), Docker Desktop, Visual Studio Code (VS Code), and how to work with Development Containers in VS Code on a Windows machine.
4+
5+
Requirements:
6+
- [VS Code](https://code.visualstudio.com/)
7+
- [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install)
8+
- [Docker Desktop](https://docs.docker.com/desktop/setup/install/windows-install/)
9+
10+
## Step 1: Verify installations & Setup
11+
12+
You can verify the installations in a terminal:
13+
14+
```bash
15+
code --version
16+
wsl --version
17+
docker --version
18+
```
19+
20+
### Configure Docker to Use WSL2
21+
22+
See [Docker Desktop Documentation](https://docs.docker.com/desktop/features/wsl/#turn-on-docker-desktop-wsl-2).
23+
1. Open Docker Desktop.
24+
2. Go to **Settings > General** and make sure **Use the WSL 2 based engine** is checked.
25+
3. Under **Settings > Resources > WSL Integration**, ensure that your desired Linux distribution(s) are selected for integration with Docker.
26+
27+
### Install Extensions
28+
29+
1. Open Visual Studio Code.
30+
2. Press `Ctrl+Shift+X` to open the Extensions view.
31+
3. Search and install (includes WSL and Dev Containers Extensions):
32+
- [Remote Development Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)
33+
34+
Helpful VS Code Documentations:
35+
- [Developing in WSL](https://code.visualstudio.com/docs/remote/wsl)
36+
- [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers)
37+
38+
39+
## Step 2: Open the Development Container (Using Pre-built Image)
40+
41+
For faster setup, we'll use a pre-built Docker image:
42+
43+
1. Open the `doubleml-docs` repository in VS Code:
44+
45+
```bash
46+
code /path/to/doubleml-docs
47+
```
48+
49+
2. Open the Command Palette (`Ctrl+Shift+P`).
50+
3. Type `Dev Containers: Reopen in Container`.
51+
52+
VS Code will pull the `svenklaassen/doubleml-docs:latest` image (if needed) based on `devcontainer.json` and open the project in the container.<br>
53+
This approach is much faster than building the container from scratch. VS Code automatically downloads the image from Docker Hub if it's not already on your system.
54+
55+
56+
## Step 3: Build the documentation
57+
58+
1. Open a terminal in VS Code (`Terminal > New Terminal`)
59+
60+
2. Build the documentation:
61+
62+
```bash
63+
cd doc
64+
make html
65+
```
66+
67+
To build without notebook examples:
68+
```bash
69+
make html NBSPHINX_EXECUTE=never
70+
```
71+
72+
3. View the built documentation by opening the output files:
73+
74+
```bash
75+
# On Windows
76+
explorer.exe _build/html
77+
78+
# On Linux
79+
xdg-open _build/html
80+
81+
# On macOS
82+
open _build/html
83+
```

0 commit comments

Comments
 (0)