-
Notifications
You must be signed in to change notification settings - Fork 16.9k
Add environment context detection utility for Breeze (GSoC PoC) #64753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,146 @@ | ||||||||||
| # Licensed to the Apache Software Foundation (ASF) under one | ||||||||||
| # or more contributor license agreements. See the NOTICE file | ||||||||||
| # distributed with this work for additional information | ||||||||||
| # regarding copyright ownership. The ASF licenses this file | ||||||||||
| # to you under the Apache License, Version 2.0 (the | ||||||||||
| # "License"); you may not use this file except in compliance | ||||||||||
| # with the License. You may obtain a copy of the License at | ||||||||||
| # | ||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| # | ||||||||||
| # Unless required by applicable law or agreed to in writing, | ||||||||||
| # software distributed under the License is distributed on an | ||||||||||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||
| # KIND, either express or implied. See the License for the | ||||||||||
| # specific language governing permissions and limitations | ||||||||||
| # under the License. | ||||||||||
| """ | ||||||||||
| Environment context detection helper for Breeze AI workflows. | ||||||||||
|
|
||||||||||
| This module provides utilities to detect the execution environment (WSL, Docker, etc.) | ||||||||||
| and recommend appropriate commands for AI-assisted Breeze workflows. | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| from __future__ import annotations | ||||||||||
|
|
||||||||||
| import os | ||||||||||
| import subprocess | ||||||||||
| from dataclasses import dataclass | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @dataclass | ||||||||||
| class EnvironmentContext: | ||||||||||
| """Information about the current execution environment.""" | ||||||||||
|
|
||||||||||
| is_wsl: bool | ||||||||||
| """True if running under Windows Subsystem for Linux (WSL).""" | ||||||||||
|
|
||||||||||
| inside_container: bool | ||||||||||
| """True if running inside a Docker container.""" | ||||||||||
|
|
||||||||||
| docker_available: bool | ||||||||||
| """True if Docker is available and accessible.""" | ||||||||||
|
|
||||||||||
| recommended_command: str | ||||||||||
| """Recommended command for the current environment (e.g., 'breeze shell' or 'pytest').""" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def _detect_wsl() -> bool: | ||||||||||
| """ | ||||||||||
| Detect whether we are running under Windows Subsystem for Linux (WSL). | ||||||||||
|
|
||||||||||
| Uses multiple detection methods: | ||||||||||
| 1. Check WSL_DISTRO_NAME environment variable (WSL 2 specific) | ||||||||||
| 2. Check /proc/version for Microsoft/WSL markers (WSL 1 & 2) | ||||||||||
| 3. Check uname release for microsoft marker (WSL 2) | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| True if running under WSL, False otherwise. | ||||||||||
| """ | ||||||||||
| # Method 1: Environment variable (WSL 2 specific) | ||||||||||
| if "WSL_DISTRO_NAME" in os.environ: | ||||||||||
| return True | ||||||||||
|
|
||||||||||
|
Comment on lines
+48
to
+63
|
||||||||||
| # Method 2: Check /proc/version (WSL 1 & 2) | ||||||||||
| try: | ||||||||||
| with open("/proc/version", encoding="utf-8") as version_file: | ||||||||||
| version = version_file.read() | ||||||||||
| if "Microsoft" in version or "WSL" in version: | ||||||||||
|
Comment on lines
+67
to
+68
|
||||||||||
| version = version_file.read() | |
| if "Microsoft" in version or "WSL" in version: | |
| version = version_file.read().lower() | |
| if "microsoft" in version or "wsl" in version: |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detect_environment_context() always runs _is_docker_available() (which shells out to docker info with a 5s timeout) even when inside_container is True and the result doesn't affect recommended_command. Consider skipping the Docker availability check when running inside the container, or making the availability probe opt-in, to keep context detection fast and predictable.
| # Check Docker availability | |
| docker_available = _is_docker_available() | |
| # Check Docker availability only when running outside the container. | |
| docker_available = False if inside_container else _is_docker_available() |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,226 @@ | ||||||||||||||||
| # Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||||
| # or more contributor license agreements. See the NOTICE file | ||||||||||||||||
| # distributed with this work for additional information | ||||||||||||||||
| # regarding copyright ownership. The ASF licenses this file | ||||||||||||||||
| # to you under the Apache License, Version 2.0 (the | ||||||||||||||||
|
Comment on lines
+1
to
+5
|
||||||||||||||||
| # "License"); you may not use this file except in compliance | ||||||||||||||||
| # with the License. You may obtain a copy of the License at | ||||||||||||||||
| # | ||||||||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||
| # | ||||||||||||||||
| # Unless required by applicable law or agreed to in writing, | ||||||||||||||||
| # software distributed under the License is distributed on an | ||||||||||||||||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||
| # KIND, either express or implied. See the License for the | ||||||||||||||||
| # specific language governing permissions and limitations | ||||||||||||||||
| # under the License. | ||||||||||||||||
| """ | ||||||||||||||||
| Tests for environment context detection. | ||||||||||||||||
|
|
||||||||||||||||
| Tests the ability to detect execution environment (WSL, Docker, etc.) | ||||||||||||||||
| and recommend appropriate commands for Breeze workflows. | ||||||||||||||||
| """ | ||||||||||||||||
|
|
||||||||||||||||
| from __future__ import annotations | ||||||||||||||||
|
|
||||||||||||||||
| import subprocess | ||||||||||||||||
| from pathlib import Path | ||||||||||||||||
| from unittest.mock import MagicMock, patch | ||||||||||||||||
|
|
||||||||||||||||
| import pytest | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+27
to
+31
|
||||||||||||||||
| from pathlib import Path | |
| from unittest.mock import MagicMock, patch | |
| import pytest | |
| from unittest.mock import MagicMock, patch | |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are whitespace-only/trailing spaces on otherwise blank lines (e.g. the blank line after monkeypatch.delenv(...)). This violates the repo's trailing-whitespace checks and should be cleaned up.
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests create MagicMock() instances without a spec/autospec (e.g. for the subprocess.run result). Using spec/autospec (or a real subprocess.CompletedProcess) helps catch attribute typos and keeps mocks aligned with the real API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module also appears to be using CRLF line endings;
.editorconfigspecifiesend_of_line = lf. Please convert the file to LF to align with repository conventions and avoid noisy diffs/tooling issues.