Skip to content

Commit 69c1403

Browse files
authored
Test for homebrew, conda in codespaces and poetry (#63)
Tests for #53 Fixes #66 with tests for it.
1 parent b40789a commit 69c1403

File tree

18 files changed

+786
-70
lines changed

18 files changed

+786
-70
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM homebrew/brew
2+
3+
RUN sh -c "$(curl -fsSL https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
4+
-t powerlevel10k/powerlevel10k \
5+
-p git \
6+
-p git-extras \
7+
-p https://github.com/zsh-users/zsh-completions
8+
RUN git clone https://github.com/romkatv/powerlevel10k $HOME/.oh-my-zsh/custom/themes/powerlevel10k
9+
RUN curl https://raw.githubusercontent.com/DonJayamanne/vscode-jupyter/containerChanges/.devcontainer/.p10k.zsh > ~/.p10k.zsh
10+
RUN echo "# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh." >> ~/.zshrc
11+
RUN echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> ~/.zshrc
12+
13+
# Install Pythone
14+
15+
16+
# Install Rust
17+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
18+
RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc
19+
ENV PATH="/root/.cargo/bin:${PATH}"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "linux-homebrew",
3+
"build": {
4+
"context": "../..",
5+
"dockerfile": "./Dockerfile"
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"ms-python.python@prerelease",
11+
"esbenp.prettier-vscode",
12+
"rust-lang.rust-analyzer",
13+
"EditorConfig.EditorConfig"
14+
]
15+
}
16+
},
17+
"workspaceFolder": "/workspaces/python-environment-tools"
18+
}

.github/workflows/pr-check.yml

Lines changed: 213 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@ name: PR/CI Check
22

33
on:
44
pull_request:
5+
branches:
6+
- main
7+
- release*
8+
- release/*
9+
- release-*
510
push:
6-
branches-ignore:
11+
branches:
712
- main
813
- release*
914
- release/*
1015
- release-*
1116

1217
jobs:
1318
tests:
19+
# Very generic tests, we don't verify whether the envs are discovered correctly or not.
20+
# However we do ensure that envs that are discovered are valid.
21+
# See other jobs for specific tests.
1422
name: Tests
1523
runs-on: ${{ matrix.os }}
1624
strategy:
@@ -26,20 +34,12 @@ jobs:
2634
- os: ubuntu-latest
2735
target: x86_64-unknown-linux-musl
2836
run_cli: "yes"
29-
# - os: ubuntu-latest
30-
# target: aarch64-unknown-linux-gnu
31-
# - os: ubuntu-latest
32-
# target: arm-unknown-linux-gnueabihf
3337
- os: macos-latest
3438
target: x86_64-apple-darwin
3539
run_cli: "yes"
3640
- os: macos-14
3741
target: aarch64-apple-darwin
3842
run_cli: "yes"
39-
# - os: ubuntu-latest
40-
# target: x86_64-unknown-linux-gnu
41-
# - os: ubuntu-latest
42-
# target: aarch64-unknown-linux-musl
4343
steps:
4444
- name: Checkout
4545
uses: actions/checkout@v4
@@ -151,6 +151,22 @@ jobs:
151151
pyenv virtualenv 3.12 pyenv-virtualenv-env1
152152
shell: bash
153153

154+
# region venv
155+
- name: Create .venv
156+
# if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos')
157+
run: |
158+
python -m venv .venv
159+
shell: bash
160+
161+
- name: Create .venv2
162+
# if: startsWith( matrix.os, 'ubuntu') || startsWith( matrix.os, 'macos')
163+
run: |
164+
python -m venv .venv2
165+
shell: bash
166+
167+
# endregion venv
168+
169+
# Rust
154170
- name: Rust Tool Chain setup
155171
uses: dtolnay/rust-toolchain@stable
156172
with:
@@ -167,7 +183,194 @@ jobs:
167183
shell: bash
168184

169185
- name: Run Tests
170-
run: cargo test --frozen --all-features -- --nocapture
186+
# Run integration tests in a single thread,
187+
# We end up creating conda envs and running multiple tests in parallel
188+
# that creat conda envs simultaneously causes issues (sometimes the conda envs do not seem to get created)
189+
# Similar issues were identified in vscode-jupyter tests as well (something to do with conda lock files or the like)
190+
run: cargo test --frozen --features ci -- --nocapture --test-threads=1
191+
env:
192+
RUST_BACKTRACE: 1
193+
RUST_LOG: trace
194+
shell: bash
195+
196+
isolated-tests:
197+
# Some of these tests are very specific and need to be run in isolation.
198+
# E.g. we need to ensure we have a poetry project setup correctly (without .venv created using `pip -m venv .venv`).
199+
# We can try to use the previous `tests` job, but that gets very complicated.
200+
name: Other Tests
201+
runs-on: ${{ matrix.os }}
202+
strategy:
203+
fail-fast: false
204+
matrix:
205+
include:
206+
- feature: ci-poetry-global
207+
os: ubuntu-latest
208+
target: x86_64-unknown-linux-musl
209+
- feature: ci-poetry-project
210+
os: ubuntu-latest
211+
target: x86_64-unknown-linux-musl
212+
- feature: ci-poetry-custom
213+
os: ubuntu-latest
214+
target: x86_64-unknown-linux-musl
215+
steps:
216+
- name: Checkout
217+
uses: actions/checkout@v4
218+
219+
# Setup Poetry
220+
- name: Set Python 3.x to PATH
221+
if: startsWith( matrix.feature, 'ci-poetry')
222+
uses: actions/setup-python@v5
223+
with:
224+
python-version: "3.x"
225+
226+
- name: Set Python 3.12 to PATH
227+
if: startsWith( matrix.feature, 'ci-poetry')
228+
uses: actions/setup-python@v5
229+
with:
230+
python-version: "3.12"
231+
232+
- name: Set Python 3.11 to PATH
233+
if: startsWith( matrix.feature, 'ci-poetry')
234+
uses: actions/setup-python@v5
235+
with:
236+
python-version: "3.11"
237+
238+
- name: Install Poetry (envs globally)
239+
if: startsWith( matrix.feature, 'ci-poetry-global')
240+
uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b
241+
with:
242+
virtualenvs-create: true
243+
virtualenvs-in-project: false
244+
installer-parallel: true
245+
246+
- name: Install Poetry (env locally)
247+
if: startsWith( matrix.feature, 'ci-poetry-project')
248+
uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b
249+
with:
250+
virtualenvs-create: true
251+
virtualenvs-in-project: true
252+
installer-parallel: true
253+
254+
- name: Install Poetry (env locally)
255+
if: startsWith( matrix.feature, 'ci-poetry-custom')
256+
uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b
257+
with:
258+
virtualenvs-create: true
259+
virtualenvs-in-project: false
260+
virtualenvs-path: ~/my-custom-path
261+
installer-parallel: true
262+
263+
- name: Petry config
264+
if: startsWith( matrix.feature, 'ci-poetry')
265+
run: poetry config --list
266+
shell: bash
267+
268+
- name: Petry setup
269+
if: startsWith( matrix.feature, 'ci-poetry')
270+
# We want to have 2 envs for this poetry project 3.12 and 3.11.
271+
run: poetry init --name=pet-test --python=^3.11 -q -n
272+
shell: bash
273+
274+
- name: Petry virtual env setup 3.12
275+
if: startsWith( matrix.feature, 'ci-poetry')
276+
run: poetry env use python3.12
277+
shell: bash
278+
279+
- name: Petry virtual env setup 3.11
280+
if: startsWith( matrix.feature, 'ci-poetry')
281+
run: poetry env use python3.11
282+
shell: bash
283+
284+
- name: Petry list envs
285+
if: startsWith( matrix.feature, 'ci-poetry')
286+
run: poetry env list
287+
shell: bash
288+
289+
- name: Petry pyproject.toml
290+
if: startsWith( matrix.feature, 'ci-poetry')
291+
run: cat pyproject.toml
292+
shell: bash
293+
294+
# # Dump env vars
295+
# - name: Env
296+
# run: set
297+
# shell: bash
298+
299+
# Rust
300+
- name: Rust Tool Chain setup
301+
uses: dtolnay/rust-toolchain@stable
302+
with:
303+
toolchain: stable
304+
targets: ${{ matrix.target }}
305+
306+
- name: Cargo Fetch
307+
run: cargo fetch
308+
shell: bash
309+
310+
- name: Find Environments
311+
run: cargo run --release --target ${{ matrix.target }}
312+
shell: bash
313+
314+
- name: Run Tests
315+
# Run integration tests in a single thread,
316+
# We end up creating conda envs and running multiple tests in parallel
317+
# that creat conda envs simultaneously causes issues (sometimes the conda envs do not seem to get created)
318+
# Similar issues were identified in vscode-jupyter tests as well (something to do with conda lock files or the like)
319+
run: cargo test --frozen --features ${{ matrix.feature }} -- --nocapture --test-threads=1
320+
env:
321+
RUST_BACKTRACE: 1
322+
RUST_LOG: trace
323+
shell: bash
324+
325+
container-tests:
326+
# These tests are required as its not easy/possible to use the previous jobs.
327+
# E.g. we need to test against the jupyter container, as we found some issues specific to that env.
328+
name: Tests in Containers
329+
container:
330+
image: ${{ matrix.image }}
331+
options: --user=root
332+
runs-on: ${{ matrix.os }}
333+
strategy:
334+
fail-fast: false
335+
matrix:
336+
include:
337+
- feature: ci-jupyter-container
338+
os: ubuntu-latest
339+
# For Tests again the container used in https://github.com/github/codespaces-jupyter
340+
image: mcr.microsoft.com/devcontainers/universal:2.11.1
341+
target: x86_64-unknown-linux-musl
342+
- feature: ci-homebrew-container
343+
os: ubuntu-latest
344+
# For Homebrew in Ubuntu
345+
image: homebrew/brew
346+
target: x86_64-unknown-linux-musl
347+
steps:
348+
- name: Checkout
349+
uses: actions/checkout@v4
350+
351+
# Homebrew
352+
- name: Homebrew Python
353+
if: startsWith( matrix.image, 'homebrew')
354+
355+
shell: bash
356+
357+
# Rust
358+
- name: Rust Tool Chain setup
359+
uses: dtolnay/rust-toolchain@stable
360+
with:
361+
toolchain: stable
362+
targets: ${{ matrix.target }}
363+
364+
- name: Cargo Fetch
365+
run: cargo fetch
366+
shell: bash
367+
368+
- name: Find Environments
369+
run: cargo run --release --target ${{ matrix.target }} -- find -v
370+
shell: bash
371+
372+
- name: Run Tests
373+
run: cargo test --frozen --features ${{ matrix.feature }} -- --nocapture
171374
shell: bash
172375

173376
builds:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pet-conda/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pet-core = { path = "../pet-core" }
1616
log = "0.4.21"
1717
regex = "1.10.4"
1818
pet-reporter = { path = "../pet-reporter" }
19-
19+
env_logger = "0.10.2"
2020

2121
[features]
2222
ci = []

crates/pet-conda/src/environment_locations.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ pub fn get_conda_environment_paths(
6565
*/
6666
fn get_conda_environment_paths_from_conda_rc(env_vars: &EnvVariables) -> Vec<PathBuf> {
6767
if let Some(conda_rc) = Condarc::from(env_vars) {
68+
trace!("Conda environments in .condarc {:?}", conda_rc.env_dirs);
6869
conda_rc.env_dirs
6970
} else {
71+
trace!("No Conda environments in .condarc");
7072
vec![]
7173
}
7274
}
@@ -98,6 +100,7 @@ fn get_conda_environment_paths_from_known_paths(env_vars: &EnvVariables) -> Vec<
98100
}
99101
}
100102
env_paths.append(&mut env_vars.known_global_search_locations.clone());
103+
trace!("Conda environments in known paths {:?}", env_paths);
101104
env_paths
102105
}
103106

@@ -118,6 +121,7 @@ fn get_conda_environment_paths_from_additional_paths(
118121
}
119122
}
120123
env_paths.append(&mut additional_env_dirs.clone());
124+
trace!("Conda environments in additional paths {:?}", env_paths);
121125
env_paths
122126
}
123127

@@ -170,7 +174,9 @@ pub fn get_conda_envs_from_environment_txt(env_vars: &EnvVariables) -> Vec<PathB
170174
if let Ok(reader) = fs::read_to_string(environment_txt.clone()) {
171175
trace!("Found environments.txt file {:?}", environment_txt);
172176
for line in reader.lines() {
173-
envs.push(norm_case(&PathBuf::from(line.to_string())));
177+
let line = norm_case(&PathBuf::from(line.to_string()));
178+
trace!("Conda env in environments.txt file {:?}", line);
179+
envs.push(line);
174180
}
175181
}
176182
}

0 commit comments

Comments
 (0)