Skip to content

Commit 2855a30

Browse files
authored
Merge branch 'main' into feature/implement_copy_import_path
2 parents 7607eed + 8ae346b commit 2855a30

45 files changed

Lines changed: 2116 additions & 350 deletions

Some content is hidden

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

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
**/*.map
22
**/*.analyzer.html
3+
**/.env
34
*.vsix
45
.editorconfig
56
.env

package-lock.json

Lines changed: 141 additions & 289 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"theme": "dark"
4848
},
4949
"engines": {
50-
"vscode": "^1.94.0-20240918"
50+
"vscode": "^1.95.0"
5151
},
5252
"enableTelemetry": false,
5353
"keywords": [
@@ -1479,6 +1479,107 @@
14791479
"fileMatch": "meta.yaml",
14801480
"url": "./schemas/conda-meta.json"
14811481
}
1482+
],
1483+
"languageModelTools": [
1484+
{
1485+
"name": "get_python_environment_details",
1486+
"displayName": "Get Python Environment Info",
1487+
"userDescription": "%python.languageModelTools.get_python_environment_details.userDescription%",
1488+
"modelDescription": "This tool will retrieve the details of the Python Environment for the specified file or workspace. The details returned include the 1. Type of Environment (conda, venv, etec), 2. Version of Python, 3. List of all installed packages with their versions. ALWAYS call configure_python_environment before using this tool.",
1489+
"toolReferenceName": "pythonGetEnvironmentInfo",
1490+
"tags": [
1491+
"enable_other_tool_configure_python_environment"
1492+
],
1493+
"icon": "$(snake)",
1494+
"canBeReferencedInPrompt": true,
1495+
"inputSchema": {
1496+
"type": "object",
1497+
"properties": {
1498+
"resourcePath": {
1499+
"type": "string",
1500+
"description": "The path to the Python file or workspace to get the environment information for."
1501+
}
1502+
},
1503+
"required": []
1504+
},
1505+
"when": "!pythonEnvExtensionInstalled"
1506+
},
1507+
{
1508+
"name": "get_python_executable_details",
1509+
"displayName": "Get Python Executable",
1510+
"userDescription": "%python.languageModelTools.get_python_executable_details.userDescription%",
1511+
"modelDescription": "This tool will retrieve the details of the Python Environment for the specified file or workspace. ALWAYS use this tool before executing any Python command in the terminal. This tool returns the details of how to construct the fully qualified path and or command including details such as arguments required to run Python in a terminal. Note: Instead of executing `python --version` or `python -c 'import sys; print(sys.executable)'`, use this tool to get the Python executable path to replace the `python` command. E.g. instead of using `python -c 'import sys; print(sys.executable)'`, use this tool to build the command `conda run -n <env_name> -c 'import sys; print(sys.executable)'`. ALWAYS call configure_python_environment before using this tool.",
1512+
"toolReferenceName": "pythonExecutableCommand",
1513+
"tags": [
1514+
"enable_other_tool_configure_python_environment"
1515+
],
1516+
"icon": "$(terminal)",
1517+
"canBeReferencedInPrompt": true,
1518+
"inputSchema": {
1519+
"type": "object",
1520+
"properties": {
1521+
"resourcePath": {
1522+
"type": "string",
1523+
"description": "The path to the Python file or workspace to get the executable information for. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace."
1524+
}
1525+
},
1526+
"required": []
1527+
},
1528+
"when": "!pythonEnvExtensionInstalled"
1529+
},
1530+
{
1531+
"name": "install_python_packages",
1532+
"displayName": "Install Python Package",
1533+
"userDescription": "%python.languageModelTools.install_python_packages.userDescription%",
1534+
"modelDescription": "Installs Python packages in the given workspace. Use this tool to install packages in the user's chosen environment. ALWAYS call configure_python_environment before using this tool.",
1535+
"toolReferenceName": "pythonInstallPackage",
1536+
"tags": [
1537+
"enable_other_tool_configure_python_environment"
1538+
],
1539+
"icon": "$(package)",
1540+
"canBeReferencedInPrompt": true,
1541+
"inputSchema": {
1542+
"type": "object",
1543+
"properties": {
1544+
"packageList": {
1545+
"type": "array",
1546+
"items": {
1547+
"type": "string"
1548+
},
1549+
"description": "The list of packages to install."
1550+
},
1551+
"resourcePath": {
1552+
"type": "string",
1553+
"description": "The path to the Python file or workspace into which the packages are installed. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace."
1554+
}
1555+
},
1556+
"required": [
1557+
"packageList"
1558+
]
1559+
},
1560+
"when": "!pythonEnvExtensionInstalled"
1561+
},
1562+
{
1563+
"name": "configure_python_environment",
1564+
"displayName": "Configure Python Environment",
1565+
"modelDescription": "This tool configures a Python environment in the given workspace. ALWAYS Use this tool to set up the user's chosen environment and ALWAYS call this tool before using any other Python related tools.",
1566+
"userDescription": "%python.languageModelTools.configure_python_environment.userDescription%",
1567+
"toolReferenceName": "configurePythonEnvironment",
1568+
"tags": [],
1569+
"icon": "$(gear)",
1570+
"canBeReferencedInPrompt": true,
1571+
"inputSchema": {
1572+
"type": "object",
1573+
"properties": {
1574+
"resourcePath": {
1575+
"type": "string",
1576+
"description": "The path to the Python file or workspace for which a Python Environment needs to be configured."
1577+
}
1578+
},
1579+
"required": []
1580+
},
1581+
"when": "!pythonEnvExtensionInstalled"
1582+
}
14821583
]
14831584
},
14841585
"copilot": {
@@ -1571,7 +1672,7 @@
15711672
"@types/sinon": "^17.0.3",
15721673
"@types/stack-trace": "0.0.29",
15731674
"@types/tmp": "^0.0.33",
1574-
"@types/vscode": "^1.93.0",
1675+
"@types/vscode": "^1.95.0",
15751676
"@types/which": "^2.0.1",
15761677
"@types/winreg": "^1.2.30",
15771678
"@types/xml2js": "^0.4.2",

package.nls.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
22
"python.command.python.startTerminalREPL.title": "Start Terminal REPL",
3+
"python.languageModelTools.get_python_environment_details.userDescription": "Get information for a Python Environment, such as Type, Version, Packages, and more.",
4+
"python.languageModelTools.install_python_packages.userDescription": "Installs Python packages in a Python Environment.",
5+
"python.languageModelTools.get_python_executable_details.userDescription": "Get executable info for a Python Environment",
6+
"python.languageModelTools.configure_python_environment.userDescription": "Configure a Python Environment for a workspace",
37
"python.command.python.startNativeREPL.title": "Start Native Python REPL",
48
"python.command.python.createEnvironment.title": "Create Environment...",
59
"python.command.python.createNewFile.title": "New Python File",
610
"python.command.python.createTerminal.title": "Create Terminal",
711
"python.command.python.execInTerminal.title": "Run Python File in Terminal",
812
"python.command.python.execInTerminalIcon.title": "Run Python File",
9-
"python.command.python.execInDedicatedTerminal.title": "Run Python File in Dedicated Terminal",
13+
"python.command.python.execInDedicatedTerminal.title": "Run Python File in Dedicated Terminal",
1014
"python.command.python.setInterpreter.title": "Select Interpreter",
1115
"python.command.python.clearWorkspaceInterpreter.title": "Clear Workspace Interpreter Setting",
1216
"python.command.python.viewOutput.title": "Show Output",

python_files/create_venv.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,20 @@ def run_process(args: Sequence[str], error_message: str) -> None:
9898
raise VenvError(error_message) from exc
9999

100100

101+
def get_win_venv_path(name: str) -> str:
102+
venv_dir = CWD / name
103+
# If using MSYS2 Python, the Python executable is located in the 'bin' directory.
104+
if file_exists(venv_dir / "bin" / "python.exe"):
105+
return os.fspath(venv_dir / "bin" / "python.exe")
106+
else:
107+
return os.fspath(venv_dir / "Scripts" / "python.exe")
108+
109+
101110
def get_venv_path(name: str) -> str:
102111
# See `venv` doc here for more details on binary location:
103112
# https://docs.python.org/3/library/venv.html#creating-virtual-environments
104113
if sys.platform == "win32":
105-
return os.fspath(CWD / name / "Scripts" / "python.exe")
114+
return get_win_venv_path(name)
106115
else:
107116
return os.fspath(CWD / name / "bin" / "python")
108117

python_files/pythonrc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def __str__(self):
5353
result = ""
5454
# For non-windows allow recent_command history.
5555
if sys.platform != "win32":
56-
result = "{command_line}{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format(
56+
result = "{command_executed}{command_line}{command_finished}{prompt_started}{prompt}{command_start}".format(
57+
command_executed="\x1b]633;C\x07",
5758
command_line="\x1b]633;E;" + str(get_last_command()) + "\x07",
5859
command_finished="\x1b]633;D;" + str(exit_code) + "\x07",
5960
prompt_started="\x1b]633;A\x07",
6061
prompt=original_ps1,
6162
command_start="\x1b]633;B\x07",
62-
command_executed="\x1b]633;C\x07",
6363
)
6464
else:
6565
result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format(

python_files/tests/test_create_venv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def create_gitignore(_p):
122122
def test_install_packages(install_type):
123123
importlib.reload(create_venv)
124124
create_venv.is_installed = lambda _x: True
125-
create_venv.file_exists = lambda x: install_type in x
125+
create_venv.file_exists = lambda x: install_type in str(x)
126126

127127
pip_upgraded = False
128128
installing = None

python_files/tests/test_shell_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_decoration_success():
1717
if sys.platform != "win32" and (not is_wsl):
1818
assert (
1919
result
20-
== "\x1b]633;E;None\x07\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
20+
== "\x1b]633;C\x07\x1b]633;E;None\x07\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07"
2121
)
2222
else:
2323
pass
@@ -32,7 +32,7 @@ def test_decoration_failure():
3232
if sys.platform != "win32" and (not is_wsl):
3333
assert (
3434
result
35-
== "\x1b]633;E;None\x07\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
35+
== "\x1b]633;C\x07\x1b]633;E;None\x07\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07"
3636
)
3737
else:
3838
pass

python_files/unittestadapter/execution.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from types import TracebackType
1313
from typing import Dict, List, Optional, Set, Tuple, Type, Union
1414

15-
from packaging.version import Version
16-
1715
# Adds the scripts directory to the PATH as a workaround for enabling shell for test execution.
1816
path_var_name = "PATH" if "PATH" in os.environ else "Path"
1917
os.environ[path_var_name] = (
@@ -326,6 +324,13 @@ def send_run_data(raw_data, test_run_pipe):
326324
)
327325
import coverage
328326

327+
# insert "python_files/lib/python" into the path so packaging can be imported
328+
python_files_dir = pathlib.Path(__file__).parent.parent
329+
bundled_dir = pathlib.Path(python_files_dir / "lib" / "python")
330+
sys.path.append(os.fspath(bundled_dir))
331+
332+
from packaging.version import Version
333+
329334
coverage_version = Version(coverage.__version__)
330335
# only include branches if coverage version is 7.7.0 or greater (as this was when the api saves)
331336
if coverage_version >= Version("7.7.0"):

python_files/vscode_pytest/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from typing import TYPE_CHECKING, Any, Dict, Generator, Literal, TypedDict
1414

1515
import pytest
16-
from packaging.version import Version
1716

1817
if TYPE_CHECKING:
1918
from pluggy import Result
@@ -443,6 +442,13 @@ def pytest_sessionfinish(session, exitstatus):
443442
# load the report and build the json result to return
444443
import coverage
445444

445+
# insert "python_files/lib/python" into the path so packaging can be imported
446+
python_files_dir = pathlib.Path(__file__).parent.parent
447+
bundled_dir = pathlib.Path(python_files_dir / "lib" / "python")
448+
sys.path.append(os.fspath(bundled_dir))
449+
450+
from packaging.version import Version
451+
446452
coverage_version = Version(coverage.__version__)
447453
global INCLUDE_BRANCHES
448454
# only include branches if coverage version is 7.7.0 or greater (as this was when the api saves)

0 commit comments

Comments
 (0)