def update_pyvenv(venv_dir: PathLike) -> None:
    venv_dir = PathPlus(venv_dir)

    pyvenv_config: Dict[str, str] = shippinglabel.read_pyvenv(venv_dir)
    pyvenv_config["repo_helper_devenv"] = __version__

    with (venv_dir / "pyvenv.cfg").open('w') as fp:
        for key, value in pyvenv_config.items():
            value = f" = " + str(value).replace('\n', '\n\t')
            fp.write(f"{key}{value}\n")
Exemple #2
0
    def update_pyvenv(self) -> None:
        """
		Read and update the ``pyvenv.cfg`` file of the virtualenv.
		"""

        pyvenv_config: Dict[str, str] = read_pyvenv(self.venv_dir)
        pyvenv_config["pyproject-devenv"] = __version__

        with (self.venv_dir / "pyvenv.cfg").open('w') as fp:
            for key, value in pyvenv_config.items():
                value = f" = " + str(value).replace('\n', '\n\t')
                fp.write(f"{key}{value}\n")
Exemple #3
0
def test_mkdevenv_no_lib_deps_dynamic(tmp_pathplus: PathPlus, capsys):
	test_requirements = [
			"pytest",
			"hypothesis",
			]

	(tmp_pathplus / "pyproject.toml").write_lines([
			"[build-system]",
			'requires = ["setuptools", "wheel"]',
			'',
			"[project]",
			"name = 'pyproject-devenv-demo'",
			"dynamic = ['dependencies']",
			])
	(tmp_pathplus / "requirements.txt").touch()

	(tmp_pathplus / "tests").mkdir()
	(tmp_pathplus / "tests/requirements.txt").write_lines(test_requirements)

	assert mkdevenv(tmp_pathplus, tmp_pathplus / "venv", verbosity=1, upgrade=False) == 0

	capout = capsys.readouterr()
	assert not capout.err
	assert "Installing library requirements" not in capout.out

	# Check list of packages in virtualenv
	venv_dir = tmp_pathplus / "venv"

	if PYPY:
		version_dirs = [venv_dir]
	elif sys.platform == "win32":
		version_dirs = [(venv_dir / "Lib")]
	else:
		version_dirs = list((venv_dir / "lib").glob("py*"))

	for version_dir in version_dirs:
		for package in test_requirements:
			assert (version_dir / "site-packages" / package).is_dir()

	assert len(version_dirs) == 1

	pyvenv_config: Dict[str, str] = read_pyvenv(venv_dir)

	assert "prompt" in pyvenv_config
	assert pyvenv_config["prompt"] == "(pyproject-devenv-demo) "

	assert "pyproject-devenv" in pyvenv_config
	assert pyvenv_config["pyproject-devenv"] == __version__

	assert "virtualenv" in pyvenv_config

	assert "include-system-site-packages" in pyvenv_config
	assert not strtobool(pyvenv_config["include-system-site-packages"])
def read_pyvenv(venv_dir: PathLike) -> Dict[str, str]:
    """
	Reads the ``pyvenv.cfg`` for the given virtualenv, and returns a ``key: value`` mapping of its contents.

	.. versionadded:: 0.3.2

	:param venv_dir:

	:rtype:
	"""

    return shippinglabel.read_pyvenv(venv_dir)
Exemple #5
0
def test_mkdevenv_verbose(tmp_pathplus: PathPlus, extra_args):
    lib_requirements = [
        "click",
        "flask",
        "werkzeug",
        "consolekit",
        "requests",
        "apeye",
    ]

    test_requirements = [
        "pytest",
        "hypothesis",
    ]

    (tmp_pathplus / "pyproject.toml").write_lines([
        "[build-system]",
        'requires = ["setuptools", "wheel"]',
        '',
        "[project]",
        "name = 'pyproject-devenv-demo'",
        "dynamic = ['dependencies']",
    ])
    (tmp_pathplus / "requirements.txt").write_lines(lib_requirements)

    (tmp_pathplus / "tests").mkdir()
    (tmp_pathplus / "tests/requirements.txt").write_lines(test_requirements)

    with in_directory(tmp_pathplus):
        runner = CliRunner()
        result: Result = runner.invoke(main, extra_args)
        assert result.exit_code == 0

    assert " Installing project requirements " in result.stdout
    assert " Installing test requirements " in result.stdout
    assert " Installing build requirements " in result.stdout
    assert "Successfully created development virtualenv." in result.stdout

    # Check list of packages in virtualenv
    venv_dir = tmp_pathplus / "venv"

    if PYPY:
        version_dirs = [venv_dir]
    elif sys.platform == "win32":
        version_dirs = [(venv_dir / "Lib")]
    else:
        version_dirs = list((venv_dir / "lib").glob("py*"))

    for version_dir in version_dirs:

        for package in lib_requirements:
            assert (version_dir / "site-packages" / package).is_dir()

        for package in test_requirements:
            assert (version_dir / "site-packages" / package).is_dir()

    assert len(version_dirs) == 1

    pyvenv_config: Dict[str, str] = read_pyvenv(venv_dir)

    assert "prompt" in pyvenv_config
    assert pyvenv_config["prompt"] == "(pyproject-devenv-demo) "

    assert "pyproject-devenv" in pyvenv_config
    assert pyvenv_config["pyproject-devenv"] == __version__

    assert "virtualenv" in pyvenv_config

    assert "include-system-site-packages" in pyvenv_config
    assert not strtobool(pyvenv_config["include-system-site-packages"])
Exemple #6
0
def test_mkdevenv_no_build_deps(tmp_pathplus: PathPlus, capsys):
	lib_requirements = [
			"click",
			"flask",
			"werkzeug",
			"consolekit",
			"requests",
			"apeye",
			]

	test_requirements = [
			"pytest",
			"hypothesis",
			]

	(tmp_pathplus / "pyproject.toml").write_lines([
			"[project]",
			"name = 'pyproject-devenv-demo'",
			"dynamic = ['dependencies']",
			'',
			"[project.optional-dependencies]",
			"doc = ['sphinx']",
			'',
			])
	(tmp_pathplus / "requirements.txt").write_lines(lib_requirements)

	(tmp_pathplus / "tests").mkdir()
	(tmp_pathplus / "tests/requirements.txt").write_lines(test_requirements)

	assert mkdevenv(tmp_pathplus, tmp_pathplus / "venv", verbosity=2, upgrade=False) == 0

	capout = capsys.readouterr()
	assert not capout.err
	assert "Installing build requirements" not in capout.out

	# Check list of packages in virtualenv
	venv_dir = tmp_pathplus / "venv"

	if PYPY:
		version_dirs = [venv_dir]
	elif sys.platform == "win32":
		version_dirs = [(venv_dir / "Lib")]
	else:
		version_dirs = list((venv_dir / "lib").glob("py*"))

	for version_dir in version_dirs:

		for package in lib_requirements:
			assert (version_dir / "site-packages" / package).is_dir()

		for package in test_requirements:
			assert (version_dir / "site-packages" / package).is_dir()

	assert len(version_dirs) == 1

	pyvenv_config: Dict[str, str] = read_pyvenv(venv_dir)

	assert "prompt" in pyvenv_config
	assert pyvenv_config["prompt"] == "(pyproject-devenv-demo) "

	assert "pyproject-devenv" in pyvenv_config
	assert pyvenv_config["pyproject-devenv"] == __version__

	assert "virtualenv" in pyvenv_config

	assert "include-system-site-packages" in pyvenv_config
	assert not strtobool(pyvenv_config["include-system-site-packages"])