Skip to content

Commit 703de32

Browse files
committed
Merge pull request #7 from eleanorjboyd/fix-main
fix main
2 parents 9f67fbe + e9a2b97 commit 703de32

File tree

128 files changed

+4122
-1297
lines changed

Some content is hidden

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

128 files changed

+4122
-1297
lines changed

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"esbenp.prettier-vscode",
77
"dbaeumer.vscode-eslint",
88
"ms-python.python",
9+
"ms-python.black-formatter",
910
"ms-python.vscode-pylance"
1011
]
1112
}

.vscode/launch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@
253253
"request": "attach",
254254
"listen": { "host": "localhost", "port": 5678 },
255255
"justMyCode": true
256+
},
257+
{
258+
"name": "Debug pytest plugin tests",
259+
260+
"type": "python",
261+
"request": "launch",
262+
"module": "pytest",
263+
"args": ["${workspaceFolder}/pythonFiles/tests/pytestadapter"],
264+
"justMyCode": true
256265
}
257266
],
258267
"compounds": [

build/webpack/webpack.extension.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ const config = {
6161
// See: https://github.com/microsoft/vscode-extension-telemetry/issues/41#issuecomment-598852991
6262
'applicationinsights-native-metrics',
6363
'@opentelemetry/tracing',
64+
'@azure/opentelemetry-instrumentation-azure-sdk',
65+
'@opentelemetry/instrumentation',
66+
'@azure/functions-core',
6467
],
6568
plugins: [...common.getDefaultPlugins('extension')],
6669
resolve: {

package-lock.json

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

package.json

Lines changed: 64 additions & 46 deletions
Large diffs are not rendered by default.

package.nls.json

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"python.command.python.setInterpreter.title": "Select Interpreter",
1111
"python.command.python.clearWorkspaceInterpreter.title": "Clear Workspace Interpreter Setting",
1212
"python.command.python.viewOutput.title": "Show Output",
13+
"python.command.python.installJupyter.title": "Install the Jupyter extension",
1314
"python.command.python.viewLanguageServerOutput.title": "Show Language Server Output",
1415
"python.command.python.configureTests.title": "Configure Tests",
1516
"python.command.testing.rerunFailedTests.title": "Rerun Failed Tests",
@@ -26,6 +27,7 @@
2627
"python.command.python.refreshTensorBoard.title": "Refresh TensorBoard",
2728
"python.menu.createNewFile.title": "Python File",
2829
"python.editor.context.submenu.runPython": "Run Python",
30+
"python.editor.context.submenu.runPythonInteractive": "Run in Interactive window",
2931
"python.activeStateToolPath.description": "Path to the State Tool executable for ActiveState runtimes (version 0.36+).",
3032
"python.autoComplete.extraPaths.description": "List of paths to libraries and the like that need to be imported by auto complete engine. E.g. when using Google App SDK, the paths are not in system path, hence need to be added into this list.",
3133
"python.condaPath.description": "Path to the conda executable to use for activation (version 4.4+).",
@@ -98,6 +100,7 @@
98100
"python.linting.pylintEnabled.description": "Whether to lint Python files using pylint.",
99101
"python.linting.pylintPath.description": "Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path.",
100102
"python.logging.level.description": "The logging level the extension logs at, defaults to 'error'",
103+
"python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.",
101104
"python.pipenvPath.description": "Path to the pipenv executable to use for activation.",
102105
"python.poetryPath.description": "Path to the poetry executable.",
103106
"python.sortImports.args.description": "Arguments passed in. Each argument is a separate item in the array.",
@@ -120,5 +123,42 @@
120123
"python.venvFolders.description": "Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).",
121124
"python.venvPath.description": "Path to folder with a list of Virtual Environments (e.g. ~/.pyenv, ~/Envs, ~/.virtualenvs).",
122125
"python.sortImports.args.deprecationMessage": "This setting will be removed soon. Use 'isort.args' instead.",
123-
"python.sortImports.path.deprecationMessage": "This setting will be removed soon. Use 'isort.path' instead."
126+
"python.sortImports.path.deprecationMessage": "This setting will be removed soon. Use 'isort.path' instead.",
127+
"walkthrough.pythonWelcome.title": "Get Started with Python Development",
128+
"walkthrough.pythonWelcome.description": "Your first steps to set up a Python project with all the powerful tools and features that the Python extension has to offer!",
129+
"walkthrough.step.python.createPythonFile.title": "Create a Python file",
130+
"walkthrough.step.python.createPythonFile.description": "[Open](command:toSide:workbench.action.files.openFile) or [create](command:toSide:workbench.action.files.newUntitledFile?%7B%22languageId%22%3A%22python%22%7D) a Python file - make sure to save it as \".py\".\n[Create Python File](command:toSide:workbench.action.files.newUntitledFile?%7B%22languageId%22%3A%22python%22%7D)",
131+
"walkthrough.step.python.installPythonWin8.title": "Install Python",
132+
"walkthrough.step.python.installPythonWin8.description": "The Python Extension requires Python to be installed. Install Python [from python.org](https://www.python.org/downloads).\n\n[Install Python](https://www.python.org/downloads)\n",
133+
"walkthrough.step.python.installPythonMac.title": "Install Python",
134+
"walkthrough.step.python.installPythonMac.description": "The Python Extension requires Python to be installed. Install Python 3 through the terminal.\n[Install Python via Brew](command:python.installPythonOnMac)\n",
135+
"walkthrough.step.python.installPythonLinux.title": "Install Python",
136+
"walkthrough.step.python.installPythonLinux.description": "The Python Extension requires Python to be installed. Install Python 3 through the terminal.\n[Install Python via terminal](command:python.installPythonOnLinux)\n",
137+
"walkthrough.step.python.selectInterpreter.title": "Select a Python Interpreter",
138+
"walkthrough.step.python.selectInterpreter.description": "Choose which Python interpreter/environment you want to use for your Python project.\n[Select Python Interpreter](command:python.setInterpreter)\n**Tip**: Run the ``Python: Select Interpreter`` command in the [Command Palette](command:workbench.action.showCommands).",
139+
"walkthrough.step.python.createEnvironment.title": "Create a Python Environment ",
140+
"walkthrough.step.python.createEnvironment.description": "Create an environment for your Python project.\n[Create Environment](command:python.createEnvironment)\n**Tip**: Run the ``Python: Create Environment`` command in the [Command Palette](command:workbench.action.showCommands).\n 🔍 Check out our [docs](https://aka.ms/pythonenvs) to learn more.",
141+
"walkthrough.step.python.runAndDebug.title": "Run and debug your Python file",
142+
"walkthrough.step.python.runAndDebug.description": "Open your Python file and click on the play button on the top right of the editor, or press F5 when on the file and select \"Python File\" to run with the debugger. \n \n[Learn more](https://code.visualstudio.com/docs/python/python-tutorial#_run-hello-world)",
143+
"walkthrough.step.python.learnMoreWithDS.title": "Explore more resources",
144+
"walkthrough.step.python.learnMoreWithDS.description": "🎨 Explore all the features the Python extension has to offer by looking for \"Python\" in the [Command Palette](command:workbench.action.showCommands). \n 📈 Learn more about getting started with [data science](command:workbench.action.openWalkthrough?%7B%22category%22%3A%22ms-python.python%23pythonDataScienceWelcome%22%2C%22step%22%3A%22ms-python.python%23python.createNewNotebook%22%7D) in Python. \n ✨ Take a look at our [Release Notes](https://aka.ms/AA8dxtb) to learn more about the latest features. \n \n[Learn More](https://aka.ms/AA8dqti)",
145+
"walkthrough.pythonDataScienceWelcome.title": "Get Started with Python for Data Science",
146+
"walkthrough.pythonDataScienceWelcome.description": "Your first steps to getting started with a Data Science project with Python!",
147+
"walkthrough.step.python.installJupyterExt.title": "Install Jupyter extension",
148+
"walkthrough.step.python.installJupyterExt.description": "If you haven't already, install the [Jupyter extension](command:workbench.extensions.search?\"ms-toolsai.jupyter\") to take full advantage of notebooks experiences in VS Code!\n \n[Search Jupyter extension](command:workbench.extensions.search?\"ms-toolsai.jupyter\")",
149+
"walkthrough.step.python.createNewNotebook.title": "Create or open a Jupyter Notebook",
150+
"walkthrough.step.python.createNewNotebook.description": "Right click in the file explorer and create a new file with an .ipynb extension. Or, open the [Command Palette](command:workbench.action.showCommands) and run the command \n``Jupyter: Create New Blank Notebook``.\n[Create new Jupyter Notebook](command:toSide:jupyter.createnewnotebook)\n If you have an existing project, you can also [open a folder](command:workbench.action.files.openFolder) and/or clone a project from GitHub: [clone a Git repository](command:git.clone).",
151+
"walkthrough.step.python.openInteractiveWindow.title": "Open the Python Interactive Window",
152+
"walkthrough.step.python.openInteractiveWindow.description": "The Python Interactive Window is a Python shell where you can execute and view the results of your Python code. You can create cells on a Python file by typing ``#%%``.\n \nTo open the interactive window anytime, open the [Command Palette](command:workbench.action.showCommands) and run the command \n``Jupyter: Create Interactive Window``.\n[Open Interactive Window](command:jupyter.createnewinteractive)",
153+
"walkthrough.step.python.dataScienceLearnMore.title": "Find out more!",
154+
"walkthrough.step.python.dataScienceLearnMore.description": "📒 Take a look into the [Jupyter extension](command:workbench.extensions.search?\"ms-toolsai.jupyter\") features, by looking for \"Jupyter\" in the [Command Palette](command:workbench.action.showCommands). \n 🏃🏻 Find out more features in our [Tutorials](https://aka.ms/AAdjzpd). \n[Learn more](https://aka.ms/AAdar6q)",
155+
"walkthrough.step.python.createPythonFile.altText": "Open a Python file or a folder with a Python project.",
156+
"walkthrough.step.python.selectInterpreter.altText": "Selecting a Python interpreter from the status bar",
157+
"walkthrough.step.python.createEnvironment.altText": "Creating a Python environment from the Command Palette",
158+
"walkthrough.step.python.runAndDebug.altText": "How to run and debug in VS Code with F5 or the play button on the top right.",
159+
"walkthrough.step.python.learnMoreWithDS.altText": "Image representing our documentation page and mailing list resources.",
160+
"walkthrough.step.python.installJupyterExt.altText": "Creating a new Jupyter notebook",
161+
"walkthrough.step.python.createNewNotebook.altText": "Creating a new Jupyter notebook",
162+
"walkthrough.step.python.openInteractiveWindow.altText": "Opening Python interactive window",
163+
"walkthrough.step.python.dataScienceLearnMore.altText": "Image representing our documentation page and mailing list resources."
124164
}

pythonFiles/create_microvenv.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pathlib
77
import subprocess
88
import sys
9-
import urllib.request as url_lib
109
from typing import Optional, Sequence
1110

1211
VENV_NAME = ".venv"
@@ -29,13 +28,6 @@ def run_process(args: Sequence[str], error_message: str) -> None:
2928
def parse_args(argv: Sequence[str]) -> argparse.Namespace:
3029
parser = argparse.ArgumentParser()
3130

32-
parser.add_argument(
33-
"--install-pip",
34-
action="store_true",
35-
default=False,
36-
help="Install pip into the virtual environment.",
37-
)
38-
3931
parser.add_argument(
4032
"--name",
4133
default=VENV_NAME,
@@ -54,31 +46,6 @@ def create_microvenv(name: str):
5446
)
5547

5648

57-
def download_pip_pyz(name: str):
58-
url = "https://bootstrap.pypa.io/pip/pip.pyz"
59-
print("CREATE_MICROVENV.DOWNLOADING_PIP")
60-
61-
try:
62-
with url_lib.urlopen(url) as response:
63-
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
64-
with open(pip_pyz_path, "wb") as out_file:
65-
data = response.read()
66-
out_file.write(data)
67-
out_file.flush()
68-
except Exception:
69-
raise MicroVenvError("CREATE_MICROVENV.DOWNLOAD_PIP_FAILED")
70-
71-
72-
def install_pip(name: str):
73-
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
74-
executable = os.fspath(CWD / name / "bin" / "python")
75-
print("CREATE_MICROVENV.INSTALLING_PIP")
76-
run_process(
77-
[executable, pip_pyz_path, "install", "pip"],
78-
"CREATE_MICROVENV.INSTALL_PIP_FAILED",
79-
)
80-
81-
8249
def main(argv: Optional[Sequence[str]] = None) -> None:
8350
if argv is None:
8451
argv = []
@@ -88,10 +55,6 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
8855
create_microvenv(args.name)
8956
print("CREATE_MICROVENV.CREATED_MICROVENV")
9057

91-
if args.install_pip:
92-
download_pip_pyz(args.name)
93-
install_pip(args.name)
94-
9558

9659
if __name__ == "__main__":
9760
main(sys.argv[1:])

pythonFiles/create_venv.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pathlib
88
import subprocess
99
import sys
10+
import urllib.request as url_lib
1011
from typing import List, Optional, Sequence, Union
1112

1213
VENV_NAME = ".venv"
@@ -126,51 +127,92 @@ def add_gitignore(name: str) -> None:
126127
f.write("*")
127128

128129

130+
def download_pip_pyz(name: str):
131+
url = "https://bootstrap.pypa.io/pip/pip.pyz"
132+
print("CREATE_VENV.DOWNLOADING_PIP")
133+
134+
try:
135+
with url_lib.urlopen(url) as response:
136+
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
137+
with open(pip_pyz_path, "wb") as out_file:
138+
data = response.read()
139+
out_file.write(data)
140+
out_file.flush()
141+
except Exception:
142+
raise VenvError("CREATE_VENV.DOWNLOAD_PIP_FAILED")
143+
144+
145+
def install_pip(name: str):
146+
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
147+
executable = get_venv_path(name)
148+
print("CREATE_VENV.INSTALLING_PIP")
149+
run_process(
150+
[executable, pip_pyz_path, "install", "pip"],
151+
"CREATE_VENV.INSTALL_PIP_FAILED",
152+
)
153+
154+
129155
def main(argv: Optional[Sequence[str]] = None) -> None:
130156
if argv is None:
131157
argv = []
132158
args = parse_args(argv)
133159

134160
use_micro_venv = False
135-
if not is_installed("venv"):
161+
venv_installed = is_installed("venv")
162+
pip_installed = is_installed("pip")
163+
ensure_pip_installed = is_installed("ensurepip")
164+
165+
if not venv_installed:
136166
if sys.platform == "win32":
137167
raise VenvError("CREATE_VENV.VENV_NOT_FOUND")
138168
else:
139169
use_micro_venv = True
140170

141-
pip_installed = is_installed("pip")
142-
deps_needed = args.requirements or args.extras or args.toml
143-
if deps_needed and not pip_installed and not use_micro_venv:
144-
raise VenvError("CREATE_VENV.PIP_NOT_FOUND")
145-
146171
if venv_exists(args.name):
172+
# A virtual environment with same name exists.
173+
# We will use the existing virtual environment.
147174
venv_path = get_venv_path(args.name)
148175
print(f"EXISTING_VENV:{venv_path}")
149176
else:
150177
if use_micro_venv:
178+
# `venv` was not found but on this platform we can use `microvenv`
151179
run_process(
152180
[
153181
sys.executable,
154182
os.fspath(MICROVENV_SCRIPT_PATH),
155-
"--install-pip",
156183
"--name",
157184
args.name,
158185
],
159186
"CREATE_VENV.MICROVENV_FAILED_CREATION",
160187
)
161-
pip_installed = True
188+
elif not pip_installed or not ensure_pip_installed:
189+
# `venv` was found but `pip` or `ensurepip` was not found.
190+
# We create a venv without `pip` in it. We will later install `pip`.
191+
run_process(
192+
[sys.executable, "-m", "venv", "--without-pip", args.name],
193+
"CREATE_VENV.VENV_FAILED_CREATION",
194+
)
162195
else:
196+
# Both `venv` and `pip` were found. So create a .venv normally
163197
run_process(
164198
[sys.executable, "-m", "venv", args.name],
165199
"CREATE_VENV.VENV_FAILED_CREATION",
166200
)
201+
167202
venv_path = get_venv_path(args.name)
168203
print(f"CREATED_VENV:{venv_path}")
204+
169205
if args.git_ignore:
170206
add_gitignore(args.name)
171207

172-
if pip_installed:
208+
# At this point we have a .venv. Now we handle installing `pip`.
209+
if pip_installed and ensure_pip_installed:
210+
# We upgrade pip if it is already installed.
173211
upgrade_pip(venv_path)
212+
else:
213+
# `pip` was not found, so we download it and install it.
214+
download_pip_pyz(args.name)
215+
install_pip(args.name)
174216

175217
if args.toml:
176218
print(f"VENV_INSTALLING_PYPROJECT: {args.toml}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
# This test's id is double_nested_folder/nested_folder_one/nested_folder_two/test_nest.py::test_function.
6+
# This test passes.
7+
def test_function(): # test_marker--test_function
8+
assert 1 == 1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
# This test's id is dual_level_nested_folder/nested_folder_one/test_bottom_folder.py::test_bottom_function_t.
6+
# This test passes.
7+
def test_bottom_function_t(): # test_marker--test_bottom_function_t
8+
assert True
9+
10+
11+
# This test's id is dual_level_nested_folder/nested_folder_one/test_bottom_folder.py::test_bottom_function_f.
12+
# This test fails.
13+
def test_bottom_function_f(): # test_marker--test_bottom_function_f
14+
assert False
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
# This test's id is dual_level_nested_folder/test_top_folder.py::test_top_function_t.
6+
# This test passes.
7+
def test_top_function_t(): # test_marker--test_top_function_t
8+
assert True
9+
10+
11+
# This test's id is dual_level_nested_folder/test_top_folder.py::test_top_function_f.
12+
# This test fails.
13+
def test_top_function_f(): # test_marker--test_top_function_f
14+
assert False
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
# This file has no tests in it; the discovery will return an empty list of tests.
6+
def function_function(string):
7+
return string
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import pytest
4+
5+
6+
# This test has an error which will appear on pytest discovery.
7+
# This error is intentional and is meant to test pytest discovery error handling.
8+
@pytest.mark.parametrize("actual,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])
9+
def test_function():
10+
assert True
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
# This test has a syntax error.
5+
# This error is intentional and is meant to test pytest discovery error handling.
6+
def test_function()
7+
assert True
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
4+
# Testing pytest with parametrized tests. The first two pass, the third fails.
5+
# The tests ids are parametrize_tests.py::test_adding[3+5-8] and so on.
6+
@pytest.mark.parametrize( # test_marker--test_adding
7+
"actual, expected", [("3+5", 8), ("2+4", 6), ("6+9", 16)]
8+
)
9+
def test_adding(actual, expected):
10+
assert eval(actual) == expected
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
# This test passes.
6+
def test_function(): # test_marker--test_function
7+
assert 1 == 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is a doctest test which passes #test_marker--text_docstring.txt
2+
>>> x = 3
3+
>>> x
4+
3
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import unittest
4+
5+
6+
def add(a, b):
7+
return a + b
8+
9+
10+
class TestAddFunction(unittest.TestCase):
11+
# This test's id is unittest_folder/test_add.py::TestAddFunction::test_add_positive_numbers.
12+
# This test passes.
13+
def test_add_positive_numbers(self): # test_marker--test_add_positive_numbers
14+
result = add(2, 3)
15+
self.assertEqual(result, 5)
16+
17+
# This test's id is unittest_folder/test_add.py::TestAddFunction::test_add_negative_numbers.
18+
# This test passes.
19+
def test_add_negative_numbers(self): # test_marker--test_add_negative_numbers
20+
result = add(-2, -3)
21+
self.assertEqual(result, -5)

0 commit comments

Comments
 (0)