Skip to content
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

feat: add option --lib to init command to create a library project #1708

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1708.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Introduce `--lib` option to `init` command to create a library project without prompting.
11 changes: 6 additions & 5 deletions src/pdm/cli/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--backend", choices=list(_BACKENDS), help="Specify the build backend"
)
parser.add_argument(
"--lib", action="store_true", help="Create a library project"
)
parser.set_defaults(search_parent=False)

def handle(self, project: Project, options: argparse.Namespace) -> None:
Expand Down Expand Up @@ -102,15 +105,13 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
"For more info, please visit https://peps.python.org/pep-0582/",
style="success",
)
is_library = (
termui.confirm(
is_library = options.lib
if not is_library and self.interactive:
is_library = termui.confirm(
"Is the project a library that is installable?\n"
"A few more questions will be asked to include a project name "
"and build backend"
)
if self.interactive
else False
)
build_backend: type[BuildBackend] | None = None
if is_library:
name = self.ask("Project name", project.root.name)
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/cli/completions/pdm.bash
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ _pdm_a919b69078acdf0a_complete()
;;

(init)
opts="--backend --global --help --non-interactive --project --python --skip --verbose"
opts="--backend --global --help --lib --non-interactive --project --python --skip --verbose"
;;

(install)
Expand Down
1 change: 1 addition & 0 deletions src/pdm/cli/completions/pdm.fish
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from info' -l where -d 'Show the p
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l backend -d 'Specify the build backend'
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l global -d 'Use the global project, supply the project root with `-p` option'
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l help -d 'show this help message and exit'
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l lib -d 'Create a library project'
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l non-interactive -d 'Don\'t ask questions but use default values'
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l project -d 'Specify another path as the project root, which changes the base of pyproject.toml and __pypackages__'
complete -c pdm -A -n '__fish_seen_subcommand_from init' -l python -d 'Specify the Python version/path to use'
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/cli/completions/pdm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function TabExpansion($line, $lastWord) {
"init" {
$completer.AddOpts(
@(
[Option]::new(@("-g", "--global", "--non-interactive", "-n", "--python")),
[Option]::new(@("-g", "--global", "--non-interactive", "-n", "--python", "--lib")),
$projectOption,
$skipOption,
[Option]::new(@("--backend")).WithValues(@("pdm-backend", "setuptools", "flit", "hatching", "pdm-pep517"))
Expand Down
1 change: 1 addition & 0 deletions src/pdm/cli/completions/pdm.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ _pdm() {
{-n,--non-interactive}"[Don't ask questions but use default values]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
'--backend[Specify the build backend]:backend:(pdm-backend setuptools hatchling flit pdm-pep517)'
'--lib[Create a library project]'
'--python[Specify the Python version/path to use]:python:'
)
;;
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def style(text: str, *args: str, style: str | None = None, **kwargs: Any) -> str
return capture.get()


def confirm(*args: str, **kwargs: Any) -> str:
def confirm(*args: str, **kwargs: Any) -> bool:
kwargs.setdefault("default", False)
return Confirm.ask(*args, **kwargs)

Expand Down