Skip to content

Releases: alelom/python-package-folder

Added support for automated versioning number

02 Mar 17:30

Choose a tag to compare

Several fixes and improvements

02 Dec 16:32

Choose a tag to compare

Fix: Add file exclusion patterns to prevent non-package files in distributions

When building subfolders as separate packages, the tool was including
unnecessary files from the project root (e.g., .cursor/, .github/, .vscode/,
data/, docs/, references/, reports/, scripts/, Dockerfile, etc.) in the
published distribution.

This fix adds comprehensive file exclusion patterns to the temporary
pyproject.toml created for subfolder builds using hatchling's paths-exclude
configuration. The exclusions cover:

  • IDE/config directories: .cursor/, .github/, .vscode/, .idea/
  • Non-package directories: data/, docs/, references/, reports/, scripts/, tests/
  • Build artifacts: dist/, build/, *.egg-info/, pycache/, .pytest_cache/
  • Other files: Dockerfile, .gitignore, .gitattributes, .pylintrc, etc.

The exclusion patterns are added in both code paths:

  1. When creating a temporary pyproject.toml from the parent
  2. When using an existing subfolder pyproject.toml

Changes:

  • Added [tool.hatch.build] section with paths-exclude to subfolder_build.py
  • Updated _modify_pyproject_string() to include exclusions
  • Updated _adjust_subfolder_pyproject_packages_path() to include exclusions
  • Added unit tests to verify exclusion patterns are present

Tests:

  • Added test_file_exclusion_patterns_added() to verify exclusions when
    creating from parent pyproject.toml
  • Added test_file_exclusion_patterns_with_subfolder_pyproject() to verify
    exclusions when subfolder has its own pyproject.toml
  • All 114 tests pass

This ensures that only the intended package code is included in the
distribution, preventing bloated packages with unnecessary files.


Fix: Use only-include to prevent non-package files in subfolder distributions

When building subfolders as separate packages, the published tar.gz files
were including unnecessary files from the project root (e.g., .cursor/,
.github/, .vscode/, data/, docs/, references/, reports/, scripts/,
Dockerfile, etc.) instead of only the subfolder code.

The initial fix attempted to use paths-exclude in [tool.hatch.build], but
this approach didn't work because hatchling was still including files from
the project root during source distribution builds.

Solution:

  • Replaced paths-exclude with only-include in [tool.hatch.build.targets.sdist]
  • Explicitly include only the subfolder directory and necessary files:
    • The subfolder package directory (e.g., "src/integration/empty_drawing_detection")
    • pyproject.toml
    • README files (README.md, README.rst, README.txt, README)

Changes:

  • Updated _modify_pyproject_string() to use only-include for sdist targets
  • Updated _adjust_subfolder_pyproject_packages_path() to use only-include
  • Updated unit tests to verify only-include configuration instead of paths-exclude
  • Both code paths (parent pyproject.toml and subfolder pyproject.toml) now use only-include

Testing:

  • Updated test_file_exclusion_patterns_added() to verify only-include
  • Updated test_file_exclusion_patterns_with_subfolder_pyproject() to verify only-include
  • All 114 tests pass

This ensures that only the intended package code is included in the
distribution, preventing bloated packages with unnecessary project root files.


Fix: Convert absolute imports of copied dependencies to relative imports

When building subfolders as separate packages, external dependencies are
copied into the subfolder. However, the original files in the subfolder
still use absolute imports (e.g., from _shared.image_utils import ...),
which fail when the package is installed because those modules are now
part of the package and should be imported relatively.

This fix automatically converts absolute imports of copied dependencies
to relative imports during the build process for subfolder builds:

  • from _shared.image_utils import ...from ._shared.image_utils import ...
  • import _globalsfrom . import _globals
  • Only modifies imports of copied dependencies, not stdlib or third-party
  • Only modifies files in the original subfolder, not the copied dependency files
  • Restores original imports after build completes

Changes:

  • Added _convert_copied_dependency_imports_to_relative() method to BuildManager
  • Uses AST parsing for accurate import detection and modification
  • Tracks modified files in _modified_import_files dictionary
  • Restores original imports in cleanup() method
  • Integrated into prepare_build() for subfolder builds only

Testing:

  • Added test_convert_copied_dependency_imports_to_relative() unit test
  • Verifies imports are converted to relative format
  • Verifies stdlib imports are not modified
  • Verifies original imports are restored after cleanup
  • All 115 tests pass

This ensures that published subfolder packages can correctly import their
copied dependencies when installed, fixing ModuleNotFoundError issues.


Fix import handling for subfolder builds with copied dependencies

This commit addresses two import issues that occur when building
subfolder packages with external dependencies:

  1. Fix relative imports in copied dependency files:

    • When external dependencies are copied into the subfolder, their
      relative imports (e.g., from ._shared.shared_dataclasses) break
      because the file structure changes
    • Added _fix_relative_imports_in_copied_files() to convert these
      relative imports to absolute imports based on the target location
  2. Convert local file imports to relative:

    • Imports of local files within the subfolder (e.g., from detect_empty_drawings_utils import ...) need to be converted to
      relative imports (e.g., from .detect_empty_drawings_utils import ...)
    • Updated _convert_imports_to_relative() (renamed from
      _convert_copied_dependency_imports_to_relative) to handle both
      copied dependencies and local files

The implementation:

  • Fixes relative imports in copied files first (converts to absolute)
  • Then converts absolute imports of both copied dependencies and local
    files to relative imports in the subfolder's original files
  • Tracks all modified files and restores them during cleanup

This resolves ImportError issues like "attempted relative import with
no known parent package" that occurred when published packages tried
to import copied dependencies.

Tests updated to verify both behaviors.


Full Changelog: v3.0.2...v3.1.3

Make directories recognizable as Python packages, allowing type checkers to resolve imports and type annotations

27 Nov 18:07

Choose a tag to compare

Print the temporary pyproject.toml content for debugging

27 Nov 16:09

Choose a tag to compare

Preserve the original directory structure when copying external depencies

27 Nov 15:47

Choose a tag to compare

Enhanced file resolution in analyzer.py

27 Nov 11:59

Choose a tag to compare

Updated resolve_local_import() to check nested subdirectories (up to 2 levels deep) when searching for local files
Finds files in paths like src/data/spreadsheet_creation/spreadsheet_formatting_dataclasses.py
Checks all subdirectories of parent directories, not just common ones like _shared
Stricter dependency extraction in manager.py:
Only adds ambiguous imports as dependencies if they can be verified as installed packages
If an import can't be verified as a package, it's skipped (likely a local file that wasn't resolved)
Prevents adding local files as third-party dependencies
Added tests:
Created tests/test_spreadsheet_creation_imports.py to verify files in nested subdirectories are correctly identified as external dependencies and copied, not added as third-party packages

Full Changelog: v2.0.6...v2.0.7

Add _shared to identifiers

27 Nov 11:42

Choose a tag to compare

Added more logging info

26 Nov 18:37

Choose a tag to compare

Add third-party dependency detection and inclusion for subfolder builds

26 Nov 18:24

Choose a tag to compare

  • Extract third-party dependencies from all Python files (including copied external dependencies)
  • Add dependencies to temporary pyproject.toml's [project.dependencies] section
  • Handle cases where dependencies aren't installed in build environment by treating ambiguous imports as third-party
  • Add test to verify third-party dependencies are correctly added
  • Fix test cleanup assertion to account for pre-existing files

Full Changelog: v1.4.1...v2.0.4

Only publish target package/folder, not all of its dependencies

25 Nov 10:37

Choose a tag to compare