Unexpected Behavior: `poetry new .` Acts Like `poetry init` Without Creating Project Structure
Description
Unexpected Behavior: poetry new . Acts Like poetry init Without Creating Project Structure
Description
Running poetry new . inside a newly created and empty directory behaves like poetry init, rather than creating the expected full project structure. This behavior is undocumented and may be confusing to users expecting the typical src/ and tests/ layout.
Steps to Reproduce
> mkdir test-poetry
> cd test-poetry
> poetry new .
> ls
Actual Output
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 6/13/2025 7:24 PM 391 pyproject.toml
Expected Output
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 6/13/2025 7:53 PM src
d----- 6/13/2025 7:53 PM tests
-a---- 6/13/2025 7:53 PM 379 pyproject.toml
-a---- 6/13/2025 7:53 PM 0 README.md
Or alternatively, a clear error indicating that creating a project in . is not supported.
Discussion
This behavior appears to be an undocumented overlap between poetry new and poetry init. The resulting project is incomplete (no src/, tests/, or README.md). Additionally, poetry init does not support the --src flag, creating a functional gap.
Suggested Solutions
- Document the current behavior explicitly in the CLI help and documentation.
- Raise an error when
poetry new .is used, similar to how it errors on non-empty directories. - Update behavior so that
poetry new .generates a full project scaffold in the current directory.
Environment
- OS: Windows 10 Pro
- Poetry version: 2.1.3
If this behavior is intentional, it would be helpful to document it explicitly under poetry new usage
Workarounds
To mitigate this error today you need to use poetry new <project_name> in the parent directory.
Poetry Installation Method
install.python-poetry.org
Operating System
Windows 10 Pro
Poetry Version
Poetry (version 2.1.3)
Poetry Configuration
cache-dir = "C:\\Users\\Szymon BUAS\\AppData\\Local\\pypoetry\\Cache"
data-dir = "C:\\Users\\Szymon BUAS\\AppData\\Roaming\\pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
python.installation-dir = "{data-dir}\\python" # C:\Users\Szymon BUAS\AppData\Roaming\pypoetry\python
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs" # C:\Users\Szymon BUAS\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false
Python Sysconfig
sysconfig.log
Platform: "win-amd64"
Python version: "3.12"
Current installation scheme: "nt"
Paths:
data = "C:\Users\Szymon BUAS\miniconda3"
include = "C:\Users\Szymon BUAS\miniconda3\Include"
platinclude = "C:\Users\Szymon BUAS\miniconda3\Include"
platlib = "C:\Users\Szymon BUAS\miniconda3\Lib\site-packages"
platstdlib = "C:\Users\Szymon BUAS\miniconda3\Lib"
purelib = "C:\Users\Szymon BUAS\miniconda3\Lib\site-packages"
scripts = "C:\Users\Szymon BUAS\miniconda3\Scripts"
stdlib = "C:\Users\Szymon BUAS\miniconda3\Lib"
Variables:
BINDIR = "C:\Users\Szymon BUAS\miniconda3"
BINLIBDEST = "C:\Users\Szymon BUAS\miniconda3\Lib"
EXE = ".exe"
EXT_SUFFIX = ".cp312-win_amd64.pyd"
INCLUDEPY = "C:\Users\Szymon BUAS\miniconda3\Include"
LIBDEST = "C:\Users\Szymon BUAS\miniconda3\Lib"
TZPATH = "C:\Users\Szymon BUAS\miniconda3\share\zoneinfo"
VERSION = "312"
VPATH = "..\.."
abiflags = ""
base = "C:\Users\Szymon BUAS\miniconda3"
exec_prefix = "C:\Users\Szymon BUAS\miniconda3"
installed_base = "C:\Users\Szymon BUAS\miniconda3"
installed_platbase = "C:\Users\Szymon BUAS\miniconda3"
platbase = "C:\Users\Szymon BUAS\miniconda3"
platlibdir = "DLLs"
prefix = "C:\Users\Szymon BUAS\miniconda3"
projectbase = "C:\Users\Szymon BUAS\miniconda3"
py_version = "3.12.4"
py_version_nodot = "312"
py_version_nodot_plat = "312"
py_version_short = "3.12"
srcdir = "C:\Users\Szymon BUAS\miniconda3"
userbase = "C:\Users\Szymon BUAS\AppData\Roaming\Python"
Example pyproject.toml
Poetry Runtime Logs
poetry-runtime.log
Loading configuration file C:\Users\Szymon BUAS\AppData\Roaming\pypoetry\config.toml
[findpython:findpython] Running script: ['C:\\Users\\Szymon BUAS\\miniconda3\\python.EXE', '-EsSc', 'import sys; print(sys.executable)']
Found: C:\Users\Szymon BUAS\miniconda3\python.EXE
[findpython:findpython] Running script: ['C:\\Users\\Szymon BUAS\\miniconda3\\python.EXE', '-EsSc', 'import platform; print(platform.python_version())']
poetry new is cautious and does not do much if the path that you give it already exists. . already exists.
I expect a pull request documenting this would be welcome.
@dimbleby thanks for the reply. I took a quick glance at the code for the new and init and can see this is indeed intended behavior. I'll try to submit a PR with a documentation over the weekend/next week.
Actually, I do not think that this is wanted behavior but just a result of the implementation reusing code between poetry new and poetry init.
poetry new fails anyway if the directory is not empty:
https://github.com/python-poetry/poetry/blob/01955bbf46176a701da719c970ae8084951efa8a/src/poetry/console/commands/new.py#L75-L79
Thus, it should always be safe to create the project structure. Either the directory does not exist or it is empty. However, poetry new and poetry init share the code to create the pyproject.toml and project structure:
https://github.com/python-poetry/poetry/blob/01955bbf46176a701da719c970ae8084951efa8a/src/poetry/console/commands/init.py#L87-L93
https://github.com/python-poetry/poetry/blob/01955bbf46176a701da719c970ae8084951efa8a/src/poetry/console/commands/init.py#L248-L251
Thus, I would consider this a valid bug that should be fixed. If you want to give it a try, you should pay attention that only poetry new creates the project structure in an empty directory and not poetry init.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.