From 0715db599ae7c3090f5b72adf7a204f8b61aa865 Mon Sep 17 00:00:00 2001 From: Chuck Lantz Date: Fri, 19 Apr 2019 13:47:02 -0700 Subject: [PATCH] Rev python example --- .devcontainer/devcontainer.json | 1 + .vscode/launch.json | 4 +-- README.md | 52 +++++++++++++++++++++++++-------- index.html | 9 ++++++ hello.py => server.py | 11 ++++++- 5 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 index.html rename hello.py => server.py (58%) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7fdd974..438d7c7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,7 @@ { "name": "Python Sample", "dockerFile": "Dockerfile", + "appPort": 9000, "context": "..", "extensions": [ "ms-python.python", diff --git a/.vscode/launch.json b/.vscode/launch.json index 1298fb1..b02d7c4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,10 +5,10 @@ "version": "0.2.0", "configurations": [ { - "name": "Python: Current File (Integrated Terminal)", + "name": "Launch Server", "type": "python", "request": "launch", - "program": "${file}", + "program": "${workspaceFolder}/server.py", "console": "integratedTerminal" } ] diff --git a/README.md b/README.md index 670ba24..62d3968 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,48 @@ -# Python Sample Project for Visual Studio Remote - Containers +# Try Out Development Containers: Python -This is a sample project to go along with the "try" quick start for the VS Code Remote - Containers extension. +This is a sample project to go along with the "try" quick start for the **[VS Code Remote - Containers](https://aka.ms/vscode-remote/containers)** extension. -Using the sample: +**If you aren't already following the quick start, [see here](#setting-up-the-development-container).** -1. **[Windows]** Disable automatic line ending conversion for Git on the *Windows side* (given Linux and Windows use different line endings). Run: `git config --global core.autocrlf false` -2. Follow the steps at [https://aka.ms/vscode-remote/containers/getting-started](https://aka.ms/vscode-remote/containers/getting-started). -3. Open `hello.py`, launch the program, edit, and try things out! +## Things to try + +One you have this sample opened in a container, you'll be able to work with it like you would locally. + +Some things to try: + +1. **Edit:** + 1. Open `server.py` + 2. Try adding some code and check out the language features. +2. **Terminal:** Press ctrl+shift+\` and type `uname` and or other Linux commands from the terminal window. +2. **Build, Run, and Debug:** + 1. Open `sever.py` + 2. Add a breakpoint. + 3. Press F5 to launch the app in the container. + 4. Open a local browser and go to `http://localhost:9000` and note you can connect to the server in the container. + 5. Once the breakpoint is hit, try hovering over variables, examining locals, and more. +3. **Forward another port:** + 1. Stop debugging + 2. Open `sever.py` + 3. Change the server port to 5000. (`PORT = 5000`) + 4. Press F5 to launch the app in the container. + 5. Press F1 and run the **Remote-Containers: Forward Port...** command. + 6. Select port 5000. + 7. Click "Open Browser" in the notification that appears to access the web app on this new port. + +## Setting up the development container + +Follow these steps to open this sample in a container: + +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to get set up. + +2. If you're not yet in a development container: + 1. Clone this repository. + 2. Press F1 and select the **Remote-Container: Open Folder in Container...** command. + 3. Select the cloned copy of this folder, wait for the container to start, and try things out! + +### More samples -Other samples and dev container definitions: - [Tweeter App - Python and Django](https://github.com/Microsoft/python-sample-tweeterapp) -- Dev container definitions with sample content - - [Python 3](https://github.com/Microsoft/vscode-dev-containers/tree/master/containers/python-3) - - [Python 3 - Anaconda](https://github.com/Microsoft/vscode-dev-containers/tree/master/containers/python-3-anaconda) - - [Python 3 - Miniconda](https://github.com/Microsoft/vscode-dev-containers/tree/master/containers/python-3-miniconda) - - [Python 3 & Posgres](https://github.com/Microsoft/vscode-dev-containers/tree/master/containers/python-3-posgres) ## Contributing diff --git a/index.html b/index.html new file mode 100644 index 0000000..ea0d532 --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + VS Code Rocks! + + +

VS Code can do that?

+

Yes it can!

+ + \ No newline at end of file diff --git a/hello.py b/server.py similarity index 58% rename from hello.py rename to server.py index 7136310..7550e31 100644 --- a/hello.py +++ b/server.py @@ -3,4 +3,13 @@ # Licensed under the MIT License. See LICENSE in the project root for license information. #----------------------------------------------------------------------------------------- -print('Hello, remote world!') \ No newline at end of file +import socketserver +import http.server + +RequestHandler = http.server.SimpleHTTPRequestHandler + +PORT = 5000 + +with socketserver.TCPServer(("", PORT), RequestHandler) as httpd: + print("Server runnong on port", PORT) + httpd.serve_forever() \ No newline at end of file