🌟 Python Init File Auto Builder
Automatically generate __init__.py from Python modules
Pythonファイルから自動的に __init__.py を生成するVS Code拡張機能
How to use / 使用方法
Right‑click the directory where you want to create __init__.py in File Explorer after installation.
From the context menu that appears, select “Generate init.py”.
インストール後エクスプロラーで__init__.pyを作成したいディレクトリで右クリック。
右クリックで出てきたメニューからGenerate __init__.pyを選択。
Badges / バッジ

Table of Contents / 目次
Overview / 概要
This VS Code extension analyzes Python files in a directory and automatically generates
a clean and consistent __init__.py containing:
from .module import ClassA, func_b
__all__ = [...]
指定ディレクトリ内のPythonファイルを解析し、
クラス名・関数名を抽出して __init__.py を自動生成します。
Prerequisites / 事前準備
Install Node.js from the official website.
開発前にNode.jsをインストールしてください。
Required Packages / 必要パッケージ
- Yeoman (
yo)
- VS Code Extension Generator (
generator-code)
Installation Example (Windows)
npm install -g yo
npm install -g generator-code
Development Environment / 開発環境
- Windows 11 Pro
- Visual Studio Code
- TypeScript 5.x
Directory Structure / ディレクトリ構成
workspace/
├─ .vscode/ # VS Code workspace settings
├─ node_modules/ # Dependencies (not included in repo)
├─ out/ # Compiled JavaScript output
├─ src/ # Extension source code
│ ├─ generator/ # **init**.py generator
│ └─ parser/ # Python parser
├─ icon.png # Extension icon
├─ package.json # Extension metadata
├─ package.nls.json # English localization
├─ package.nls.ja.json # Japanese localization
├─ examples # Sample Python code
└─ LICENSE.txt # GPLv3 license
Source Code Details / ソースコード詳細
src/generator/initGenerator.ts
Generates __init__.py based on parsed Python files.
Pythonファイルを解析し、import文と __all__ を生成します。
graph TD
A[Start generateInitPy] --> B[Read .py files]
B --> C[Parse each file]
C --> D{Has classes or functions?}
D -->|Yes| E[Add import statement]
E --> F[Add names to __all__]
D -->|No| C
F --> G[Sort imports and names]
G --> H[Write __init__.py]
H --> I[End]
src/parser/pythonParser.ts
Extracts class and function names using regex.
正規表現でクラス名・関数名を抽出します。
graph TD
A[Start parsePythonFile]
B[Read file content]
C[Define classRegex]
D[Define funcRegex]
E[Init arrays]
F{classRegex.exec}
G[Push class name]
H{funcRegex.exec}
I[Push function name]
J[Return result]
K[End]
A --> B
B --> C
C --> D
D --> E
E --> F
F -->|Match| G
G --> F
F -->|No match| H
H -->|Match| I
I --> H
H -->|No match| J
J --> K
Debugging / デバッグ起動
Install dependencies / 依存関係をインストールする
npm install
Build TypeScript / TypeScriptのビルド
npm run compile
Run Debug / デバック起動
Press F5 in VS Code.
F5を押下。
Packaging / 配布用パッケージング
Install vsce / インストールvsce
npm install -g @vscode/vsce
Create package / パッケージ生成
vsce package
License / ライセンス
This extension is licensed under GNU GPLv3.
本拡張機能は GNU GPLv3 ライセンスで提供されています。
End of Document.