Commit 8f571352 by David Hotham Committed by GitHub

poetry-core update and cleanup (#7922)

* deprecate __getattr__ in TOMLFile
* remove unused code from env.py (unused due to removal of old installer)
* type annotations
parent 0ea82c5d
...@@ -1077,14 +1077,14 @@ testing = ["pytest", "pytest-benchmark"] ...@@ -1077,14 +1077,14 @@ testing = ["pytest", "pytest-benchmark"]
[[package]] [[package]]
name = "poetry-core" name = "poetry-core"
version = "1.5.2" version = "1.6.0"
description = "Poetry PEP 517 Build Backend" description = "Poetry PEP 517 Build Backend"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.7,<4.0" python-versions = ">=3.7,<4.0"
files = [ files = [
{file = "poetry_core-1.5.2-py3-none-any.whl", hash = "sha256:832d40a1ea5fd10c0f648d0575cadddc8b79f06f91d83a1f1a73a7e1dfacfbd7"}, {file = "poetry_core-1.6.0-py3-none-any.whl", hash = "sha256:ff96620579f02ec30ee9f789fa5dfdcddd9ab4ac848394f6f8f2f4e88306b534"},
{file = "poetry_core-1.5.2.tar.gz", hash = "sha256:c6556c3b1ec5b8668e6ef5a4494726bc41d31907339425e194e78a6178436c14"}, {file = "poetry_core-1.6.0.tar.gz", hash = "sha256:a9c7296a12d6c8e4f8aa50a66ef3c967b2b50fba634da144d358e676fad9989f"},
] ]
[package.dependencies] [package.dependencies]
...@@ -1616,14 +1616,14 @@ files = [ ...@@ -1616,14 +1616,14 @@ files = [
[[package]] [[package]]
name = "tomlkit" name = "tomlkit"
version = "0.11.6" version = "0.11.8"
description = "Style preserving TOML library" description = "Style preserving TOML library"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.6" python-versions = ">=3.7"
files = [ files = [
{file = "tomlkit-0.11.6-py3-none-any.whl", hash = "sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b"}, {file = "tomlkit-0.11.8-py3-none-any.whl", hash = "sha256:8c726c4c202bdb148667835f68d68780b9a003a9ec34167b6c673b38eff2a171"},
{file = "tomlkit-0.11.6.tar.gz", hash = "sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73"}, {file = "tomlkit-0.11.8.tar.gz", hash = "sha256:9330fc7faa1db67b541b28e62018c17d20be733177d290a13b24c62d1614e0c3"},
] ]
[[package]] [[package]]
...@@ -1890,4 +1890,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" ...@@ -1890,4 +1890,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.7" python-versions = "^3.7"
content-hash = "9aaf819933593fe3f84ff37db4ed316090da9b491e66fd5108b2b33f32f683c3" content-hash = "430ba3f08c5c3422c311d9bd03544aaf381c2ab10de8bb8bc79e87d1951d6cc1"
...@@ -32,7 +32,7 @@ Changelog = "https://python-poetry.org/history/" ...@@ -32,7 +32,7 @@ Changelog = "https://python-poetry.org/history/"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.7" python = "^3.7"
poetry-core = "1.5.2" poetry-core = "1.6.0"
poetry-plugin-export = "^1.3.1" poetry-plugin-export = "^1.3.1"
"backports.cached-property" = { version = "^1.0.2", python = "<3.8" } "backports.cached-property" = { version = "^1.0.2", python = "<3.8" }
build = "^0.10.0" build = "^0.10.0"
......
...@@ -82,7 +82,7 @@ class FileConfigSource(ConfigSource): ...@@ -82,7 +82,7 @@ class FileConfigSource(ConfigSource):
mode = 0o600 mode = 0o600
if new_file: if new_file:
self.file.touch(mode=mode) self.file.path.touch(mode=mode)
self.file.write(config) self.file.write(config)
except Exception: except Exception:
......
...@@ -249,7 +249,7 @@ The add command adds required packages to your <comment>pyproject.toml</> and in ...@@ -249,7 +249,7 @@ The add command adds required packages to your <comment>pyproject.toml</> and in
constraint_name, constraint_name,
constraint, constraint,
groups=[group], groups=[group],
root_dir=self.poetry.file.parent, root_dir=self.poetry.file.path.parent,
) )
) )
......
...@@ -95,7 +95,7 @@ To remove a repository (repo is a short alias for repositories): ...@@ -95,7 +95,7 @@ To remove a repository (repo is a short alias for repositories):
config_file = TOMLFile(CONFIG_DIR / "config.toml") config_file = TOMLFile(CONFIG_DIR / "config.toml")
try: try:
local_config_file = TOMLFile(self.poetry.file.parent / "poetry.toml") local_config_file = TOMLFile(self.poetry.file.path.parent / "poetry.toml")
if local_config_file.exists(): if local_config_file.exists():
config.merge(local_config_file.read()) config.merge(local_config_file.read())
except (RuntimeError, PyProjectException): except (RuntimeError, PyProjectException):
...@@ -106,7 +106,7 @@ To remove a repository (repo is a short alias for repositories): ...@@ -106,7 +106,7 @@ To remove a repository (repo is a short alias for repositories):
if not config_file.exists(): if not config_file.exists():
config_file.path.parent.mkdir(parents=True, exist_ok=True) config_file.path.parent.mkdir(parents=True, exist_ok=True)
config_file.touch(mode=0o0600) config_file.path.touch(mode=0o0600)
if self.option("list"): if self.option("list"):
self._list_configuration(config.all(), config.raw()) self._list_configuration(config.all(), config.raw())
......
...@@ -433,7 +433,7 @@ You can specify a package in the following forms: ...@@ -433,7 +433,7 @@ You can specify a package in the following forms:
from poetry.core.pyproject.exceptions import PyProjectException from poetry.core.pyproject.exceptions import PyProjectException
try: try:
cwd = self.poetry.file.parent cwd = self.poetry.file.path.parent
artifact_cache = self.poetry.pool.artifact_cache artifact_cache = self.poetry.pool.artifact_cache
except (PyProjectException, RuntimeError): except (PyProjectException, RuntimeError):
cwd = Path.cwd() cwd = Path.cwd()
......
...@@ -40,7 +40,7 @@ class RunCommand(EnvCommand): ...@@ -40,7 +40,7 @@ class RunCommand(EnvCommand):
poetry = self.poetry poetry = self.poetry
package = poetry.package package = poetry.package
path = poetry.file.parent path = poetry.file.path.parent
module = Module(package.name, path.as_posix(), package.packages) module = Module(package.name, path.as_posix(), package.packages)
return module return module
......
...@@ -267,7 +267,7 @@ lists all packages available.""" ...@@ -267,7 +267,7 @@ lists all packages available."""
version_length, version_length,
len( len(
get_package_version_display_string( get_package_version_display_string(
locked, root=self.poetry.file.parent locked, root=self.poetry.file.path.parent
) )
), ),
) )
...@@ -275,7 +275,7 @@ lists all packages available.""" ...@@ -275,7 +275,7 @@ lists all packages available."""
latest_length, latest_length,
len( len(
get_package_version_display_string( get_package_version_display_string(
latest, root=self.poetry.file.parent latest, root=self.poetry.file.path.parent
) )
), ),
) )
...@@ -292,7 +292,7 @@ lists all packages available.""" ...@@ -292,7 +292,7 @@ lists all packages available."""
version_length, version_length,
len( len(
get_package_version_display_string( get_package_version_display_string(
locked, root=self.poetry.file.parent locked, root=self.poetry.file.path.parent
) )
), ),
) )
...@@ -353,7 +353,7 @@ lists all packages available.""" ...@@ -353,7 +353,7 @@ lists all packages available."""
) )
if write_version: if write_version:
version = get_package_version_display_string( version = get_package_version_display_string(
locked, root=self.poetry.file.parent locked, root=self.poetry.file.path.parent
) )
line += f" <b>{version:{version_length}}</b>" line += f" <b>{version:{version_length}}</b>"
if show_latest: if show_latest:
...@@ -368,7 +368,7 @@ lists all packages available.""" ...@@ -368,7 +368,7 @@ lists all packages available."""
color = "yellow" color = "yellow"
version = get_package_version_display_string( version = get_package_version_display_string(
latest, root=self.poetry.file.parent latest, root=self.poetry.file.path.parent
) )
line += f" <fg={color}>{version:{latest_length}}</>" line += f" <fg={color}>{version:{latest_length}}</>"
......
...@@ -57,12 +57,7 @@ class Factory(BaseFactory): ...@@ -57,12 +57,7 @@ class Factory(BaseFactory):
base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups) base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
# TODO: backward compatibility, can be simplified if poetry-core with poetry_file = base_poetry.pyproject_path
# https://github.com/python-poetry/poetry-core/pull/483 is available
poetry_file: Path = (
getattr(base_poetry, "pyproject_path", None) or base_poetry.file.path
)
locker = Locker(poetry_file.parent / "poetry.lock", base_poetry.local_config) locker = Locker(poetry_file.parent / "poetry.lock", base_poetry.local_config)
# Loading global configuration # Loading global configuration
......
...@@ -91,13 +91,10 @@ class Layout: ...@@ -91,13 +91,10 @@ class Layout:
return None return None
include = parts[0] include = parts[0]
package.append("include", include) # type: ignore[no-untyped-call] package.append("include", include)
if self.basedir != Path(): if self.basedir != Path():
package.append( # type: ignore[no-untyped-call] package.append("from", self.basedir.as_posix())
"from",
self.basedir.as_posix(),
)
else: else:
if include == self._project: if include == self._project:
# package include and package name are the same, # package include and package name are the same,
......
...@@ -105,7 +105,7 @@ class EditableBuilder(Builder): ...@@ -105,7 +105,7 @@ class EditableBuilder(Builder):
pip_install(self._path, self._env, upgrade=True, editable=True) pip_install(self._path, self._env, upgrade=True, editable=True)
else: else:
# Temporarily rename pyproject.toml # Temporarily rename pyproject.toml
renamed_pyproject = self._poetry.file.with_suffix(".tmp") renamed_pyproject = self._poetry.file.path.with_suffix(".tmp")
self._poetry.file.path.rename(renamed_pyproject) self._poetry.file.path.rename(renamed_pyproject)
try: try:
pip_install(self._path, self._env, upgrade=True, editable=True) pip_install(self._path, self._env, upgrade=True, editable=True)
...@@ -130,7 +130,7 @@ class EditableBuilder(Builder): ...@@ -130,7 +130,7 @@ class EditableBuilder(Builder):
for file in self._env.site_packages.find(path=pth_file, writable_only=True): for file in self._env.site_packages.find(path=pth_file, writable_only=True):
self._debug( self._debug(
f" - Removing existing <c2>{file.name}</c2> from <b>{file.parent}</b>" f" - Removing existing <c2>{file.name}</c2> from <b>{file.parent}</b>"
f" for {self._poetry.file.parent}" f" for {self._poetry.file.path.parent}"
) )
# We can't use unlink(missing_ok=True) because it's not always available # We can't use unlink(missing_ok=True) because it's not always available
if file.exists(): if file.exists():
...@@ -142,14 +142,14 @@ class EditableBuilder(Builder): ...@@ -142,14 +142,14 @@ class EditableBuilder(Builder):
) )
self._debug( self._debug(
f" - Adding <c2>{pth_file.name}</c2> to <b>{pth_file.parent}</b> for" f" - Adding <c2>{pth_file.name}</c2> to <b>{pth_file.parent}</b> for"
f" {self._poetry.file.parent}" f" {self._poetry.file.path.parent}"
) )
return [pth_file] return [pth_file]
except OSError: except OSError:
# TODO: Replace with PermissionError # TODO: Replace with PermissionError
self._io.write_error_line( self._io.write_error_line(
f" - Failed to create <c2>{pth_file.name}</c2> for" f" - Failed to create <c2>{pth_file.name}</c2> for"
f" {self._poetry.file.parent}" f" {self._poetry.file.path.parent}"
) )
return [] return []
...@@ -163,7 +163,7 @@ class EditableBuilder(Builder): ...@@ -163,7 +163,7 @@ class EditableBuilder(Builder):
else: else:
self._io.write_error_line( self._io.write_error_line(
" - Failed to find a suitable script installation directory for" " - Failed to find a suitable script installation directory for"
f" {self._poetry.file.parent}" f" {self._poetry.file.path.parent}"
) )
return [] return []
......
...@@ -37,15 +37,7 @@ class Poetry(BasePoetry): ...@@ -37,15 +37,7 @@ class Poetry(BasePoetry):
) -> None: ) -> None:
from poetry.repositories.repository_pool import RepositoryPool from poetry.repositories.repository_pool import RepositoryPool
try: super().__init__(file, local_config, package, pyproject_type=PyProjectTOML)
super().__init__( # type: ignore[call-arg]
file, local_config, package, pyproject_type=PyProjectTOML
)
except TypeError:
# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
super().__init__(file, local_config, package)
self._pyproject = PyProjectTOML(file)
self._locker = locker self._locker = locker
self._config = config self._config = config
...@@ -59,7 +51,7 @@ class Poetry(BasePoetry): ...@@ -59,7 +51,7 @@ class Poetry(BasePoetry):
return cast("PyProjectTOML", pyproject) return cast("PyProjectTOML", pyproject)
@property @property
def file(self) -> TOMLFile: # type: ignore[override] def file(self) -> TOMLFile:
return self.pyproject.file return self.pyproject.file
@property @property
......
...@@ -77,7 +77,7 @@ class Uploader: ...@@ -77,7 +77,7 @@ class Uploader:
@property @property
def files(self) -> list[Path]: def files(self) -> list[Path]:
dist = self._poetry.file.parent / "dist" dist = self._poetry.file.path.parent / "dist"
version = self._package.version.to_string() version = self._package.version.to_string()
escaped_name = distribution_name(self._package.name) escaped_name = distribution_name(self._package.name)
...@@ -301,7 +301,7 @@ class Uploader: ...@@ -301,7 +301,7 @@ class Uploader:
""" """
Register a package to a repository. Register a package to a repository.
""" """
dist = self._poetry.file.parent / "dist" dist = self._poetry.file.path.parent / "dist"
escaped_name = distribution_name(self._package.name) escaped_name = distribution_name(self._package.name)
file = dist / f"{escaped_name}-{self._package.version.to_string()}.tar.gz" file = dist / f"{escaped_name}-{self._package.version.to_string()}.tar.gz"
......
...@@ -29,7 +29,7 @@ class PyProjectTOML(BasePyProjectTOML): ...@@ -29,7 +29,7 @@ class PyProjectTOML(BasePyProjectTOML):
self._toml_document: TOMLDocument | None = None self._toml_document: TOMLDocument | None = None
@property @property
def file(self) -> TOMLFile: # type: ignore[override] def file(self) -> TOMLFile:
return self._toml_file return self._toml_file
@property @property
......
...@@ -247,9 +247,7 @@ class InstalledRepository(Repository): ...@@ -247,9 +247,7 @@ class InstalledRepository(Repository):
continue continue
for distribution in sorted( for distribution in sorted(
metadata.distributions( # type: ignore[no-untyped-call] metadata.distributions(path=[entry]),
path=[entry],
),
key=lambda d: str(d._path), # type: ignore[attr-defined] key=lambda d: str(d._path), # type: ignore[attr-defined]
): ):
path = Path(str(distribution._path)) # type: ignore[attr-defined] path = Path(str(distribution._path)) # type: ignore[attr-defined]
......
from __future__ import annotations from __future__ import annotations
import warnings
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any from typing import Any
...@@ -35,6 +37,15 @@ class TOMLFile(BaseTOMLFile): ...@@ -35,6 +37,15 @@ class TOMLFile(BaseTOMLFile):
raise TOMLError(f"Invalid TOML file {self.path.as_posix()}: {e}") raise TOMLError(f"Invalid TOML file {self.path.as_posix()}: {e}")
def __getattr__(self, item: str) -> Any: def __getattr__(self, item: str) -> Any:
warnings.warn(
(
"`__getattr__` will be removed from the `TOMLFile` in a future release."
"\n\nInstead of accessing properties of the underlying `Path` as "
"`tomlfile.whatever`, prefer `tomlfile.path.whatever`."
),
DeprecationWarning,
stacklevel=2,
)
return getattr(self.__path, item) return getattr(self.__path, item)
def __str__(self) -> str: def __str__(self) -> str:
......
...@@ -289,10 +289,7 @@ class SitePackages: ...@@ -289,10 +289,7 @@ class SitePackages:
) )
) )
yield from metadata.PathDistribution.discover( # type: ignore[no-untyped-call] yield from metadata.PathDistribution.discover(name=name, path=path)
name=name,
path=path,
)
def find_distribution( def find_distribution(
self, name: str, writable_only: bool = False self, name: str, writable_only: bool = False
...@@ -310,9 +307,7 @@ class SitePackages: ...@@ -310,9 +307,7 @@ class SitePackages:
files = [] if distribution.files is None else distribution.files files = [] if distribution.files is None else distribution.files
for file in files: for file in files:
if file.name.endswith(suffix): if file.name.endswith(suffix):
yield Path( yield Path(distribution.locate_file(file))
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
def find_distribution_files_with_name( def find_distribution_files_with_name(
self, distribution_name: str, name: str, writable_only: bool = False self, distribution_name: str, name: str, writable_only: bool = False
...@@ -323,18 +318,7 @@ class SitePackages: ...@@ -323,18 +318,7 @@ class SitePackages:
files = [] if distribution.files is None else distribution.files files = [] if distribution.files is None else distribution.files
for file in files: for file in files:
if file.name == name: if file.name == name:
yield Path( yield Path(distribution.locate_file(file))
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
def find_distribution_nspkg_pth_files(
self, distribution_name: str, writable_only: bool = False
) -> Iterable[Path]:
return self.find_distribution_files_with_suffix(
distribution_name=distribution_name,
suffix="-nspkg.pth",
writable_only=writable_only,
)
def find_distribution_direct_url_json_files( def find_distribution_direct_url_json_files(
self, distribution_name: str, writable_only: bool = False self, distribution_name: str, writable_only: bool = False
...@@ -353,9 +337,8 @@ class SitePackages: ...@@ -353,9 +337,8 @@ class SitePackages:
): ):
files = [] if distribution.files is None else distribution.files files = [] if distribution.files is None else distribution.files
for file in files: for file in files:
path = Path( path = Path(distribution.locate_file(file))
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
# We can't use unlink(missing_ok=True) because it's not always available # We can't use unlink(missing_ok=True) because it's not always available
if path.exists(): if path.exists():
path.unlink() path.unlink()
...@@ -571,12 +554,12 @@ class EnvManager: ...@@ -571,12 +554,12 @@ class EnvManager:
@property @property
def in_project_venv(self) -> Path: def in_project_venv(self) -> Path:
venv: Path = self._poetry.file.parent / ".venv" venv: Path = self._poetry.file.path.parent / ".venv"
return venv return venv
def activate(self, python: str) -> Env: def activate(self, python: str) -> Env:
venv_path = self._poetry.config.virtualenvs_path venv_path = self._poetry.config.virtualenvs_path
cwd = self._poetry.file.parent cwd = self._poetry.file.path.parent
envs_file = TOMLFile(venv_path / self.ENVS_FILE) envs_file = TOMLFile(venv_path / self.ENVS_FILE)
...@@ -665,7 +648,7 @@ class EnvManager: ...@@ -665,7 +648,7 @@ class EnvManager:
def deactivate(self) -> None: def deactivate(self) -> None:
venv_path = self._poetry.config.virtualenvs_path venv_path = self._poetry.config.virtualenvs_path
name = self.generate_env_name( name = self.generate_env_name(
self._poetry.package.name, str(self._poetry.file.parent) self._poetry.package.name, str(self._poetry.file.path.parent)
) )
envs_file = TOMLFile(venv_path / self.ENVS_FILE) envs_file = TOMLFile(venv_path / self.ENVS_FILE)
...@@ -694,7 +677,7 @@ class EnvManager: ...@@ -694,7 +677,7 @@ class EnvManager:
venv_path = self._poetry.config.virtualenvs_path venv_path = self._poetry.config.virtualenvs_path
cwd = self._poetry.file.parent cwd = self._poetry.file.path.parent
envs_file = TOMLFile(venv_path / self.ENVS_FILE) envs_file = TOMLFile(venv_path / self.ENVS_FILE)
env = None env = None
base_env_name = self.generate_env_name(self._poetry.package.name, str(cwd)) base_env_name = self.generate_env_name(self._poetry.package.name, str(cwd))
...@@ -749,7 +732,7 @@ class EnvManager: ...@@ -749,7 +732,7 @@ class EnvManager:
if name is None: if name is None:
name = self._poetry.package.name name = self._poetry.package.name
venv_name = self.generate_env_name(name, str(self._poetry.file.parent)) venv_name = self.generate_env_name(name, str(self._poetry.file.path.parent))
venv_path = self._poetry.config.virtualenvs_path venv_path = self._poetry.config.virtualenvs_path
env_list = [VirtualEnv(p) for p in sorted(venv_path.glob(f"{venv_name}-py*"))] env_list = [VirtualEnv(p) for p in sorted(venv_path.glob(f"{venv_name}-py*"))]
...@@ -770,7 +753,7 @@ class EnvManager: ...@@ -770,7 +753,7 @@ class EnvManager:
def remove(self, python: str) -> Env: def remove(self, python: str) -> Env:
venv_path = self._poetry.config.virtualenvs_path venv_path = self._poetry.config.virtualenvs_path
cwd = self._poetry.file.parent cwd = self._poetry.file.path.parent
envs_file = TOMLFile(venv_path / self.ENVS_FILE) envs_file = TOMLFile(venv_path / self.ENVS_FILE)
base_env_name = self.generate_env_name(self._poetry.package.name, str(cwd)) base_env_name = self.generate_env_name(self._poetry.package.name, str(cwd))
...@@ -883,7 +866,7 @@ class EnvManager: ...@@ -883,7 +866,7 @@ class EnvManager:
if self._env is not None and not force: if self._env is not None and not force:
return self._env return self._env
cwd = self._poetry.file.parent cwd = self._poetry.file.path.parent
env = self.get(reload=True) env = self.get(reload=True)
if not env.is_sane(): if not env.is_sane():
......
...@@ -20,7 +20,7 @@ if TYPE_CHECKING: ...@@ -20,7 +20,7 @@ if TYPE_CHECKING:
def venv_name(app: PoetryTestApplication) -> str: def venv_name(app: PoetryTestApplication) -> str:
return EnvManager.generate_env_name( return EnvManager.generate_env_name(
app.poetry.package.name, app.poetry.package.name,
str(app.poetry.file.parent), str(app.poetry.file.path.parent),
) )
...@@ -58,7 +58,7 @@ def venvs_in_cache_dirs( ...@@ -58,7 +58,7 @@ def venvs_in_cache_dirs(
@pytest.fixture @pytest.fixture
def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]: def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None) os.environ.pop("VIRTUAL_ENV", None)
venv_dir = app.poetry.file.parent.joinpath(".venv") venv_dir = app.poetry.file.path.parent.joinpath(".venv")
venv_dir.mkdir(exist_ok=True) venv_dir.mkdir(exist_ok=True)
app.poetry.config.merge({"virtualenvs": {"in-project": True}}) app.poetry.config.merge({"virtualenvs": {"in-project": True}})
...@@ -71,7 +71,7 @@ def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]: ...@@ -71,7 +71,7 @@ def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]:
@pytest.fixture @pytest.fixture
def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]: def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None) os.environ.pop("VIRTUAL_ENV", None)
venv_dir = app.poetry.file.parent.joinpath(".venv") venv_dir = app.poetry.file.path.parent.joinpath(".venv")
venv_dir.mkdir(exist_ok=True) venv_dir.mkdir(exist_ok=True)
app.poetry.config.merge({"virtualenvs": {"in-project": None}}) app.poetry.config.merge({"virtualenvs": {"in-project": None}})
...@@ -84,7 +84,7 @@ def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]: ...@@ -84,7 +84,7 @@ def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]:
@pytest.fixture @pytest.fixture
def venvs_in_project_dir_false(app: PoetryTestApplication) -> Iterator[Path]: def venvs_in_project_dir_false(app: PoetryTestApplication) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None) os.environ.pop("VIRTUAL_ENV", None)
venv_dir = app.poetry.file.parent.joinpath(".venv") venv_dir = app.poetry.file.path.parent.joinpath(".venv")
venv_dir.mkdir(exist_ok=True) venv_dir.mkdir(exist_ok=True)
app.poetry.config.merge({"virtualenvs": {"in-project": False}}) app.poetry.config.merge({"virtualenvs": {"in-project": False}})
......
...@@ -95,7 +95,7 @@ def test_builder_installs_proper_files_for_standard_packages( ...@@ -95,7 +95,7 @@ def test_builder_installs_proper_files_for_standard_packages(
pth_file = Path("simple_project.pth") pth_file = Path("simple_project.pth")
assert tmp_venv.site_packages.exists(pth_file) assert tmp_venv.site_packages.exists(pth_file)
assert ( assert (
simple_poetry.file.parent.resolve().as_posix() simple_poetry.file.path.parent.resolve().as_posix()
== tmp_venv.site_packages.find(pth_file)[0].read_text().strip(os.linesep) == tmp_venv.site_packages.find(pth_file)[0].read_text().strip(os.linesep)
) )
...@@ -281,7 +281,7 @@ def test_builder_installs_proper_files_when_packages_configured( ...@@ -281,7 +281,7 @@ def test_builder_installs_proper_files_when_packages_configured(
if line: if line:
paths.add(line) paths.add(line)
project_root = project_with_include.file.parent.resolve() project_root = project_with_include.file.path.parent.resolve()
expected = {project_root.as_posix(), project_root.joinpath("src").as_posix()} expected = {project_root.as_posix(), project_root.joinpath("src").as_posix()}
assert paths.issubset(expected) assert paths.issubset(expected)
...@@ -339,5 +339,5 @@ def test_builder_should_execute_build_scripts( ...@@ -339,5 +339,5 @@ def test_builder_should_execute_build_scripts(
builder.build() builder.build()
assert [ assert [
["python", str(extended_without_setup_poetry.file.parent / "build.py")] ["python", str(extended_without_setup_poetry.file.path.parent / "build.py")]
] == env.executed ] == env.executed
...@@ -25,4 +25,5 @@ def test_pyproject_toml_file_invalid(pyproject_toml: Path) -> None: ...@@ -25,4 +25,5 @@ def test_pyproject_toml_file_invalid(pyproject_toml: Path) -> None:
def test_pyproject_toml_file_getattr(tmp_path: Path, pyproject_toml: Path) -> None: def test_pyproject_toml_file_getattr(tmp_path: Path, pyproject_toml: Path) -> None:
file = TOMLFile(pyproject_toml) file = TOMLFile(pyproject_toml)
assert file.parent == tmp_path with pytest.warns(DeprecationWarning):
assert file.parent == tmp_path
...@@ -17,5 +17,5 @@ def venv_name( ...@@ -17,5 +17,5 @@ def venv_name(
) -> str: ) -> str:
return manager.generate_env_name( return manager.generate_env_name(
poetry.package.name, poetry.package.name,
str(poetry.file.parent), str(poetry.file.path.parent),
) )
...@@ -157,7 +157,7 @@ def test_env_get_supported_tags_matches_inside_virtualenv( ...@@ -157,7 +157,7 @@ def test_env_get_supported_tags_matches_inside_virtualenv(
@pytest.fixture @pytest.fixture
def in_project_venv_dir(poetry: Poetry) -> Iterator[Path]: def in_project_venv_dir(poetry: Poetry) -> Iterator[Path]:
os.environ.pop("VIRTUAL_ENV", None) os.environ.pop("VIRTUAL_ENV", None)
venv_dir = poetry.file.parent.joinpath(".venv") venv_dir = poetry.file.path.parent.joinpath(".venv")
venv_dir.mkdir() venv_dir.mkdir()
try: try:
yield venv_dir yield venv_dir
...@@ -842,7 +842,7 @@ def test_raises_if_acting_on_different_project_by_name( ...@@ -842,7 +842,7 @@ def test_raises_if_acting_on_different_project_by_name(
different_venv_name = ( different_venv_name = (
EnvManager.generate_env_name( EnvManager.generate_env_name(
"different-project", "different-project",
str(poetry.file.parent), str(poetry.file.path.parent),
) )
+ "-py3.6" + "-py3.6"
) )
...@@ -1344,7 +1344,9 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable( ...@@ -1344,7 +1344,9 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
version = Version.from_parts(*sys.version_info[:3]) version = Version.from_parts(*sys.version_info[:3])
assert version.minor is not None assert version.minor is not None
poetry.package.python_versions = f"~{version.major}.{version.minor - 1}.0" poetry.package.python_versions = f"~{version.major}.{version.minor - 1}.0"
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent)) venv_name = manager.generate_env_name(
"simple-project", str(poetry.file.path.parent)
)
check_output = mocker.patch( check_output = mocker.patch(
"subprocess.check_output", "subprocess.check_output",
...@@ -1433,7 +1435,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( ...@@ -1433,7 +1435,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
manager.activate("python3.7") manager.activate("python3.7")
m.assert_called_with( m.assert_called_with(
poetry.file.parent / ".venv", poetry.file.path.parent / ".venv",
executable=Path("/usr/bin/python3.7"), executable=Path("/usr/bin/python3.7"),
flags={ flags={
"always-copy": False, "always-copy": False,
...@@ -1772,7 +1774,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt( ...@@ -1772,7 +1774,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt(
manager = EnvManager(poetry) manager = EnvManager(poetry)
poetry.package.python_versions = "^3.7" poetry.package.python_versions = "^3.7"
venv_name = manager.generate_env_name("", str(poetry.file.parent)) venv_name = manager.generate_env_name("", str(poetry.file.path.parent))
mocker.patch("sys.version_info", (2, 7, 16)) mocker.patch("sys.version_info", (2, 7, 16))
mocker.patch("shutil.which", side_effect=lambda py: f"/usr/bin/{py}") mocker.patch("shutil.which", side_effect=lambda py: f"/usr/bin/{py}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment