pdm icon indicating copy to clipboard operation
pdm copied to clipboard

Initialise project directory with git if available and use git name and email for pyproject.toml

Open doolio opened this issue 2 years ago • 9 comments

doolio avatar Aug 31 '23 09:08 doolio

The title description is unclear, and git username and email are already supported.

frostming avatar Sep 01 '23 01:09 frostming

Apologies for being unclear. I meant if git is available on a users machine to execute git init as part of pdm init. Right now pdm init just produces a .gitignore file. I think it would be great if it also initialised the project directory as a vcs (git but perhaps others as well) repository.

As for whether git's user.name and user.email values are supported it does not seem to be if one has defined their user.email in separate .gitconfig files via git's includeif feature. See below. Perhaps, I'm unusual in doing this.

image

I hope this is clearer. Thanks for your time.

doolio avatar Sep 01 '23 07:09 doolio

As for whether git's user.name and user.email values are supported it does not seem to be if one has defined their user.email in separate .gitconfig files via git's includeif feature.

But if I execute git init inside a project directory I see the user.email value I expect which implies it is only available when the directory is a git respository.

image

doolio avatar Sep 01 '23 08:09 doolio

Well, indeed, you include the config that sets the user.email only when the current repository (.git) matches the **/github pattern. I'm not sure to understand what else you would expect?

  • current repo is named github: user.email is set, PDM can use it
  • current dir is not a repo: user.email is not set, PDM can't use it

Also, even if PDM runs git init, it would probably do so at the end, so the user.email setting would still not be available during the generation of pyproject.toml. Unless I'm missing something. I'm not particularly familiar with these Git features :slightly_smiling_face:

pawamoy avatar Sep 01 '23 09:09 pawamoy

current repo is named github

No, the repo is named pdm-demo but it is within a directory named github. All projects I may work on that are hosted on github have their repositories within this github directory. I have a similar directory for gitlab hosted projects etc. My git configuration

image

is such that if a project repo is a subdirectory of the github directory then git's user.email is set to the commit email I wish to use for github. Similarly, if the project repo is a subdirectory of the gitlab directory then git's user.email is set to the commit email I wish to use for gitlab etc. The convenience is I don't need to remember to correctly configure git's user.email setting for projects that may be hosted on different forges provided I create the repo in the respective github or gitlab directories. One could use the same strategy to separate work and personal projects and ensure the correct commit username and email is applied.

See the git scm book for more details.

current dir is not a repo: user.email is not set, PDM can't use it

Right. My suggestion was for PDM to execute git init as part of pdm init and as you state it would need to do so first so it is sure to have a user.email setting when not set globally.

doolio avatar Sep 01 '23 09:09 doolio

Thanks for the explanation, that's a nice, convenient setup indeed :slightly_smiling_face:

IMO PDM shouldn't bother with adding an option to run git init. It's easy enough to run it yourself :shrug:

git init project
pdm init -np project

But that's just my opinion!

pawamoy avatar Sep 01 '23 10:09 pawamoy

Fair enough. It is something that rye does which I thought was a convenient feature.

doolio avatar Sep 01 '23 10:09 doolio

I am not sure I understand your request. When I run pdm init -n, the default template is filled as below. The authors field is already filled with my git username and email. Is it perhaps because I am using pdm with cookiecutter as an extra dependency?

[project]
name = "test"
version = "0.1.0"
description = "Default template for PDM package"
authors = [
    {name = "baggiponte", email = "[email protected]"},
]
dependencies = []
requires-python = "==3.10.*"
readme = "README.md"
license = {text = "MIT"}

[tool.pdm]
package-type = "application"

baggiponte avatar Dec 29 '23 14:12 baggiponte

The authors field is already filled with my git username and email.

Right, but not only if these are set globally. I have these set differently depending on which forge (GitHub, GitLab etc.) the project I'm working on is hosted.

doolio avatar Dec 29 '23 14:12 doolio