pythonpython-poetry

Poetry No File/Folder for Package


I have a simple project layout

myproject on ī‚  main [$!?] is šŸ“¦ v1.0.0 via īœ˜ v18.14.0 via šŸ v3.10.9 
āÆ tree -L 1
.
ā”œā”€ā”€ build
ā”œā”€ā”€ deploy
ā”œā”€ā”€ Dockerfile
ā”œā”€ā”€ poetry.lock
ā”œā”€ā”€ pyproject.toml
ā”œā”€ā”€ README.md
ā”œā”€ā”€ scripts.py
ā””ā”€ā”€ src

The pyproject.toml is:

[tool.poetry]
name = "myproject"
version = "0.1.0"
description = ""
authors = [""]

[tool.poetry.scripts]
test = "scripts:test"

The scripts.py is:

import subprocess

def test():
    """
    Run all unittests.
    
    """
    subprocess.run(
        ['python', '-u', '-m', 'pytest']
    )
if __name__ == '__main__':
    test()

When I run poetry run test:

myproject on main [$!?] is šŸ“¦ v1.0.0 via īœ˜ v18.14.0 via šŸ v3.10.9


No file/folder found for package myproject

Solution

  • Short answer:

    The directory where your pyproject.toml file sits needs to be share the same name, e.g., if the name config in pyproject.toml is name = "myproject", the directory needs to be also named myproject. Therefore, you must either:

    1. Rename the directory to match your name configuration in the pyproject.toml or
    2. Move the pyproject.toml file to the correct directory or
    3. If you don't care about making your project packageable by Poetry and only use poetry as your package manager for this project, add package-mode = false to your pyproject.toml.

    Explanation:

    There's a thread on the official GitHub for Poetry that discusses this issue. The gist of the issue is that whatever you choose for your project name, i.e., name = "myproject", needs to be the direct parent directory of where your pyproject.toml file lives. When there is a mismatch, you get the error you are getting.

    Sources: