Skip to content

Docs: clarify how to proceed after setup steps #301

Closed

Description

@maxalbert

Hi @DavidVujic, first of all huge thanks for introducing the Polylith architecture to the Python community and for your invaluable work on the related tooling.

Describe the bug

I recently discovered the Polylith architecture and read up about its concepts in the Clojure-focused GitBook and in your Python-focused documentation.

I wanted to try it out with a hands-on example and followed the steps in the Setup section (using uv) to create a minimal Polylith workspace.

However, I struggled to get the development workflow going in the way I expected. I'm unsure if my expectations were wrong or if some crucial steps are missing in the setup documentation to get to a fully functioning development project.

To Reproduce

Note: for reference, a repo with the workspace structure resulting from the steps below is available here.

Start in an empty directory and make sure that python and uv are available. I'm using the following versions:

$ python --version
Python 3.13.0

$ uv --version
uv 0.4.30

Then follow the steps in the setup guide:

$ uv init --name=polylith-bug-report
$ uv add --dev polylith-cli
$ uv add --dev ipython  # optional, for convenience

$ uv run poly create workspace --name bug_report --theme loose

Now edit pyproject.toml according to the instructions here by adding the following sections:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build]
dev-mode-dirs = ["components", "bases", "development", "."]

Finally, run:

$ uv sync

Expected behavior

At this stage, I expected to be able to enter a Python console and import the bug_report module. However:

$ python -c "import bug_report"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import bug_report
ModuleNotFoundError: No module named 'bug_report'

It turns out that if I create a new component then the import does work:

$ uv run poly create component --name dummy

$ python -c "import bug_report; print(bug_report is not None)"
True

However, this is quite nonintuitive. It actually took me quite a few attempts of debugging and experimenting with different things to realise that this was all that's needed.

I'm still not sure if I'm missing any further setup steps, for example in order to get the development project fully set up and working. I have included a couple of my open questions below.

Desktop (please complete the following information):

  • OS: Mac OS 10.14.6
  • Python version: 3.13.0
  • Uv version: 0.4.30

Additional context / Further questions

As indicated above, I'm not sure whether completing the setup steps is sufficient for a fully working Polylith workspace. Open questions:

  1. The docs section on Projects & pyproject.toml mentions that the project-specific pyproject.toml files need hatch-polylith-bricks as an additional build system dependency, and also require the section [tool.hatch.build.hooks.polylith-bricks] to be present (even if it is empty). Is this also necessary to set up the development project in the toplevel pyproject.toml file?

  2. Do I need to run poly sync to complete the workspace setup? If I do this (after creating the dummy component above), the following section is added to the toplevel pyproject.toml file:

    [tool.polylith.bricks]
     "components/bug_report/dummy" = "bug_report/dummy"

    However, I think that I can import new components (and presumably bases, although I haven't tried this) without this section being present. Does it make a difference?

Many thanks for reading and any clarifications!

Activity

  1. DavidVujic commented on Nov 28, 2024

    @DavidVujic
    Owner

    Hi @maxalbert, thank you for the detailed report! ⭐

    I think that the bug_report import fails because there isn't any source code added into the environment at that point. I think that it will be the same issue in a non-polylith scenario. It would explain why the importing works after creating a component: when python code is added into the repo. Note that you will need to have an activated virtual environment, or running the command within a uv run context.

    I should probably clarify this part in the docs.

    The open questions:

    1. no, the development pyproject.toml should not contain the Hatch build hook. The Build hook is for packaging individual projects (building wheels).
    2. Running poly sync is optional, and it will add any missing components or bases to the development project. It will also add missing components to the projects, if there is a base importing it.
  2. DavidVujic commented on Nov 28, 2024

    @DavidVujic
    Owner

    I have added a new sub-section called Next stepsin the Setup section of the docs, that I hope clarifies the install and setup flow: https://davidvujic.github.io/python-polylith-docs/setup/#next-steps

  3. DavidVujic commented on Nov 28, 2024

    @DavidVujic
    Owner

    (I will move this to Discussions and Q&A)

  4. Repository owner locked and limited conversation to collaborators on Nov 28, 2024
  5. converted this issue into a discussion #303 on Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions