diff --git a/news/2978.feature.md b/news/2978.feature.md new file mode 100644 index 0000000000..64f44edcfc --- /dev/null +++ b/news/2978.feature.md @@ -0,0 +1 @@ +Add `--license` and `--project-version` as CLI options to control and streamline them during `pdm init` - especially in automated scenarios with `--non-interactive` \ No newline at end of file diff --git a/src/pdm/cli/commands/init.py b/src/pdm/cli/commands/init.py index 71590bccbb..027c44d7f2 100644 --- a/src/pdm/cli/commands/init.py +++ b/src/pdm/cli/commands/init.py @@ -107,7 +107,7 @@ def get_metadata_from_input(self, project: Project, options: argparse.Namespace) from pdm.formats.base import array_of_inline_tables, make_array, make_inline_table name = self.ask_project(project) - version = self.ask("Project version", "0.1.0") + version = self.ask("Project version", options.project_version or "0.1.0") is_dist = options.dist or bool(options.backend) if not is_dist and self.interactive: is_dist = termui.confirm( @@ -139,7 +139,7 @@ def get_metadata_from_input(self, project: Project, options: argparse.Namespace) else: description = "" default_python_requires = f"=={python.major}.{python.minor}.*" - license = self.ask("License(SPDX name)", "MIT") + license = self.ask("License(SPDX name)", options.license or "MIT") git_user, git_email = get_user_email_from_git() author = self.ask("Author name", git_user) @@ -201,6 +201,8 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None: "--dist", "--lib", dest="dist", action="store_true", help="Create a package for distribution" ) group.add_argument("--backend", choices=list(_BACKENDS), help="Specify the build backend, which implies --dist") + group.add_argument("--license", help="Specify the license (SPDX name)") + group.add_argument("--project-version", help="Specify the project's version") parser.add_argument( "template", nargs="?", help="Specify the project template, which can be a local path or a Git URL" ) diff --git a/src/pdm/cli/completions/pdm.bash b/src/pdm/cli/completions/pdm.bash index c65ad16421..d31a39212e 100644 --- a/src/pdm/cli/completions/pdm.bash +++ b/src/pdm/cli/completions/pdm.bash @@ -1,7 +1,7 @@ # BASH completion script for pdm # Generated by pycomplete 0.4.0 -_pdm_a919b69078acdf0a_complete() +_pdm_fd45d3342570d348_complete() { local cur script coms opts com COMPREPLY=() @@ -65,7 +65,7 @@ _pdm_a919b69078acdf0a_complete() ;; (init) - opts="--backend --cookiecutter --copier --dist --global --help --non-interactive --overwrite --project --python --quiet --skip --verbose" + opts="--backend --cookiecutter --copier --dist --global --help --license --non-interactive --overwrite --project --project-version --python --quiet --skip --verbose" ;; (install) @@ -155,4 +155,4 @@ _pdm_a919b69078acdf0a_complete() fi } -complete -o default -F _pdm_a919b69078acdf0a_complete pdm +complete -o default -F _pdm_fd45d3342570d348_complete pdm diff --git a/src/pdm/cli/completions/pdm.fish b/src/pdm/cli/completions/pdm.fish index c38fd9c904..1f626e3ce1 100644 --- a/src/pdm/cli/completions/pdm.fish +++ b/src/pdm/cli/completions/pdm.fish @@ -1,7 +1,7 @@ # FISH completion script for pdm # Generated by pycomplete 0.4.0 -function __fish_pdm_a919b69078acdf0a_complete_no_subcommand +function __fish_pdm_fd45d3342570d348_complete_no_subcommand for i in (commandline -opc) if contains -- $i add build cache completion config export fix import info init install list lock outdated plugin publish py python remove run search self show sync update use venv return 1 @@ -11,18 +11,18 @@ function __fish_pdm_a919b69078acdf0a_complete_no_subcommand end # global options -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l config -d 'Specify another config file path [env var: PDM_CONFIG_FILE] ' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l help -d 'Show this help message and exit.' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l ignore-python -d 'Ignore the Python path saved in .pdm-python. [env var: PDM_IGNORE_SAVED_PYTHON]' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l no-cache -d 'Disable the cache for the current command. [env var: PDM_NO_CACHE]' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l pep582 -d 'Print the command line to be eval\'d by the shell' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l quiet -d 'Suppress output' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' -complete -c pdm -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -l version -d 'Show the version and exit' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l config -d 'Specify another config file path [env var: PDM_CONFIG_FILE] ' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l help -d 'Show this help message and exit.' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l ignore-python -d 'Ignore the Python path saved in .pdm-python. [env var: PDM_IGNORE_SAVED_PYTHON]' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l no-cache -d 'Disable the cache for the current command. [env var: PDM_NO_CACHE]' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l pep582 -d 'Print the command line to be eval\'d by the shell' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l quiet -d 'Suppress output' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' +complete -c pdm -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -l version -d 'Show the version and exit' # commands # add -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a add -d 'Add package(s) to pyproject.toml and install them' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a add -d 'Add package(s) to pyproject.toml and install them' complete -c pdm -A -n '__fish_seen_subcommand_from add' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from add' -l dev -d 'Add packages into dev dependencies' complete -c pdm -A -n '__fish_seen_subcommand_from add' -l dry-run -d 'Show the difference only and don\'t perform any action' @@ -55,7 +55,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from add' -l venv -d 'Run the comm complete -c pdm -A -n '__fish_seen_subcommand_from add' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # build -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a build -d 'Build artifacts for distribution' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a build -d 'Build artifacts for distribution' complete -c pdm -A -n '__fish_seen_subcommand_from build' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from build' -l dest -d 'Target directory to put artifacts' complete -c pdm -A -n '__fish_seen_subcommand_from build' -l help -d 'Show this help message and exit.' @@ -69,7 +69,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from build' -l skip -d 'Skip some complete -c pdm -A -n '__fish_seen_subcommand_from build' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # cache -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a cache -d 'Control the caches of PDM' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a cache -d 'Control the caches of PDM' complete -c pdm -A -n '__fish_seen_subcommand_from cache' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from cache' -l quiet -d 'Suppress output' complete -c pdm -A -n '__fish_seen_subcommand_from cache' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' @@ -100,11 +100,11 @@ complete -c pdm -A -n '__fish_seen_subcommand_from cache; and __fish_seen_subcom complete -c pdm -A -n '__fish_seen_subcommand_from cache; and __fish_seen_subcommand_from remove' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # completion -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a completion -d 'Generate completion scripts for the given shell' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a completion -d 'Generate completion scripts for the given shell' complete -c pdm -A -n '__fish_seen_subcommand_from completion' -l help -d 'Show this help message and exit.' # config -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a config -d 'Display the current configuration' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a config -d 'Display the current configuration' complete -c pdm -A -n '__fish_seen_subcommand_from config' -l delete -d 'Unset a configuration key' complete -c pdm -A -n '__fish_seen_subcommand_from config' -l edit -d 'Edit the configuration file in the default editor(defined by EDITOR env var)' complete -c pdm -A -n '__fish_seen_subcommand_from config' -l global -d 'Use the global project, supply the project root with `-p` option' @@ -115,7 +115,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from config' -l quiet -d 'Suppress complete -c pdm -A -n '__fish_seen_subcommand_from config' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # export -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a export -d 'Export the locked packages set to other formats' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a export -d 'Export the locked packages set to other formats' complete -c pdm -A -n '__fish_seen_subcommand_from export' -l dev -d 'Select dev dependencies' complete -c pdm -A -n '__fish_seen_subcommand_from export' -l editable-self -d 'Include the project itself as an editable dependency' complete -c pdm -A -n '__fish_seen_subcommand_from export' -l expandvars -d 'Expand environment variables in requirements' @@ -138,7 +138,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from export' -l without -d 'Exclud complete -c pdm -A -n '__fish_seen_subcommand_from export' -l without-hashes -d 'Don\'t include artifact hashes' # fix -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a fix -d 'Fix the project problems according to the latest version of PDM' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a fix -d 'Fix the project problems according to the latest version of PDM' complete -c pdm -A -n '__fish_seen_subcommand_from fix' -l dry-run -d 'Only show the problems' complete -c pdm -A -n '__fish_seen_subcommand_from fix' -l global -d 'Use the global project, supply the project root with `-p` option' complete -c pdm -A -n '__fish_seen_subcommand_from fix' -l help -d 'Show this help message and exit.' @@ -147,7 +147,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from fix' -l quiet -d 'Suppress ou complete -c pdm -A -n '__fish_seen_subcommand_from fix' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # import -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a import -d 'Import project metadata from other formats' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a import -d 'Import project metadata from other formats' complete -c pdm -A -n '__fish_seen_subcommand_from import' -l dev -d 'import packages into dev dependencies' complete -c pdm -A -n '__fish_seen_subcommand_from import' -l format -d 'Specify the file format explicitly' complete -c pdm -A -n '__fish_seen_subcommand_from import' -l global -d 'Use the global project, supply the project root with `-p` option' @@ -158,7 +158,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from import' -l quiet -d 'Suppress complete -c pdm -A -n '__fish_seen_subcommand_from import' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # info -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a info -d 'Show the project information' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a info -d 'Show the project information' complete -c pdm -A -n '__fish_seen_subcommand_from info' -l env -d 'Show PEP 508 environment markers' complete -c pdm -A -n '__fish_seen_subcommand_from info' -l global -d 'Use the global project, supply the project root with `-p` option' complete -c pdm -A -n '__fish_seen_subcommand_from info' -l help -d 'Show this help message and exit.' @@ -172,23 +172,25 @@ complete -c pdm -A -n '__fish_seen_subcommand_from info' -l verbose -d 'Use `-v` complete -c pdm -A -n '__fish_seen_subcommand_from info' -l where -d 'Show the project root path' # init -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a init -d 'Initialize a pyproject.toml for PDM' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a init -d 'Initialize a pyproject.toml for PDM' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l backend -d 'Specify the build backend, which implies --dist' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l cookiecutter -d 'Use Cookiecutter to generate project [installed]' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l copier -d 'Use Copier to generate project [installed]' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l dist -d 'Create a package for distribution' 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 license -d 'Specify the license (SPDX name)' 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 overwrite -d 'Overwrite existing files' 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__ [env var: PDM_PROJECT]' +complete -c pdm -A -n '__fish_seen_subcommand_from init' -l project-version -d 'Specify the project\'s version' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l python -d 'Specify the Python version/path to use' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l quiet -d 'Suppress output' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l skip -d 'Skip some tasks and/or hooks by their comma-separated names. Can be supplied multiple times. Use ":all" to skip all hooks. Use ":pre" and ":post" to skip all pre or post hooks.' complete -c pdm -A -n '__fish_seen_subcommand_from init' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # install -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a install -d 'Install dependencies from lock file' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a install -d 'Install dependencies from lock file' complete -c pdm -A -n '__fish_seen_subcommand_from install' -l check -d 'Check if the lock file is up to date and fail otherwise' complete -c pdm -A -n '__fish_seen_subcommand_from install' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from install' -l dev -d 'Select dev dependencies' @@ -213,7 +215,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from install' -l verbose -d 'Use ` complete -c pdm -A -n '__fish_seen_subcommand_from install' -l without -d 'Exclude groups of optional-dependencies or dev-dependencies' # list -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a list -d 'List packages installed in the current working set' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a list -d 'List packages installed in the current working set' complete -c pdm -A -n '__fish_seen_subcommand_from list' -l csv -d 'Output dependencies in CSV document format' complete -c pdm -A -n '__fish_seen_subcommand_from list' -l exclude -d 'Exclude dependency groups from the output' complete -c pdm -A -n '__fish_seen_subcommand_from list' -l fields -d 'Select information to output as a comma separated string. All fields: groups,homepage,licenses,location,name,version.' @@ -233,7 +235,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from list' -l venv -d 'Run the com complete -c pdm -A -n '__fish_seen_subcommand_from list' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # lock -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a lock -d 'Resolve and lock dependencies' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a lock -d 'Resolve and lock dependencies' complete -c pdm -A -n '__fish_seen_subcommand_from lock' -l check -d 'Check if the lock file is up to date and quit' complete -c pdm -A -n '__fish_seen_subcommand_from lock' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from lock' -l dev -d 'Select dev dependencies' @@ -259,7 +261,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from lock' -l verbose -d 'Use `-v` complete -c pdm -A -n '__fish_seen_subcommand_from lock' -l without -d 'Exclude groups of optional-dependencies or dev-dependencies' # outdated -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a outdated -d 'Check for outdated packages and list the latest versions on indexes.' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a outdated -d 'Check for outdated packages and list the latest versions on indexes.' complete -c pdm -A -n '__fish_seen_subcommand_from outdated' -l global -d 'Use the global project, supply the project root with `-p` option' complete -c pdm -A -n '__fish_seen_subcommand_from outdated' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from outdated' -l json -d 'Output in JSON format' @@ -268,7 +270,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from outdated' -l quiet -d 'Suppre complete -c pdm -A -n '__fish_seen_subcommand_from outdated' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # plugin -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a plugin -d 'Manage the PDM program itself (previously known as plugin)' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a plugin -d 'Manage the PDM program itself (previously known as plugin)' complete -c pdm -A -n '__fish_seen_subcommand_from plugin' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from plugin' -l quiet -d 'Suppress output' complete -c pdm -A -n '__fish_seen_subcommand_from plugin' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' @@ -306,7 +308,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from plugin; and __fish_seen_subco complete -c pdm -A -n '__fish_seen_subcommand_from plugin; and __fish_seen_subcommand_from update' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # publish -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a publish -d 'Build and publish the project to PyPI' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a publish -d 'Build and publish the project to PyPI' complete -c pdm -A -n '__fish_seen_subcommand_from publish' -l ca-certs -d 'The path to a PEM-encoded Certificate Authority bundle to use for publish server validation [env var: PDM_PUBLISH_CA_CERTS]' complete -c pdm -A -n '__fish_seen_subcommand_from publish' -l comment -d 'The comment to include with the distribution file.' complete -c pdm -A -n '__fish_seen_subcommand_from publish' -l dest -d 'The directory to upload the package from' @@ -325,7 +327,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from publish' -l username -d 'The complete -c pdm -A -n '__fish_seen_subcommand_from publish' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # py -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a py -d 'Manage installed Python interpreters' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a py -d 'Manage installed Python interpreters' complete -c pdm -A -n '__fish_seen_subcommand_from py' -l help -d 'Show this help message and exit.' # py subcommands set -l py_subcommands install list remove @@ -350,7 +352,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from py; and __fish_seen_subcomman complete -c pdm -A -n '__fish_seen_subcommand_from py; and __fish_seen_subcommand_from remove' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # python -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a python -d 'Manage installed Python interpreters' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a python -d 'Manage installed Python interpreters' complete -c pdm -A -n '__fish_seen_subcommand_from python' -l help -d 'Show this help message and exit.' # python subcommands set -l python_subcommands install list remove @@ -375,7 +377,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from python; and __fish_seen_subco complete -c pdm -A -n '__fish_seen_subcommand_from python; and __fish_seen_subcommand_from remove' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # remove -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a remove -d 'Remove packages from pyproject.toml' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a remove -d 'Remove packages from pyproject.toml' complete -c pdm -A -n '__fish_seen_subcommand_from remove' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from remove' -l dev -d 'Remove packages from dev dependencies' complete -c pdm -A -n '__fish_seen_subcommand_from remove' -l dry-run -d 'Show the difference only and don\'t perform any action' @@ -396,7 +398,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from remove' -l venv -d 'Run the c complete -c pdm -A -n '__fish_seen_subcommand_from remove' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # run -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a run -d 'Run commands or scripts with local packages loaded' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a run -d 'Run commands or scripts with local packages loaded' complete -c pdm -A -n '__fish_seen_subcommand_from run' -l global -d 'Use the global project, supply the project root with `-p` option' complete -c pdm -A -n '__fish_seen_subcommand_from run' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from run' -l json -d 'Output all scripts infos in JSON' @@ -410,13 +412,13 @@ complete -c pdm -A -n '__fish_seen_subcommand_from run' -l venv -d 'Run the comm complete -c pdm -A -n '__fish_seen_subcommand_from run' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # search -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a search -d 'Search for PyPI packages' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a search -d 'Search for PyPI packages' complete -c pdm -A -n '__fish_seen_subcommand_from search' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from search' -l quiet -d 'Suppress output' complete -c pdm -A -n '__fish_seen_subcommand_from search' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # self -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a self -d 'Manage the PDM program itself (previously known as plugin)' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a self -d 'Manage the PDM program itself (previously known as plugin)' complete -c pdm -A -n '__fish_seen_subcommand_from self' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from self' -l quiet -d 'Suppress output' complete -c pdm -A -n '__fish_seen_subcommand_from self' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' @@ -454,7 +456,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from self; and __fish_seen_subcomm complete -c pdm -A -n '__fish_seen_subcommand_from self; and __fish_seen_subcommand_from update' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # show -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a show -d 'Show the package information' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a show -d 'Show the package information' complete -c pdm -A -n '__fish_seen_subcommand_from show' -l global -d 'Use the global project, supply the project root with `-p` option' complete -c pdm -A -n '__fish_seen_subcommand_from show' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from show' -l keywords -d 'Show keywords' @@ -469,7 +471,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from show' -l verbose -d 'Use `-v` complete -c pdm -A -n '__fish_seen_subcommand_from show' -l version -d 'Show version' # sync -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a sync -d 'Synchronize the current working set with lock file' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a sync -d 'Synchronize the current working set with lock file' complete -c pdm -A -n '__fish_seen_subcommand_from sync' -l clean -d 'Clean packages not in the lockfile' complete -c pdm -A -n '__fish_seen_subcommand_from sync' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from sync' -l dev -d 'Select dev dependencies' @@ -494,7 +496,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from sync' -l verbose -d 'Use `-v` complete -c pdm -A -n '__fish_seen_subcommand_from sync' -l without -d 'Exclude groups of optional-dependencies or dev-dependencies' # update -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a update -d 'Update package(s) in pyproject.toml' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a update -d 'Update package(s) in pyproject.toml' complete -c pdm -A -n '__fish_seen_subcommand_from update' -l config-setting -d 'Pass options to the builder. options with a value must be specified after "=": `--config-setting=key(=value)` or `-Ckey(=value)`' complete -c pdm -A -n '__fish_seen_subcommand_from update' -l dev -d 'Select dev dependencies' complete -c pdm -A -n '__fish_seen_subcommand_from update' -l fail-fast -d 'Abort on first installation error' @@ -530,7 +532,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from update' -l verbose -d 'Use `- complete -c pdm -A -n '__fish_seen_subcommand_from update' -l without -d 'Exclude groups of optional-dependencies or dev-dependencies' # use -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a use -d 'Use the given python version or path as base interpreter. If not found, PDM will try to install one.' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a use -d 'Use the given python version or path as base interpreter. If not found, PDM will try to install one.' complete -c pdm -A -n '__fish_seen_subcommand_from use' -l auto-install-max -d 'If `python` argument not given, auto install maximum best match - otherwise has no effect' complete -c pdm -A -n '__fish_seen_subcommand_from use' -l auto-install-min -d 'If `python` argument not given, auto install minimal best match - otherwise has no effect' complete -c pdm -A -n '__fish_seen_subcommand_from use' -l first -d 'Select the first matched interpreter - no auto install' @@ -544,7 +546,7 @@ complete -c pdm -A -n '__fish_seen_subcommand_from use' -l venv -d 'Use the inte complete -c pdm -A -n '__fish_seen_subcommand_from use' -l verbose -d 'Use `-v` for detailed output and `-vv` for more detailed' # venv -complete -c pdm -f -n '__fish_pdm_a919b69078acdf0a_complete_no_subcommand' -a venv -d 'Virtualenv management' +complete -c pdm -f -n '__fish_pdm_fd45d3342570d348_complete_no_subcommand' -a venv -d 'Virtualenv management' complete -c pdm -A -n '__fish_seen_subcommand_from venv' -l help -d 'Show this help message and exit.' complete -c pdm -A -n '__fish_seen_subcommand_from venv' -l path -d 'Show the path to the given virtualenv' complete -c pdm -A -n '__fish_seen_subcommand_from venv' -l project -d 'Specify another path as the project root, which changes the base of pyproject.toml and __pypackages__ [env var: PDM_PROJECT]' diff --git a/src/pdm/cli/completions/pdm.ps1 b/src/pdm/cli/completions/pdm.ps1 index c7ee633d95..583d395f3b 100644 --- a/src/pdm/cli/completions/pdm.ps1 +++ b/src/pdm/cli/completions/pdm.ps1 @@ -291,7 +291,7 @@ function TabExpansion($line, $lastWord) { @( [Option]::new(@( "-g", "--global", "--non-interactive", "-n", "--python", "--dist", "--lib", "--copier", - "--cookiecutter", "--overwrite" + "--cookiecutter", "--overwrite", "--license", "--project-version" )), $projectOption, $skipOption, diff --git a/src/pdm/cli/completions/pdm.zsh b/src/pdm/cli/completions/pdm.zsh index e45e0c465d..7dc15f5447 100644 --- a/src/pdm/cli/completions/pdm.zsh +++ b/src/pdm/cli/completions/pdm.zsh @@ -205,6 +205,8 @@ _pdm() { '--python[Specify the Python version/path to use]:python:' '--copier[Use Copier to generate project]' '--cookiecutter[Use Cookiecutter to generate project]' + '--license[Specify the license (SPDX name)]:license:' + "--project-version[Specify the project's version]:project_version:" '1:template:' ) ;; diff --git a/tests/cli/test_init.py b/tests/cli/test_init.py index 5048b1cb7e..1451f41c41 100644 --- a/tests/cli/test_init.py +++ b/tests/cli/test_init.py @@ -134,3 +134,77 @@ def test_init_with_backend_default_library(project_no_init, pdm): def test_init_with_backend_default_library_non_interactive(project_no_init, pdm): pdm(["init", "-n", "--backend", "flit-core"], obj=project_no_init) assert project_no_init.backend.__class__.__name__ == "FlitBackend" + + +def test_init_with_license_non_interactive(project_no_init, pdm, mocker): + mocker.patch( + "pdm.cli.commands.init.get_user_email_from_git", + return_value=("Testing", "me@example.org"), + ) + do_use = mocker.patch("pdm.cli.commands.use.Command.do_use", return_value=PythonInfo.from_path(sys.executable)) + expected_license = "Proprietary" + result = pdm(["init", "-n", "--license", expected_license], obj=project_no_init) + assert result.exit_code == 0 + python_version = f"{project_no_init.python.major}.{project_no_init.python.minor}" + do_use.assert_called_once_with( + project_no_init, + ANY, + first=True, + ignore_remembered=True, + ignore_requires_python=True, + save=False, + hooks=ANY, + ) + data = { + "project": { + "authors": [{"email": "me@example.org", "name": "Testing"}], + "dependencies": [], + "description": "Default template for PDM package", + "license": {"text": f"{expected_license}"}, + "name": project_no_init.root.name, + "requires-python": f"=={python_version}.*", + "readme": "README.md", + "version": "0.1.0", + }, + "tool": {"pdm": {"distribution": False}}, + } + + with open(project_no_init.root.joinpath("pyproject.toml"), "rb") as fp: + assert tomllib.load(fp) == data + + +def test_init_with_project_version_non_interactive(project_no_init, pdm, mocker): + mocker.patch( + "pdm.cli.commands.init.get_user_email_from_git", + return_value=("Testing", "me@example.org"), + ) + do_use = mocker.patch("pdm.cli.commands.use.Command.do_use", return_value=PythonInfo.from_path(sys.executable)) + expected_project_version = "2.0.42" + result = pdm(["init", "-n", "--project-version", expected_project_version], obj=project_no_init) + assert result.exit_code == 0 + python_version = f"{project_no_init.python.major}.{project_no_init.python.minor}" + do_use.assert_called_once_with( + project_no_init, + ANY, + first=True, + ignore_remembered=True, + ignore_requires_python=True, + save=False, + hooks=ANY, + ) + data = { + "project": { + "authors": [{"email": "me@example.org", "name": "Testing"}], + "dependencies": [], + "description": "Default template for PDM package", + "license": {"text": "MIT"}, + "name": project_no_init.root.name, + "requires-python": f"=={python_version}.*", + "readme": "README.md", + "version": f"{expected_project_version}", + }, + "tool": {"pdm": {"distribution": False}}, + } + + with open(project_no_init.root.joinpath("pyproject.toml"), "rb") as fp: + assert tomllib.load(fp) == data