示例#1
0
文件: init.py 项目: skyoo2003/pdm
    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)
示例#2
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)
示例#3
0
文件: init.py 项目: ulwlu/pdm
    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)
示例#4
0
文件: init.py 项目: xareelee/pdm
    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)
示例#5
0
def test_use_invalid_wrapper_python(project):
    wrapper_script = """#!/bin/bash
echo hello
"""
    shim_path = project.root.joinpath("python_shim.sh")
    shim_path.write_text(wrapper_script)
    shim_path.chmod(0o755)
    with pytest.raises(InvalidPyVersion):
        actions.do_use(project, shim_path.as_posix())
示例#6
0
def test_use_wrapper_python(project):
    wrapper_script = """#!/bin/bash
exec "{}" "$@"
""".format(sys.executable)
    shim_path = project.root.joinpath("python_shim.sh")
    shim_path.write_text(wrapper_script)
    shim_path.chmod(0o755)

    actions.do_use(project, shim_path.as_posix())
    assert project.python.executable == sys.executable
示例#7
0
def project_no_init(tmp_path, mocker):
    p = TestProject(tmp_path.as_posix())
    p.core = main
    mocker.patch("pdm.utils.get_finder", get_local_finder)
    mocker.patch("pdm.models.environment.get_finder", get_local_finder)
    mocker.patch("pdm.project.core.Config.HOME_CONFIG", tmp_path)
    old_config_map = Config._config_map.copy()
    p.global_config["cache_dir"] = tmp_path.joinpath("caches").as_posix()
    do_use(p, sys.executable)
    yield p
    # Restore the config items
    Config._config_map = old_config_map
示例#8
0
def test_add_editable_package(project, repository, working_set, is_dev, vcs):
    # Ensure that correct python version is used.
    actions.do_use(project, sys.executable)
    actions.do_add(
        project,
        is_dev,
        editables=["git+https://github.com/test-root/demo.git#egg=demo"],
    )
    section = "dev-dependencies" if is_dev else "dependencies"
    assert "demo" in project.tool_settings[section]
    locked_candidates = project.get_locked_candidates(
        "dev" if is_dev else "default")
    assert locked_candidates["idna"].version == "2.7"
    assert "idna" in working_set
示例#9
0
文件: conftest.py 项目: pohlt/pdm
def project_no_init(tmp_path, mocker):
    p = TestProject(tmp_path.as_posix())
    p.core = main
    mocker.patch("pdm.utils.get_finder", get_local_finder)
    mocker.patch("pdm.models.environment.get_finder", get_local_finder)
    mocker.patch("pdm.project.core.Config.HOME_CONFIG", tmp_path)
    old_config_map = Config._config_map.copy()
    p.global_config["cache_dir"] = tmp_path.joinpath("caches").as_posix()
    do_use(p, getattr(sys, "_base_executable", sys.executable))
    with temp_environ():
        os.environ.pop("VIRTUAL_ENV", None)
        os.environ.pop("PYTHONPATH", None)
        yield p
    # Restore the config items
    Config._config_map = old_config_map
示例#10
0
def project_no_init(tmp_path, mocker):
    p = main.create_project(tmp_path)
    mocker.patch("pdm.utils.get_finder", get_local_finder)
    mocker.patch("pdm.models.environment.get_finder", get_local_finder)
    mocker.patch("pdm.project.core.Config.HOME_CONFIG", tmp_path)
    old_config_map = Config._config_map.copy()
    p.global_config["cache_dir"] = tmp_path.joinpath("caches").as_posix()
    do_use(p, getattr(sys, "_base_executable", sys.executable))
    with temp_environ():
        os.environ.pop("VIRTUAL_ENV", None)
        os.environ.pop("PEP582_PACKAGES", None)
        pythonpath = os.environ.pop("PYTHONPATH", "")
        pythonpath = remove_pep582_path_from_pythonpath(pythonpath)
        if pythonpath:
            os.environ["PYTHONPATH"] = pythonpath
        yield p
    # Restore the config items
    Config._config_map = old_config_map
示例#11
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)
示例#12
0
def project_no_init(tmp_path, mocker, core):
    test_home = tmp_path / ".pdm-home"
    test_home.mkdir(parents=True)
    test_home.joinpath("config.toml").write_text(
        '[global_project]\npath = "{}"\n'.format(
            test_home.joinpath("global-project").as_posix()))
    p = core.create_project(
        tmp_path, global_config=test_home.joinpath("config.toml").as_posix())
    mocker.patch("pdm.utils.get_finder", get_local_finder)
    mocker.patch("pdm.models.environment.get_finder", get_local_finder)
    tmp_path.joinpath("caches").mkdir(parents=True)
    p.global_config["cache_dir"] = tmp_path.joinpath("caches").as_posix()
    do_use(p, getattr(sys, "_base_executable", sys.executable))
    with temp_environ():
        os.environ.pop("VIRTUAL_ENV", None)
        os.environ.pop("CONDA_PREFIX", None)
        os.environ.pop("PEP582_PACKAGES", None)
        os.environ.pop("NO_SITE_PACKAGES", None)
        pythonpath = os.environ.pop("PYTHONPATH", "")
        pythonpath = remove_pep582_path_from_pythonpath(pythonpath)
        if pythonpath:
            os.environ["PYTHONPATH"] = pythonpath
        yield p
示例#13
0
def test_use_remember_last_selection(project, mocker):
    cache = JSONFileCache(project.cache_dir / "use_cache.json")
    cache.clear()
    actions.do_use(project, first=True)
    cache._read_cache()
    assert not cache._cache
    actions.do_use(project, "3", first=True)
    cache._read_cache()
    assert cache.has_key("3")
    mocker.patch.object(project, "find_interpreters")
    actions.do_use(project, "3")
    project.find_interpreters.assert_not_called()
示例#14
0
def use(project, first, python):
    """Use the given python version or path as base interpreter."""
    actions.do_use(project, python, first)
示例#15
0
文件: use.py 项目: xareelee/pdm
 def handle(self, project: Project, options: argparse.Namespace) -> None:
     actions.do_use(project, options.python, options.first)
示例#16
0
文件: commands.py 项目: stacklens/pdm
def use(project, python):
    """Use the given python version as base interpreter."""
    actions.do_use(project, python)