Skip to content

pdm init with --cookiecutter does git init in the wrong directory? #3721

@cr1901

Description

@cr1901

Describe the bug

When pdm init is run using a cookiecutter template, pdm will do git init in the working directory, instead of the directory that cookiecutter created to instantiate the template. Nominally, the directory that cookiecutter just created is the source root, not the working directory where pdm was invoked.

To reproduce

In an empty directory, do, for example: pdm init --cookiecutter gh:cr1901/amaranth-cookiecutter --no-input.

William@DESKTOP-3H1DSBV MINGW64 /tmp/pdm-test
$ pdm init --cookiecutter gh:cr1901/amaranth-cookiecutter --no-input
Creating a pyproject.toml for PDM...
INFO: Git repository initialized successfully.
Project is initialized successfully

William@DESKTOP-3H1DSBV MINGW64 /tmp/pdm-test
$ ls -la
total 1800
drwxr-xr-x 1 William None 0 Jan 13 19:29 .
drwxr-xr-x 1 William None 0 Jan 13 19:12 ..
drwxr-xr-x 1 William None 0 Jan 13 19:29 .git
drwxr-xr-x 1 William None 0 Jan 13 19:29 amaranth_ip

amarnath_ip is the package source code root, containing the src/, tests/, pyproject.toml, and

Expected Behavior

Since the starting working directory is not actually the project root when --cookiecutter is used, pdm should traverse down to the just-created directory from the cookiecutter invocation and do git init there.

Environment Information

(Notice that I had to traverse down a directory from my starting directory for pdm info to work)

William@DESKTOP-3H1DSBV MINGW64 /tmp/pdm-test
$ cd amaranth_ip/

William@DESKTOP-3H1DSBV MINGW64 /tmp/pdm-test/amaranth_ip
$ pdm info && pdm info --env
WARNING: Project requires a python version of >=3.9, The virtualenv is being created for you as it cannot be matched to the right
version.
INFO: python.use_venv is on, creating a virtualenv for this project...
Virtualenv is created successfully at C:/msys64/tmp/pdm-test/amaranth_ip/.venv
PDM version:
  2.26.4
Python Interpreter:
  C:/msys64/tmp/pdm-test/amaranth_ip/.venv/bin/python.exe (3.12)
Project Root:
  C:/msys64/tmp/pdm-test/amaranth_ip
Local Packages:
  C:/msys64/tmp/pdm-test/amaranth_ip/.venv/lib/python3.12/site-packages
{
  "implementation_name": "cpython",
  "implementation_version": "3.12.12",
  "os_name": "nt",
  "platform_machine": "AMD64",
  "platform_release": "10",
  "platform_system": "Windows",
  "platform_version": "10.0.19045",
  "python_full_version": "3.12.12",
  "platform_python_implementation": "CPython",
  "python_version": "3.12",
  "sys_platform": "win32"
}

Verbose Command Output

No change from non-verbose command output.

William@DESKTOP-3H1DSBV MINGW64 /tmp/pdm-test
$ pdm -v init -v --cookiecutter gh:cr1901/amaranth-cookiecutter --no-input
Creating a pyproject.toml for PDM...
INFO: Git repository initialized successfully.
Project is initialized successfully

Additional Context

Since cookiecutter will always create a subdirectory, I believe this could be fixed by modifying initialize_git to be cookiecutter-aware?

I.e. "if pdm init was invoked with cookiecutter, traverse into the directory returned by cookiecutter.main and do git init there.

A fix should also probably mention in the --help that the --cookiecutter option always creates a subdirectory, whereas pdm's built-in generator always uses the current directory.

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions