From 28d3f241ef88a38aca664ba0085fe35ea386086f Mon Sep 17 00:00:00 2001 From: Nehal Patel Date: Mon, 24 Nov 2025 22:45:12 -0800 Subject: [PATCH] Restructure Python package to follow best practices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reorganize the Python emulator to follow Python Packaging Authority (PyPA) guidelines and the "src layout" pattern. This makes the package structure more professional, standard, and maintainable. Changes: - Move Python modules from src/ to src/host_emulator/ - Update package configuration in pyproject.toml with explicit package location - Update all imports from "from src import" to "from host_emulator import" - Maintain proper src layout to prevent accidental import of development version New structure: py/host-emulator/ ├── src/ │ └── host_emulator/ ← Proper package name (underscores for Python) │ ├── __init__.py │ ├── common.py │ ├── emulator.py │ ├── i2c.py │ ├── pin.py │ └── uart.py ├── tests/ └── pyproject.toml This structure follows: - PEP 420 (Implicit Namespace Packages) - PyPA packaging best practices - Src layout pattern for proper isolation All 29 tests continue to pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- py/host-emulator/pyproject.toml | 1 + py/host-emulator/src/{ => host_emulator}/__init__.py | 0 py/host-emulator/src/{ => host_emulator}/common.py | 0 py/host-emulator/src/{ => host_emulator}/emulator.py | 0 py/host-emulator/src/{ => host_emulator}/i2c.py | 0 py/host-emulator/src/{ => host_emulator}/pin.py | 0 py/host-emulator/src/{ => host_emulator}/uart.py | 0 py/host-emulator/tests/conftest.py | 3 +-- py/host-emulator/tests/test_blinky.py | 2 +- 9 files changed, 3 insertions(+), 3 deletions(-) rename py/host-emulator/src/{ => host_emulator}/__init__.py (100%) rename py/host-emulator/src/{ => host_emulator}/common.py (100%) rename py/host-emulator/src/{ => host_emulator}/emulator.py (100%) rename py/host-emulator/src/{ => host_emulator}/i2c.py (100%) rename py/host-emulator/src/{ => host_emulator}/pin.py (100%) rename py/host-emulator/src/{ => host_emulator}/uart.py (100%) diff --git a/py/host-emulator/pyproject.toml b/py/host-emulator/pyproject.toml index 59d352d..7e606e7 100644 --- a/py/host-emulator/pyproject.toml +++ b/py/host-emulator/pyproject.toml @@ -4,6 +4,7 @@ version = "0.1.0" description = "" authors = ["Nehal Patel "] readme = "README.md" +packages = [{include = "host_emulator", from = "src"}] [tool.poetry.dependencies] python = "^3.11" diff --git a/py/host-emulator/src/__init__.py b/py/host-emulator/src/host_emulator/__init__.py similarity index 100% rename from py/host-emulator/src/__init__.py rename to py/host-emulator/src/host_emulator/__init__.py diff --git a/py/host-emulator/src/common.py b/py/host-emulator/src/host_emulator/common.py similarity index 100% rename from py/host-emulator/src/common.py rename to py/host-emulator/src/host_emulator/common.py diff --git a/py/host-emulator/src/emulator.py b/py/host-emulator/src/host_emulator/emulator.py similarity index 100% rename from py/host-emulator/src/emulator.py rename to py/host-emulator/src/host_emulator/emulator.py diff --git a/py/host-emulator/src/i2c.py b/py/host-emulator/src/host_emulator/i2c.py similarity index 100% rename from py/host-emulator/src/i2c.py rename to py/host-emulator/src/host_emulator/i2c.py diff --git a/py/host-emulator/src/pin.py b/py/host-emulator/src/host_emulator/pin.py similarity index 100% rename from py/host-emulator/src/pin.py rename to py/host-emulator/src/host_emulator/pin.py diff --git a/py/host-emulator/src/uart.py b/py/host-emulator/src/host_emulator/uart.py similarity index 100% rename from py/host-emulator/src/uart.py rename to py/host-emulator/src/host_emulator/uart.py diff --git a/py/host-emulator/tests/conftest.py b/py/host-emulator/tests/conftest.py index 335a066..5d671d1 100644 --- a/py/host-emulator/tests/conftest.py +++ b/py/host-emulator/tests/conftest.py @@ -1,10 +1,9 @@ import pathlib import subprocess +from host_emulator import DeviceEmulator from pytest import fixture -from src import DeviceEmulator - def pytest_addoption(parser): parser.addoption( diff --git a/py/host-emulator/tests/test_blinky.py b/py/host-emulator/tests/test_blinky.py index c71f3c0..408740f 100644 --- a/py/host-emulator/tests/test_blinky.py +++ b/py/host-emulator/tests/test_blinky.py @@ -1,6 +1,6 @@ from time import sleep -from src import Pin +from host_emulator import Pin pin_stats = {}