Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Python Init File Auto BuilderNew to Visual Studio Code? Get it now.
Python Init File Auto Builder

Python Init File Auto Builder

taka-labs

|
27 installs
| (0) | Free
Generate __init__.py automatically from .py files
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

🌟 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 / バッジ

VS Code Extension TypeScript License: GPLv3


Table of Contents / 目次

  • 🌟 Python Init File Auto Builder
    • How to use / 使用方法
    • Badges / バッジ
    • Table of Contents / 目次
    • Overview / 概要
    • Prerequisites / 事前準備
    • Required Packages / 必要パッケージ
      • Installation Example (Windows)
    • Development Environment / 開発環境
    • Directory Structure / ディレクトリ構成
    • Source Code Details / ソースコード詳細
      • src/generator/initGenerator.ts
      • src/parser/pythonParser.ts
    • Debugging / デバッグ起動
      • Install dependencies / 依存関係をインストールする
      • Build TypeScript / TypeScriptのビルド
      • Run Debug / デバック起動
    • Packaging / 配布用パッケージング
      • Install vsce / インストールvsce
      • Create package / パッケージ生成
    • License / ライセンス

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.


  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft