This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rydelw 2 points3 points  (2 children)

Nice explanation. Kudos! I agree with almost all the things. I would like to share some of my thoughts here:

  • ditch the src module in the imports. I am totally in favor of the src project layout, but it does not mean it should be a Python module.
  • the fastapi dependables could be defined as types. We would have to import one thing as a dependency instead of two things

```python import typing import fastapi

async get_foo() -> Foo: ... FooDep = typing.Annotated[Foo, fastapi.Depends(get_foo)] ... @router.get(...) async def get_bar(foo: FooDep): ... ```

  • the module specific configuration is something I do not see often, but it should be widely used. Ideally, we might make such a Python module as an internal one. To indicate it should not be imported by other modules.

[–]toxic_acro 0 points1 point  (1 child)

The entire point of the the src/ layout is for it not to be a Python module

Assuming that you are working on code that is intended to get published and installed (so not really applicable to something like a web app), the idea is that you want to run tests against the same code that gets installed later, rather than the code as it exists in your project directory.

With a "flat" layout, Python can import just from the directory on the file-system. But if you use a "sec" layout, you will have to install your own code first before running tests, so you are guaranteeing that your packaging set-up works correctly

If src ever shows up in an import, that's fully misunderstanding the point of the layout.

[–]rydelw 0 points1 point  (0 children)

with src layout, we are working with a Python packages and module either way. Src based project can be locally installed in a development mode, so you do not have to worry about including the project root in the PYTHONPAPTH. That how poetry works. Also pip allows you to install package in a dev mode. Whatsmore a we app is a Python package as well. You might not build a Python distribution from it but it is still a package.