Python Main RunnerA Visual Studio Code extension that makes it easier to run Python projects with multiple entry points. Python projects often contain multiple files with:
However, VS Code's default Run Python File button only runs the currently opened file. Python Main Runner scans your workspace for Python entry points and allows you to quickly select and run any of them without opening the file first. Features
ExampleGiven this project:
With:
|
| Command | Description |
|---|---|
Run Python Main |
Runs the currently selected Python entry point |
Select Python Main |
Opens a list of detected Python entry points |
How It Works
Python Main Runner:
- Searches the workspace for
.pyfiles. - Reads each Python file.
- Detects the following pattern:
if __name__ == "__main__":
- Adds matching files to the available entry point list.
- Runs the selected file in a VS Code terminal.
Development
Clone the repository:
git clone <repository-url>
cd python-main-runner
Install dependencies:
npm install
Compile the extension:
npm run compile
Start development mode:
npm run watch
Then press:
F5
inside VS Code to launch the Extension Development Host.
Packaging
Install the VS Code Extension Manager:
npm install -g @vscode/vsce
Create a .vsix package:
vsce package
Install locally:
code --install-extension python-main-runner-x.x.x.vsix
Project Structure
python-main-runner/
│
├── src/
│ └── extension.ts
│
├── package.json
├── tsconfig.json
├── README.md
└── node_modules/
Future Improvements
Possible improvements:
- Use the VS Code selected Python interpreter instead of system
python - Support debugging selected entry points
- Allow command-line arguments
- Add run profiles
- Improve Python parsing using the Python AST
- Add workspace-specific configurations