Compare commits
	
		
			10 Commits
		
	
	
		
			e0924bf561
			...
			6271f413a0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6271f413a0 | |||
| 
						 | 
					e351212b72 | ||
| 
						 | 
					df4601984c | ||
| 
						 | 
					c74127a70b | ||
| 
						 | 
					92d3f79252 | ||
| 
						 | 
					b6dff129ff | ||
| 
						 | 
					0c1547cfd8 | ||
| 
						 | 
					be9b057025 | ||
| 
						 | 
					1bc90ceb6c | ||
| 
						 | 
					484807cbe6 | 
@@ -1,30 +0,0 @@
 | 
			
		||||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.202.3/containers/python-3/.devcontainer/base.Dockerfile
 | 
			
		||||
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
 | 
			
		||||
ARG VARIANT=3-bullseye
 | 
			
		||||
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
 | 
			
		||||
 | 
			
		||||
# [Optional] Allow the vscode user to pip install globally w/o sudo
 | 
			
		||||
ENV PIP_TARGET=/usr/local/pip-global
 | 
			
		||||
ENV PYTHONPATH=${PIP_TARGET}:${PYTHONPATH}
 | 
			
		||||
ENV PATH=${PIP_TARGET}/bin:${PATH}
 | 
			
		||||
RUN if ! cat /etc/group | grep -e "^pip-global:" > /dev/null 2>&1; then groupadd -r pip-global; fi \
 | 
			
		||||
    && usermod -a -G pip-global vscode \
 | 
			
		||||
    && umask 0002 && mkdir -p ${PIP_TARGET} \
 | 
			
		||||
    && chown :pip-global ${PIP_TARGET} \
 | 
			
		||||
    && ( [ ! -f "/etc/profile.d/00-restore-env.sh" ] || sed -i -e "s/export PATH=/export PATH=\/usr\/local\/pip-global:/" /etc/profile.d/00-restore-env.sh )
 | 
			
		||||
 | 
			
		||||
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
 | 
			
		||||
ARG NODE_VERSION="none"
 | 
			
		||||
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
 | 
			
		||||
 | 
			
		||||
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
 | 
			
		||||
# COPY requirements.txt /tmp/pip-tmp/
 | 
			
		||||
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
 | 
			
		||||
#    && rm -rf /tmp/pip-tmp
 | 
			
		||||
 | 
			
		||||
# [Optional] Uncomment this section to install additional OS packages.
 | 
			
		||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
 | 
			
		||||
#     && apt-get -y install --no-install-recommends <your-package-list-here>
 | 
			
		||||
 | 
			
		||||
# [Optional] Uncomment this line to install global node packages.
 | 
			
		||||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
 | 
			
		||||
@@ -1,73 +1,20 @@
 | 
			
		||||
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
 | 
			
		||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.3/containers/python-3
 | 
			
		||||
{
 | 
			
		||||
	"name": "Python 3",
 | 
			
		||||
	"build": {
 | 
			
		||||
		"dockerfile": "Dockerfile",
 | 
			
		||||
		"context": "..",
 | 
			
		||||
		"args": { 
 | 
			
		||||
			// Update 'VARIANT' to pick a Python version: 3, 3.9, 3.8, 3.7, 3.6.
 | 
			
		||||
			// Append -bullseye or -buster to pin to an OS version.
 | 
			
		||||
			// Use -bullseye variants on local on arm64/Apple Silicon.
 | 
			
		||||
			"VARIANT": "3.9-bullseye",
 | 
			
		||||
			// Options
 | 
			
		||||
			"NODE_VERSION": "lts/*"
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
		
 | 
			
		||||
	// Configure tool-specific properties.
 | 
			
		||||
	"image": "mcr.microsoft.com/devcontainers/python:1-3.12",
 | 
			
		||||
	"customizations": {
 | 
			
		||||
		// Configure properties specific to VS Code.
 | 
			
		||||
		"vscode": {
 | 
			
		||||
			// Set *default* container specific settings.json values on container create.
 | 
			
		||||
			"settings": { 
 | 
			
		||||
				"terminal.integrated.profiles.linux": {
 | 
			
		||||
					"bash": {
 | 
			
		||||
						"path": "/bin/bash"
 | 
			
		||||
					}
 | 
			
		||||
				},
 | 
			
		||||
				"python.defaultInterpreterPath": "/usr/local/bin/python",
 | 
			
		||||
				"python.languageServer": "Default",
 | 
			
		||||
				"python.linting.enabled": true,
 | 
			
		||||
				"python.linting.pylintEnabled": true,
 | 
			
		||||
				"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
 | 
			
		||||
				"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
 | 
			
		||||
				"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
 | 
			
		||||
				"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
 | 
			
		||||
				"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
 | 
			
		||||
				"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
 | 
			
		||||
				"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
 | 
			
		||||
				"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
 | 
			
		||||
				"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
 | 
			
		||||
			},
 | 
			
		||||
			
 | 
			
		||||
			// Add the IDs of extensions you want installed when the container is created.
 | 
			
		||||
			"settings": {},
 | 
			
		||||
			"extensions": [
 | 
			
		||||
				"ms-python.python",
 | 
			
		||||
				"ms-python.vscode-pylance"
 | 
			
		||||
				"streetsidesoftware.code-spell-checker"
 | 
			
		||||
			]
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
 | 
			
		||||
	// "forwardPorts": [9000],
 | 
			
		||||
 | 
			
		||||
	// Use 'portsAttributes' to set default properties for specific forwarded ports. More info: https://code.visualstudio.com/docs/remote/devcontainerjson-reference.
 | 
			
		||||
	"portsAttributes": {
 | 
			
		||||
		"9000": {
 | 
			
		||||
			"label": "Hello Remote World",
 | 
			
		||||
			"onAutoForward": "notify"
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	// Use 'otherPortsAttributes' to configure any ports that aren't configured using 'portsAttributes'.
 | 
			
		||||
	// "otherPortsAttributes": {
 | 
			
		||||
	// 		"onAutoForward": "silent"
 | 
			
		||||
	// },
 | 
			
		||||
 | 
			
		||||
	// Use 'postCreateCommand' to run commands after the container is created.
 | 
			
		||||
	"postCreateCommand": "pip3 install -r requirements.txt",
 | 
			
		||||
 | 
			
		||||
	// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
 | 
			
		||||
	"remoteUser": "vscode"
 | 
			
		||||
	"postAttachCommand": "python app.py"
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								.gitea/workflows/dependabot.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.gitea/workflows/dependabot.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
# For more details, see https://containers.dev/guide/dependabot
 | 
			
		||||
version: 2
 | 
			
		||||
updates:
 | 
			
		||||
  - package-ecosystem: "devcontainers"
 | 
			
		||||
    directory: "/"
 | 
			
		||||
    schedule:
 | 
			
		||||
      interval: weekly
 | 
			
		||||
							
								
								
									
										21
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,21 +0,0 @@
 | 
			
		||||
    MIT License
 | 
			
		||||
 | 
			
		||||
    Copyright (c) Microsoft Corporation. All rights reserved.
 | 
			
		||||
 | 
			
		||||
    Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
    of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
    in the Software without restriction, including without limitation the rights
 | 
			
		||||
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
    copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
    furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
    The above copyright notice and this permission notice shall be included in all
 | 
			
		||||
    copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
    SOFTWARE
 | 
			
		||||
							
								
								
									
										108
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								README.md
									
									
									
									
									
								
							@@ -1,103 +1,17 @@
 | 
			
		||||
# Try Out Development Containers: Python
 | 
			
		||||
# base
 | 
			
		||||
 | 
			
		||||
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-python)
 | 
			
		||||
Python 项目工程模板
 | 
			
		||||
 | 
			
		||||
A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Remote - Containers](https://aka.ms/vscode-remote/containers)**.
 | 
			
		||||
## 使用方法
 | 
			
		||||
 | 
			
		||||
This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too.
 | 
			
		||||
```
 | 
			
		||||
make
 | 
			
		||||
./fork
 | 
			
		||||
make clean
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
> **Note:** If you already have a codespace or dev container, you can jump to the [Things to try](#things-to-try) section. 
 | 
			
		||||
### 版权说明
 | 
			
		||||
 | 
			
		||||
## Setting up the development container
 | 
			
		||||
Copyright @ Mengning Software 
 | 
			
		||||
 | 
			
		||||
### GitHub Codespaces
 | 
			
		||||
Follow these steps to open this sample in a Codespace:
 | 
			
		||||
1. Click the Code drop-down menu and select the **Open with Codespaces** option.
 | 
			
		||||
1. Select **+ New codespace** at the bottom on the pane.
 | 
			
		||||
 | 
			
		||||
For more information on creating your codespace, visit the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
 | 
			
		||||
 | 
			
		||||
### VS Code Remote - Containers
 | 
			
		||||
 | 
			
		||||
If you already have VS Code and Docker installed, you can click the badge above or [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-python) to get started. Clicking these links will cause VS Code to automatically install the Remote - Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
 | 
			
		||||
 | 
			
		||||
Follow these steps to open this sample in a container using the VS Code Remote - Containers extension:
 | 
			
		||||
 | 
			
		||||
1. If this is your first time using a development container, please ensure your system meets the prerequisites (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
 | 
			
		||||
 | 
			
		||||
2. To use this repository, you can either open the repository in an isolated Docker volume:
 | 
			
		||||
 | 
			
		||||
    - Press <kbd>F1</kbd> and select the **Remote-Containers: Try a Sample...** command.
 | 
			
		||||
    - Choose the "Python" sample, wait for the container to start, and try things out!
 | 
			
		||||
        > **Note:** Under the hood, this will use the **Remote-Containers: Clone Repository in Container Volume...** command to clone the source code in a Docker volume instead of the local filesystem. [Volumes](https://docs.docker.com/storage/volumes/) are the preferred mechanism for persisting container data.   
 | 
			
		||||
 | 
			
		||||
   Or open a locally cloned copy of the code:
 | 
			
		||||
 | 
			
		||||
   - Clone this repository to your local filesystem.
 | 
			
		||||
   - Press <kbd>F1</kbd> and select the **Remote-Containers: Open Folder in Container...** command.
 | 
			
		||||
   - Select the cloned copy of this folder, wait for the container to start, and try things out!
 | 
			
		||||
 | 
			
		||||
## Things to try
 | 
			
		||||
 | 
			
		||||
Once you have this sample opened, you'll be able to work with it like you would locally.
 | 
			
		||||
 | 
			
		||||
> **Note:** This container runs as a non-root user with sudo access by default. Comment out `"remoteUser": "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root.
 | 
			
		||||
 | 
			
		||||
Some things to try:
 | 
			
		||||
 | 
			
		||||
1. **Edit:**
 | 
			
		||||
   - Open `app.py`
 | 
			
		||||
   - Try adding some code and check out the language features.
 | 
			
		||||
 | 
			
		||||
2. **Terminal:** 
 | 
			
		||||
    - Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> to open a terminal window.
 | 
			
		||||
    - Type `python -m flask run --port 9000 --no-debugger --no-reload` to run the app.
 | 
			
		||||
         - The terminal will say your app is `Running on http://127.0.0.1:9000/`. Click on the link in the terminal to view your app running in the browser.
 | 
			
		||||
    - Notice that the Python extension is already installed in the container since the `.devcontainer/devcontainer.json` lists `"ms-python.python"` as an extension to install automatically when the container is created.
 | 
			
		||||
    
 | 
			
		||||
      > **Tip:** If you use this container outside of VS Code via `docker run` with `-p 9000`, you may need to append `--host 0.0.0.0` to the command above. The `-p` option "publishes" the port rather than forwarding it. It therefore will not work if the application only listens to localhost. The `forwardPorts` property in `devcontainer.json` does not have this limitation, but you can use `appPort` property instead if you want to mirror the `docker run` behavior.
 | 
			
		||||
 | 
			
		||||
3. **Build, Run, and Debug:**
 | 
			
		||||
   - Open `app.py`
 | 
			
		||||
   - Add a breakpoint (e.g. on line 9).
 | 
			
		||||
   - Press <kbd>F5</kbd> to launch the app in the container.
 | 
			
		||||
   - Once the breakpoint is hit, try hovering over variables (e.g. the app variable on line 7), examining locals, and more.
 | 
			
		||||
   - Continue (<kbd>F5</kbd>). You can connect to the server in the container by either: 
 | 
			
		||||
      - Clicking on `Open in Browser` in the notification telling you: `Your service running on port 9000 is available`.
 | 
			
		||||
      - Clicking the globe icon in the 'Ports' view. The 'Ports' view gives you an organized table of your forwarded ports, and you can access it with the command **Ports: Focus on Ports View**.
 | 
			
		||||
   - Notice port 9000 in the 'Ports' view is labeled "Hello Remote World." In `devcontainer.json`, you can set `"portsAttributes"`, such as a label for your forwarded ports and the action to be taken when the port is autoforwarded.
 | 
			
		||||
   
 | 
			
		||||
   > **Note:** In Remote - Containers, you can access your app at `http://localhost:9000` in a local browser. But in a browser-based Codespace, you must click the link from the notification or the `Ports` view so that the service handles port forwarding in the browser and generates the correct URL.
 | 
			
		||||
 | 
			
		||||
4. **Rebuild or update your container**
 | 
			
		||||
 | 
			
		||||
   You may want to make changes to your container, such as installing a different version of a software or forwarding a new port. You'll rebuild your container for your changes to take effect. 
 | 
			
		||||
 | 
			
		||||
   **Open browser automatically:** As an example change, let's update the `portsAttributes` in the `.devcontainer/devcontainer.json` file to open a browser when our port is automatically forwarded.
 | 
			
		||||
   
 | 
			
		||||
   - Open the `.devcontainer/devcontainer.json` file.
 | 
			
		||||
   - Modify the `"onAutoForward"` attribute in your `portsAttributes` from `"notify"` to `"openBrowser"`.
 | 
			
		||||
   - Press <kbd>F1</kbd> and select the **Remote-Containers: Rebuild Container** or **Codespaces: Rebuild Container** command so the modifications are picked up.  
 | 
			
		||||
 | 
			
		||||
### More samples
 | 
			
		||||
 | 
			
		||||
- [Tweeter App - Python and Django](https://github.com/Microsoft/python-sample-tweeterapp)
 | 
			
		||||
 | 
			
		||||
## Contributing
 | 
			
		||||
 | 
			
		||||
This project welcomes contributions and suggestions.  Most contributions require you to agree to a
 | 
			
		||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
 | 
			
		||||
the rights to use your contribution. For details, visit https://cla.microsoft.com.
 | 
			
		||||
 | 
			
		||||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
 | 
			
		||||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
 | 
			
		||||
provided by the bot. You will only need to do this once across all repos using our CLA.
 | 
			
		||||
 | 
			
		||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
 | 
			
		||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
 | 
			
		||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
 | 
			
		||||
 | 
			
		||||
## License
 | 
			
		||||
 | 
			
		||||
Copyright © Microsoft Corporation All rights reserved.<br />
 | 
			
		||||
Licensed under the MIT License. See LICENSE in the project root for license information.
 | 
			
		||||
梦宁软件(江苏)有限公司 版权所有
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								app.py
									
									
									
									
									
								
							@@ -1,11 +1,14 @@
 | 
			
		||||
#-----------------------------------------------------------------------------------------
 | 
			
		||||
# Copyright (c) Microsoft Corporation. All rights reserved.
 | 
			
		||||
# Licensed under the MIT License. See LICENSE in the project root for license information.
 | 
			
		||||
#-----------------------------------------------------------------------------------------
 | 
			
		||||
# 简单的加法计算器
 | 
			
		||||
 | 
			
		||||
from flask import Flask
 | 
			
		||||
app = Flask(__name__)
 | 
			
		||||
def add_numbers(a, b):
 | 
			
		||||
    """计算两个数字的和"""
 | 
			
		||||
    return a + b
 | 
			
		||||
 | 
			
		||||
@app.route("/")
 | 
			
		||||
def hello():
 | 
			
		||||
    return app.send_static_file("index.html")
 | 
			
		||||
# 获取用户输入
 | 
			
		||||
print("简单的加法计算器")
 | 
			
		||||
num1 = float(input("请输入第一个数字: "))
 | 
			
		||||
num2 = float(input("请输入第二个数字: "))
 | 
			
		||||
 | 
			
		||||
# 计算并输出结果
 | 
			
		||||
result = add_numbers(num1, num2)
 | 
			
		||||
print(f"{num1} + {num2} = {result}")
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
flask
 | 
			
		||||
@@ -1,9 +0,0 @@
 | 
			
		||||
<html>
 | 
			
		||||
    <head>
 | 
			
		||||
        <title>VS Code Rocks!</title>
 | 
			
		||||
    </head>
 | 
			
		||||
    <body>
 | 
			
		||||
        <h1>VS Code can do that?</h1>
 | 
			
		||||
        <p>Yes it can!</p>
 | 
			
		||||
    </body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user