Exemple #1
0
def init(project):
    """Initialize a pyproject.toml for PDM."""
    python = click.prompt("Please enter the Python interpreter to use")
    actions.do_use(project, python)

    if project.pyproject_file.exists():
        context.io.echo("{}".format(
            context.io.cyan("pyproject.toml already exists, update it now.")))
    else:
        context.io.echo("{}".format(
            context.io.cyan("Creating a pyproject.toml for PDM...")))
    name = click.prompt(f"Project name", default=project.root.name)
    version = click.prompt("Project version", default="0.0.0")
    license = click.prompt("License(SPDX name)", default="MIT")

    git_user, git_email = get_user_email_from_git()
    author = click.prompt(f"Author name", default=git_user)
    email = click.prompt(f"Author email", default=git_email)
    python_version = ".".join(
        map(str,
            get_python_version(project.environment.python_executable)[:2]))
    python_requires = click.prompt("Python requires('*' to allow any)",
                                   default=f">={python_version}")

    actions.do_init(project, name, version, license, author, email,
                    python_requires)
Exemple #2
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        if project.pyproject_file.exists():
            project.core.ui.echo("{}".format(
                termui.cyan("pyproject.toml already exists, update it now.")))
        else:
            project.core.ui.echo("{}".format(
                termui.cyan("Creating a pyproject.toml for PDM...")))
        non_interactive = options.non_interactive
        if non_interactive:
            actions.do_use(project, "3", True)
        else:
            actions.do_use(project)
        is_library = (False if non_interactive else click.confirm(
            "Is the project a library that will be upload to PyPI?", ))
        if is_library:
            name = self.ask("Project name", project.root.name, non_interactive)
            version = self.ask("Project version", "0.1.0", non_interactive)
        else:
            name, version = "", ""
        license = self.ask("License(SPDX name)", "MIT", non_interactive)

        git_user, git_email = get_user_email_from_git()
        author = self.ask("Author name", git_user, non_interactive)
        email = self.ask("Author email", git_email, non_interactive)
        python_version = f"{project.python.major}.{project.python.minor}"
        python_requires = self.ask("Python requires('*' to allow any)",
                                   f">={python_version}", non_interactive)

        actions.do_init(project, name, version, license, author, email,
                        python_requires)
        if not non_interactive:
            actions.ask_for_import(project)
Exemple #3
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        if project.pyproject_file.exists():
            stream.echo("{}".format(
                stream.cyan("pyproject.toml already exists, update it now.")))
        else:
            stream.echo("{}".format(
                stream.cyan("Creating a pyproject.toml for PDM...")))
        python = click.prompt("Please enter the Python interpreter to use",
                              default="",
                              show_default=False)
        actions.do_use(project, python)
        name = click.prompt("Project name", default=project.root.name)
        version = click.prompt("Project version", default="0.0.0")
        license = click.prompt("License(SPDX name)", default="MIT")

        git_user, git_email = get_user_email_from_git()
        author = click.prompt("Author name", default=git_user)
        email = click.prompt("Author email", default=git_email)
        python_version = ".".join(
            map(str,
                get_python_version(project.environment.python_executable)[:2]))
        python_requires = click.prompt("Python requires('*' to allow any)",
                                       default=f">={python_version}")

        actions.do_init(project, name, version, license, author, email,
                        python_requires)
        actions.ask_for_import(project)
Exemple #4
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        if project.pyproject_file.exists():
            project.core.ui.echo("{}".format(
                termui.cyan("pyproject.toml already exists, update it now.")))
        else:
            project.core.ui.echo("{}".format(
                termui.cyan("Creating a pyproject.toml for PDM...")))
        actions.do_use(project)
        is_library = click.confirm(
            "Is the project a library that will be upload to PyPI?", )
        if is_library:
            name = click.prompt("Project name", default=project.root.name)
            version = click.prompt("Project version", default="0.1.0")
        else:
            name, version = "", ""
        license = click.prompt("License(SPDX name)", default="MIT")

        git_user, git_email = get_user_email_from_git()
        author = click.prompt("Author name", default=git_user)
        email = click.prompt("Author email", default=git_email)
        python_version, _ = get_python_version(project.python_executable, True,
                                               2)
        python_requires = click.prompt("Python requires('*' to allow any)",
                                       default=f">={python_version}")

        actions.do_init(project, name, version, license, author, email,
                        python_requires)
        actions.ask_for_import(project)
Exemple #5
0
def project(tmp_path, mocker):
    p = TestProject(tmp_path.as_posix())
    p.config["cache_dir"] = tmp_path.joinpath("caches").as_posix()
    mocker.patch("pdm.utils.get_finder", get_local_finder)
    mocker.patch("pdm.models.environment.get_finder", get_local_finder)
    mocker.patch("pdm.cli.commands.Project", return_value=p)
    do_init(p, "test_project", "0.0.0")
    return p
Exemple #6
0
def init(project):
    if project.pyproject_file.exists():
        context.io.echo("{}".format(
            context.io.cyan("pyproject.toml already exists, update it now.")))
    else:
        context.io.echo("{}".format(
            context.io.cyan("Creating a pyproject.toml for PDM...")))
    name = click.prompt(f"Project name", default=project.root.name)
    version = click.prompt("Project version", default="0.0.0")
    license = click.prompt("License(SPDX name)", default="MIT")

    git_user, git_email = get_user_email_from_git()
    author = click.prompt(f"Author name", default=git_user)
    email = click.prompt(f"Author email", default=git_email)
    actions.do_init(project, name, version, license, author, email)
Exemple #7
0
    def handle(self, project: Project, options: argparse.Namespace) -> None:
        if project.pyproject_file.exists():
            stream.echo(
                "{}".format(
                    stream.cyan("pyproject.toml already exists, update it now.")
                )
            )
        else:
            stream.echo(
                "{}".format(stream.cyan("Creating a pyproject.toml for PDM..."))
            )
        python = click.prompt(
            "Please enter the Python interpreter to use", default="", show_default=False
        )
        actions.do_use(project, python)
        is_library = (
            click.prompt(
                "Is the project a library that will be upload to PyPI?(y/n)",
                default="n",
            ).lower()
            == "y"
        )
        if is_library:
            name = click.prompt("Project name", default=project.root.name)
            version = click.prompt("Project version", default="0.1.0")
        else:
            name, version = "", ""
        license = click.prompt("License(SPDX name)", default="MIT")

        git_user, git_email = get_user_email_from_git()
        author = click.prompt("Author name", default=git_user)
        email = click.prompt("Author email", default=git_email)
        python_version, _ = get_python_version(
            project.environment.python_executable, True, 2
        )
        python_requires = click.prompt(
            "Python requires('*' to allow any)", default=f">={python_version}"
        )

        actions.do_init(project, name, version, license, author, email, python_requires)
        actions.ask_for_import(project)
Exemple #8
0
def test_init_validate_python_requires(project_no_init):
    with pytest.raises(ValueError):
        actions.do_init(project_no_init, python_requires="3.7")
Exemple #9
0
def project(project_no_init):
    do_init(project_no_init, "test_project", "0.0.0")
    # Clean the cached property
    project_no_init._environment = None
    return project_no_init
Exemple #10
0
def project(project_no_init):
    do_init(project_no_init, "test_project", "0.0.0")
    # Clean the cached property
    project_no_init.__dict__.pop("environment", None)
    return project_no_init
Exemple #11
0
def project(project_no_init):
    do_init(project_no_init, "test_project", "0.0.0")
    return project_no_init