Skip to content

Commit

Permalink
Merge pull request #7 from eleanorjboyd/fix-main
Browse files Browse the repository at this point in the history
fix main
  • Loading branch information
eleanorjboyd committed Apr 19, 2023
2 parents 9f67fbe + 703de32 commit 2f16aae
Show file tree
Hide file tree
Showing 128 changed files with 4,122 additions and 1,297 deletions.
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.vscode-pylance"
]
}
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@
"request": "attach",
"listen": { "host": "localhost", "port": 5678 },
"justMyCode": true
},
{
"name": "Debug pytest plugin tests",

"type": "python",
"request": "launch",
"module": "pytest",
"args": ["${workspaceFolder}/pythonFiles/tests/pytestadapter"],
"justMyCode": true
}
],
"compounds": [
Expand Down
3 changes: 3 additions & 0 deletions build/webpack/webpack.extension.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const config = {
// See: https://github.com/microsoft/vscode-extension-telemetry/issues/41#issuecomment-598852991
'applicationinsights-native-metrics',
'@opentelemetry/tracing',
'@azure/opentelemetry-instrumentation-azure-sdk',
'@opentelemetry/instrumentation',
'@azure/functions-core',
],
plugins: [...common.getDefaultPlugins('extension')],
resolve: {
Expand Down
1,401 changes: 683 additions & 718 deletions package-lock.json

Large diffs are not rendered by default.

110 changes: 64 additions & 46 deletions package.json

Large diffs are not rendered by default.

42 changes: 41 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"python.command.python.setInterpreter.title": "Select Interpreter",
"python.command.python.clearWorkspaceInterpreter.title": "Clear Workspace Interpreter Setting",
"python.command.python.viewOutput.title": "Show Output",
"python.command.python.installJupyter.title": "Install the Jupyter extension",
"python.command.python.viewLanguageServerOutput.title": "Show Language Server Output",
"python.command.python.configureTests.title": "Configure Tests",
"python.command.testing.rerunFailedTests.title": "Rerun Failed Tests",
Expand All @@ -26,6 +27,7 @@
"python.command.python.refreshTensorBoard.title": "Refresh TensorBoard",
"python.menu.createNewFile.title": "Python File",
"python.editor.context.submenu.runPython": "Run Python",
"python.editor.context.submenu.runPythonInteractive": "Run in Interactive window",
"python.activeStateToolPath.description": "Path to the State Tool executable for ActiveState runtimes (version 0.36+).",
"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.",
"python.condaPath.description": "Path to the conda executable to use for activation (version 4.4+).",
Expand Down Expand Up @@ -98,6 +100,7 @@
"python.linting.pylintEnabled.description": "Whether to lint Python files using pylint.",
"python.linting.pylintPath.description": "Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path.",
"python.logging.level.description": "The logging level the extension logs at, defaults to 'error'",
"python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.",
"python.pipenvPath.description": "Path to the pipenv executable to use for activation.",
"python.poetryPath.description": "Path to the poetry executable.",
"python.sortImports.args.description": "Arguments passed in. Each argument is a separate item in the array.",
Expand All @@ -120,5 +123,42 @@
"python.venvFolders.description": "Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).",
"python.venvPath.description": "Path to folder with a list of Virtual Environments (e.g. ~/.pyenv, ~/Envs, ~/.virtualenvs).",
"python.sortImports.args.deprecationMessage": "This setting will be removed soon. Use 'isort.args' instead.",
"python.sortImports.path.deprecationMessage": "This setting will be removed soon. Use 'isort.path' instead."
"python.sortImports.path.deprecationMessage": "This setting will be removed soon. Use 'isort.path' instead.",
"walkthrough.pythonWelcome.title": "Get Started with Python Development",
"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!",
"walkthrough.step.python.createPythonFile.title": "Create a Python file",
"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)",
"walkthrough.step.python.installPythonWin8.title": "Install Python",
"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",
"walkthrough.step.python.installPythonMac.title": "Install Python",
"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",
"walkthrough.step.python.installPythonLinux.title": "Install Python",
"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",
"walkthrough.step.python.selectInterpreter.title": "Select a Python Interpreter",
"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).",
"walkthrough.step.python.createEnvironment.title": "Create a Python Environment ",
"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.",
"walkthrough.step.python.runAndDebug.title": "Run and debug your Python file",
"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)",
"walkthrough.step.python.learnMoreWithDS.title": "Explore more resources",
"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)",
"walkthrough.pythonDataScienceWelcome.title": "Get Started with Python for Data Science",
"walkthrough.pythonDataScienceWelcome.description": "Your first steps to getting started with a Data Science project with Python!",
"walkthrough.step.python.installJupyterExt.title": "Install Jupyter extension",
"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\")",
"walkthrough.step.python.createNewNotebook.title": "Create or open a Jupyter Notebook",
"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).",
"walkthrough.step.python.openInteractiveWindow.title": "Open the Python Interactive Window",
"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)",
"walkthrough.step.python.dataScienceLearnMore.title": "Find out more!",
"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)",
"walkthrough.step.python.createPythonFile.altText": "Open a Python file or a folder with a Python project.",
"walkthrough.step.python.selectInterpreter.altText": "Selecting a Python interpreter from the status bar",
"walkthrough.step.python.createEnvironment.altText": "Creating a Python environment from the Command Palette",
"walkthrough.step.python.runAndDebug.altText": "How to run and debug in VS Code with F5 or the play button on the top right.",
"walkthrough.step.python.learnMoreWithDS.altText": "Image representing our documentation page and mailing list resources.",
"walkthrough.step.python.installJupyterExt.altText": "Creating a new Jupyter notebook",
"walkthrough.step.python.createNewNotebook.altText": "Creating a new Jupyter notebook",
"walkthrough.step.python.openInteractiveWindow.altText": "Opening Python interactive window",
"walkthrough.step.python.dataScienceLearnMore.altText": "Image representing our documentation page and mailing list resources."
}
37 changes: 0 additions & 37 deletions pythonFiles/create_microvenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pathlib
import subprocess
import sys
import urllib.request as url_lib
from typing import Optional, Sequence

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

parser.add_argument(
"--install-pip",
action="store_true",
default=False,
help="Install pip into the virtual environment.",
)

parser.add_argument(
"--name",
default=VENV_NAME,
Expand All @@ -54,31 +46,6 @@ def create_microvenv(name: str):
)


def download_pip_pyz(name: str):
url = "https://bootstrap.pypa.io/pip/pip.pyz"
print("CREATE_MICROVENV.DOWNLOADING_PIP")

try:
with url_lib.urlopen(url) as response:
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
with open(pip_pyz_path, "wb") as out_file:
data = response.read()
out_file.write(data)
out_file.flush()
except Exception:
raise MicroVenvError("CREATE_MICROVENV.DOWNLOAD_PIP_FAILED")


def install_pip(name: str):
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
executable = os.fspath(CWD / name / "bin" / "python")
print("CREATE_MICROVENV.INSTALLING_PIP")
run_process(
[executable, pip_pyz_path, "install", "pip"],
"CREATE_MICROVENV.INSTALL_PIP_FAILED",
)


def main(argv: Optional[Sequence[str]] = None) -> None:
if argv is None:
argv = []
Expand All @@ -88,10 +55,6 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
create_microvenv(args.name)
print("CREATE_MICROVENV.CREATED_MICROVENV")

if args.install_pip:
download_pip_pyz(args.name)
install_pip(args.name)


if __name__ == "__main__":
main(sys.argv[1:])
60 changes: 51 additions & 9 deletions pythonFiles/create_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pathlib
import subprocess
import sys
import urllib.request as url_lib
from typing import List, Optional, Sequence, Union

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


def download_pip_pyz(name: str):
url = "https://bootstrap.pypa.io/pip/pip.pyz"
print("CREATE_VENV.DOWNLOADING_PIP")

try:
with url_lib.urlopen(url) as response:
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
with open(pip_pyz_path, "wb") as out_file:
data = response.read()
out_file.write(data)
out_file.flush()
except Exception:
raise VenvError("CREATE_VENV.DOWNLOAD_PIP_FAILED")


def install_pip(name: str):
pip_pyz_path = os.fspath(CWD / name / "pip.pyz")
executable = get_venv_path(name)
print("CREATE_VENV.INSTALLING_PIP")
run_process(
[executable, pip_pyz_path, "install", "pip"],
"CREATE_VENV.INSTALL_PIP_FAILED",
)


def main(argv: Optional[Sequence[str]] = None) -> None:
if argv is None:
argv = []
args = parse_args(argv)

use_micro_venv = False
if not is_installed("venv"):
venv_installed = is_installed("venv")
pip_installed = is_installed("pip")
ensure_pip_installed = is_installed("ensurepip")

if not venv_installed:
if sys.platform == "win32":
raise VenvError("CREATE_VENV.VENV_NOT_FOUND")
else:
use_micro_venv = True

pip_installed = is_installed("pip")
deps_needed = args.requirements or args.extras or args.toml
if deps_needed and not pip_installed and not use_micro_venv:
raise VenvError("CREATE_VENV.PIP_NOT_FOUND")

if venv_exists(args.name):
# A virtual environment with same name exists.
# We will use the existing virtual environment.
venv_path = get_venv_path(args.name)
print(f"EXISTING_VENV:{venv_path}")
else:
if use_micro_venv:
# `venv` was not found but on this platform we can use `microvenv`
run_process(
[
sys.executable,
os.fspath(MICROVENV_SCRIPT_PATH),
"--install-pip",
"--name",
args.name,
],
"CREATE_VENV.MICROVENV_FAILED_CREATION",
)
pip_installed = True
elif not pip_installed or not ensure_pip_installed:
# `venv` was found but `pip` or `ensurepip` was not found.
# We create a venv without `pip` in it. We will later install `pip`.
run_process(
[sys.executable, "-m", "venv", "--without-pip", args.name],
"CREATE_VENV.VENV_FAILED_CREATION",
)
else:
# Both `venv` and `pip` were found. So create a .venv normally
run_process(
[sys.executable, "-m", "venv", args.name],
"CREATE_VENV.VENV_FAILED_CREATION",
)

venv_path = get_venv_path(args.name)
print(f"CREATED_VENV:{venv_path}")

if args.git_ignore:
add_gitignore(args.name)

if pip_installed:
# At this point we have a .venv. Now we handle installing `pip`.
if pip_installed and ensure_pip_installed:
# We upgrade pip if it is already installed.
upgrade_pip(venv_path)
else:
# `pip` was not found, so we download it and install it.
download_pip_pyz(args.name)
install_pip(args.name)

if args.toml:
print(f"VENV_INSTALLING_PYPROJECT: {args.toml}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


# This test's id is double_nested_folder/nested_folder_one/nested_folder_two/test_nest.py::test_function.
# This test passes.
def test_function(): # test_marker--test_function
assert 1 == 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


# This test's id is dual_level_nested_folder/nested_folder_one/test_bottom_folder.py::test_bottom_function_t.
# This test passes.
def test_bottom_function_t(): # test_marker--test_bottom_function_t
assert True


# This test's id is dual_level_nested_folder/nested_folder_one/test_bottom_folder.py::test_bottom_function_f.
# This test fails.
def test_bottom_function_f(): # test_marker--test_bottom_function_f
assert False
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


# This test's id is dual_level_nested_folder/test_top_folder.py::test_top_function_t.
# This test passes.
def test_top_function_t(): # test_marker--test_top_function_t
assert True


# This test's id is dual_level_nested_folder/test_top_folder.py::test_top_function_f.
# This test fails.
def test_top_function_f(): # test_marker--test_top_function_f
assert False
7 changes: 7 additions & 0 deletions pythonFiles/tests/pytestadapter/.data/empty_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


# This file has no tests in it; the discovery will return an empty list of tests.
def function_function(string):
return string
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import pytest


# This test has an error which will appear on pytest discovery.
# This error is intentional and is meant to test pytest discovery error handling.
@pytest.mark.parametrize("actual,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])
def test_function():
assert True
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# This test has a syntax error.
# This error is intentional and is meant to test pytest discovery error handling.
def test_function()
assert True
10 changes: 10 additions & 0 deletions pythonFiles/tests/pytestadapter/.data/parametrize_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest


# Testing pytest with parametrized tests. The first two pass, the third fails.
# The tests ids are parametrize_tests.py::test_adding[3+5-8] and so on.
@pytest.mark.parametrize( # test_marker--test_adding
"actual, expected", [("3+5", 8), ("2+4", 6), ("6+9", 16)]
)
def test_adding(actual, expected):
assert eval(actual) == expected
7 changes: 7 additions & 0 deletions pythonFiles/tests/pytestadapter/.data/simple_pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


# This test passes.
def test_function(): # test_marker--test_function
assert 1 == 1
4 changes: 4 additions & 0 deletions pythonFiles/tests/pytestadapter/.data/text_docstring.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a doctest test which passes #test_marker--text_docstring.txt
>>> x = 3
>>> x
3
21 changes: 21 additions & 0 deletions pythonFiles/tests/pytestadapter/.data/unittest_folder/test_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import unittest


def add(a, b):
return a + b


class TestAddFunction(unittest.TestCase):
# This test's id is unittest_folder/test_add.py::TestAddFunction::test_add_positive_numbers.
# This test passes.
def test_add_positive_numbers(self): # test_marker--test_add_positive_numbers
result = add(2, 3)
self.assertEqual(result, 5)

# This test's id is unittest_folder/test_add.py::TestAddFunction::test_add_negative_numbers.
# This test passes.
def test_add_negative_numbers(self): # test_marker--test_add_negative_numbers
result = add(-2, -3)
self.assertEqual(result, -5)
Loading

0 comments on commit 2f16aae

Please sign in to comment.