-
Notifications
You must be signed in to change notification settings - Fork 2.4k
poetry init --author multiple authors fix #8864 #10402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8b7774b
f9560f6
1435fd5
5d560b3
50d8255
5ef1cfd
822977b
b73a800
cd86c50
a3d78bf
4a9bcae
47f5700
beb255d
77d1aba
804f599
a809d76
370af9d
b9b7f78
cb44c4c
a63b679
cf74799
5b56b89
e4f1426
d4ed6db
ec37cb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -40,7 +40,9 @@ class InitCommand(Command): | |||||||||
| options: ClassVar[list[Option]] = [ | ||||||||||
| option("name", None, "Name of the package.", flag=False), | ||||||||||
| option("description", None, "Description of the package.", flag=False), | ||||||||||
| option("author", None, "Author name of the package.", flag=False), | ||||||||||
| option( | ||||||||||
| "author", None, "Author name of the package.", flag=False, multiple=True | ||||||||||
| ), | ||||||||||
| option("python", None, "Compatible Python versions.", flag=False), | ||||||||||
| option( | ||||||||||
| "dependency", | ||||||||||
|
|
@@ -148,21 +150,28 @@ def _init_pyproject( | |||||||||
| if not description and is_interactive: | ||||||||||
| description = self.ask(self.create_question("Description []: ", default="")) | ||||||||||
|
|
||||||||||
| author = self.option("author") | ||||||||||
| if not author and vcs_config.get("user.name"): | ||||||||||
| authors = self.option("author") | ||||||||||
| if not authors and vcs_config.get("user.name"): | ||||||||||
| author = vcs_config["user.name"] | ||||||||||
| author_email = vcs_config.get("user.email") | ||||||||||
| if author_email: | ||||||||||
| author += f" <{author_email}>" | ||||||||||
| authors = [author] | ||||||||||
|
|
||||||||||
| if is_interactive: | ||||||||||
| author_str = ", ".join(authors) | ||||||||||
| question = self.create_question( | ||||||||||
| f"Author [<comment>{author}</comment>, n to skip]: ", default=author | ||||||||||
| f"Author [<comment>{author_str}</comment>, n to skip]: ", | ||||||||||
| default=author_str, | ||||||||||
| ) | ||||||||||
| question.set_validator(lambda v: self._validate_author(v, author)) | ||||||||||
| question.set_validator(lambda v: self._validate_author(v, authors)) | ||||||||||
| author = self.ask(question) | ||||||||||
| if author == author_str: # user entered nothing, dont change authors | ||||||||||
| author = "" | ||||||||||
| else: | ||||||||||
| authors = author | ||||||||||
|
|
||||||||||
| authors = [author] if author else [] | ||||||||||
| authors = authors if authors else [] | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Replace if-expression with
Suggested change
ExplanationHere we find ourselves setting a value if it evaluates toTrue, and otherwiseusing a default. The 'After' case is a bit easier to read and avoids the duplication of It works because the left-hand side is evaluated first. If it evaluates to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Replace if-expression with
Suggested change
ExplanationHere we find ourselves setting a value if it evaluates toTrue, and otherwiseusing a default. The 'After' case is a bit easier to read and avoids the duplication of It works because the left-hand side is evaluated first. If it evaluates to |
||||||||||
|
|
||||||||||
| license_name = self.option("license") | ||||||||||
| if not license_name and is_interactive: | ||||||||||
|
|
@@ -237,7 +246,7 @@ def _init_pyproject( | |||||||||
| name, | ||||||||||
| version, | ||||||||||
| description=description, | ||||||||||
| author=authors[0] if authors else None, | ||||||||||
| author=authors if authors else None, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Replace if-expression with
Suggested change
ExplanationHere we find ourselves setting a value if it evaluates toTrue, and otherwiseusing a default. The 'After' case is a bit easier to read and avoids the duplication of It works because the left-hand side is evaluated first. If it evaluates to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Replace if-expression with
Suggested change
ExplanationHere we find ourselves setting a value if it evaluates toTrue, and otherwiseusing a default. The 'After' case is a bit easier to read and avoids the duplication of It works because the left-hand side is evaluated first. If it evaluates to |
||||||||||
| readme_format=readme_format, | ||||||||||
| license=license_name, | ||||||||||
| python=python, | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -63,7 +63,7 @@ def __init__( | |||||
| version: str = "0.1.0", | ||||||
| description: str = "", | ||||||
| readme_format: str = "md", | ||||||
| author: str | None = None, | ||||||
| author: str | list[str] | None = None, | ||||||
| license: str | None = None, | ||||||
| python: str | None = None, | ||||||
| dependencies: Mapping[str, str | Mapping[str, Any]] | None = None, | ||||||
|
|
@@ -85,9 +85,11 @@ def __init__( | |||||
| self._dev_dependencies = dev_dependencies or {} | ||||||
|
|
||||||
| if not author: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Prefer checking for None over falsy author Use
Suggested change
|
||||||
| author = "Your Name <you@example.com>" | ||||||
|
|
||||||
| self._author = author | ||||||
| self._authors = ["Your Name <you@example.com>"] | ||||||
| elif isinstance(author, str): # check if only 1 author was added | ||||||
| self._authors = [author] | ||||||
| else: | ||||||
| self._authors = author | ||||||
|
|
||||||
| @property | ||||||
| def basedir(self) -> Path: | ||||||
|
|
@@ -143,15 +145,16 @@ def generate_project_content(self) -> TOMLDocument: | |||||
| project_content["name"] = self._project | ||||||
| project_content["version"] = self._version | ||||||
| project_content["description"] = self._description | ||||||
| m = AUTHOR_REGEX.match(self._author) | ||||||
| if m is None: | ||||||
| # This should not happen because author has been validated before. | ||||||
| raise ValueError(f"Invalid author: {self._author}") | ||||||
| else: | ||||||
| author = {"name": m.group("name")} | ||||||
| if email := m.group("email"): | ||||||
| author["email"] = email | ||||||
| project_content["authors"].append(author) | ||||||
| for author_string in self._authors: # Iterate through the list of authors | ||||||
| m = AUTHOR_REGEX.match(author_string) | ||||||
| if m is None: | ||||||
| # This should not happen because author has been validated before. | ||||||
| raise ValueError(f"Invalid author: {author_string}") | ||||||
| else: | ||||||
| author = {"name": m.group("name")} | ||||||
| if email := m.group("email"): | ||||||
| author["email"] = email | ||||||
| project_content["authors"].append(author) | ||||||
|
|
||||||
| if self._license: | ||||||
| project_content["license"]["text"] = self._license | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
authoris not used after this line. Why do we set it here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not introduce a new
--authorsflag for multiple authors?