Skip to content

fix hatchling source path detection#45

Open
alexrashed wants to merge 2 commits intomainfrom
fix-hatchling
Open

fix hatchling source path detection#45
alexrashed wants to merge 2 commits intomainfrom
fix-hatchling

Conversation

@alexrashed
Copy link
Copy Markdown
Member

Motivation

plux has just recently built out an integration with hatchling.
When using plux with localstack-core, I was facing some issues with plux failing on a KeyError when trying to detect the package path:

. .venv/bin/activate; python -m plux entrypoints
entry point build mode: manual
discovering plugins and writing to .../plux.ini ...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File ".../.venv/lib/python3.13/site-packages/plux/__main__.py", line 13, in <module>
    main()
    ~~~~^^
  File ".../.venv/lib/python3.13/site-packages/plux/__main__.py", line 9, in main
    cli.main(argv)
    ~~~~~~~~^^^^^^
  File ".../.venv/lib/python3.13/site-packages/plux/cli/cli.py", line 183, in main
    args.func(args)
    ~~~~~~~~~^^^^^^
  File ".../.venv/lib/python3.13/site-packages/plux/cli/cli.py", line 58, in entrypoints
    builder.write(fd, output_format="ini")
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/index.py", line 42, in write
    ep = discover_entry_points(self.plugin_finder)
  File ".../.venv/lib/python3.13/site-packages/plux/core/entrypoint.py", line 34, in discover_entry_points
    return to_entry_point_dict([spec_to_entry_point(spec) for spec in finder.find_plugins()])
                                                                      ~~~~~~~~~~~~~~~~~~~^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/discovery.py", line 175, in find_plugins
    return collector.find_plugins()
           ~~~~~~~~~~~~~~~~~~~~~~^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/discovery.py", line 226, in find_plugins
    for module in self.modules:
                  ^^^^^^^^^^^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/discovery.py", line 183, in _load_modules
    for module_name in self._list_module_names():
                       ~~~~~~~~~~~~~~~~~~~~~~~^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/discovery.py", line 200, in _list_module_names
    for pkg in self.finder.find_packages():
               ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/hatchling.py", line 118, in find_packages
    self.path, relative_package_path
    ^^^^^^^^^
  File ".../.venv/lib/python3.13/site-packages/plux/build/hatchling.py", line 147, in path
    if self.builder_config.sources[""]:
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
KeyError: ''
make: *** [Makefile:76: entrypoints] Error 1

Changes

  • path property now correctly derives the different ways how Hatchling's sources dict maps can be set.
  • find_packages - changes how paths in hatchling are relative to the project root (not the source root)

@alexrashed alexrashed marked this pull request as ready for review March 26, 2026 13:44
@alexrashed alexrashed requested review from dfangl and thrau as code owners March 26, 2026 13:44
return where
return root

# No "" key. The keys themselves are source directories (e.g. "localstack-core/").
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add here another check or TODO what happens if there is a value - so not just a source dir stripping, but a true rename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants