Skip to content

Support package projects with src-layout #58

@lemonyte

Description

@lemonyte

I have an ASGI app project with the following src-layout file structure:

project_name
├── config.toml
├── pyproject.toml
├── wrangler.toml
└── src
    ├── package_name
    │   ├── __init__.py
    │   ├── server.py
    │   ├── ...
    │   ├── subpackage_name
    │   │   └── __init__.py
    │   ├── data
    │   │   └── data.json
    │   ├── static
    │   │   └── styles.css
    │   └── templates
    │       └── index.html
    ├── js-stubs
    │   └── __init__.pyi
    └── worker.py

During runtime, it needs to read files in subdirectories of the package (e.g. data, templates), and files in the current working directory (e.g. config.toml).

If I put worker.py inside the package and import the ASGI app, it fails because package_name is not installed as a package, so Python doesn't know how to import neighbouring files.

If I put worker.py at the top level, I need to import from src, which defeats the point of the src-layout.

If I put worker.py under src, the imports work fine, but none of the top-level files are accessible.

Is there a way to make pywrangler build and install the project along with its dependencies (e.g. when a build system is defined)?
What would be the best place to put worker.py in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions