Skip to content

Commit 1cdefb4

Browse files
committed
Add & use work_dir accessor
1 parent 46bef9e commit 1cdefb4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/tox/tox_env/api.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ToxEnvCreateArgs(NamedTuple):
4242
log_handler: ToxHandler
4343

4444

45-
class ToxEnv(ABC):
45+
class ToxEnv(ABC): # noqa: PLR0904
4646
"""A tox environment."""
4747

4848
def __init__(self, create_args: ToxEnvCreateArgs) -> None:
@@ -111,19 +111,19 @@ def register_config(self) -> None:
111111
self.conf.add_config(
112112
keys=["env_dir", "envdir"],
113113
of_type=Path,
114-
default=lambda conf, name: cast(Path, conf.core["work_dir"]) / self.name, # noqa: ARG005
114+
default=lambda conf, name: self.work_dir / self.name, # noqa: ARG005
115115
desc="directory assigned to the tox environment",
116116
)
117117
self.conf.add_config(
118118
keys=["env_tmp_dir", "envtmpdir"],
119119
of_type=Path,
120-
default=lambda conf, name: cast(Path, conf.core["work_dir"]) / self.name / "tmp", # noqa: ARG005
120+
default=lambda conf, name: self.work_dir / self.name / "tmp", # noqa: ARG005
121121
desc="a folder that is always reset at the start of the run",
122122
)
123123
self.conf.add_config(
124124
keys=["env_log_dir", "envlogdir"],
125125
of_type=Path,
126-
default=lambda conf, name: cast(Path, conf.core["work_dir"]) / self.name / "log", # noqa: ARG005
126+
default=lambda conf, name: self.work_dir / self.name / "log", # noqa: ARG005
127127
desc="a folder for logging where tox will put logs of tool invocation",
128128
)
129129
self.executor.register_conf(self)
@@ -194,6 +194,11 @@ def env_log_dir(self) -> Path:
194194
""":return: the tox environments log folder"""
195195
return cast(Path, self.conf["env_log_dir"])
196196

197+
@property
198+
def work_dir(self) -> Path:
199+
""":return: the tox work dir folder"""
200+
return cast(Path, self.core["work_dir"])
201+
197202
@property
198203
def name(self) -> str:
199204
return cast(str, self.conf["env_name"])
@@ -342,8 +347,8 @@ def environment_variables(self) -> dict[str, str]:
342347
for key in set_env:
343348
result[key] = set_env.load(key)
344349
result["TOX_ENV_NAME"] = self.name
345-
result["TOX_WORK_DIR"] = str(self.core["work_dir"])
346-
result["TOX_ENV_DIR"] = str(self.conf["env_dir"])
350+
result["TOX_WORK_DIR"] = str(self.work_dir)
351+
result["TOX_ENV_DIR"] = str(self.env_dir)
347352
return result
348353

349354
@staticmethod

0 commit comments

Comments
 (0)