Skip to content

Commit 2170e1e

Browse files
hengkuanweeKuan Wee HengAntoineD
authored
fix-conda-temp-file-permission-error (#161)
* fix-conda-temp-file-permission-error * Fix test for conda env creation * Bump pre-commit isort version to fix poetry dependency issue * Fix basepython for pkg_meta target --------- Co-authored-by: Kuan Wee Heng <[email protected]> Co-authored-by: Antoine Dechaume <[email protected]>
1 parent 099ec51 commit 2170e1e

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
args:
1919
- --py3-plus
2020
- repo: https://github.com/PyCQA/isort
21-
rev: 5.11.4
21+
rev: 5.12.0
2222
hooks:
2323
- id: isort
2424
- repo: https://github.com/psf/black

tests/test_conda_env.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22
import os
3+
import pathlib
34
import re
45
from unittest.mock import mock_open, patch
56

@@ -278,10 +279,12 @@ def test_conda_env(tmpdir, newconfig, mocksession):
278279

279280
mock_file = mock_open()
280281
with patch("tox_conda.plugin.tempfile.NamedTemporaryFile", mock_file):
281-
with mocksession.newaction(venv.name, "getenv") as action:
282-
tox_testenv_create(action=action, venv=venv)
282+
with patch.object(pathlib.Path, "unlink", autospec=True) as mock_unlink:
283+
with mocksession.newaction(venv.name, "getenv") as action:
284+
tox_testenv_create(action=action, venv=venv)
285+
mock_unlink.assert_called_once
283286

284-
mock_file.assert_called_with(dir=tmpdir, prefix="tox_conda_tmp", suffix=".yaml")
287+
mock_file.assert_called_with(dir=tmpdir, prefix="tox_conda_tmp", suffix=".yaml", delete=False)
285288

286289
pcalls = mocksession._pcalls
287290
assert len(pcalls) >= 1
@@ -335,10 +338,12 @@ def test_conda_env_and_spec(tmpdir, newconfig, mocksession):
335338

336339
mock_file = mock_open()
337340
with patch("tox_conda.plugin.tempfile.NamedTemporaryFile", mock_file):
338-
with mocksession.newaction(venv.name, "getenv") as action:
339-
tox_testenv_create(action=action, venv=venv)
341+
with patch.object(pathlib.Path, "unlink", autospec=True) as mock_unlink:
342+
with mocksession.newaction(venv.name, "getenv") as action:
343+
tox_testenv_create(action=action, venv=venv)
344+
mock_unlink.assert_called_once
340345

341-
mock_file.assert_called_with(dir=tmpdir, prefix="tox_conda_tmp", suffix=".yaml")
346+
mock_file.assert_called_with(dir=tmpdir, prefix="tox_conda_tmp", suffix=".yaml", delete=False)
342347

343348
pcalls = mocksession._pcalls
344349
assert len(pcalls) >= 1

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ depends =
7373

7474
[testenv:pkg_meta]
7575
description = check that the long description is valid
76-
basepython = python3.9
76+
basepython = python3.10
7777
skip_install = true
7878
deps =
7979
build>=0.0.4

tox_conda/plugin.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,27 @@ def tox_testenv_create(venv, action):
168168
env_file = yaml.load(env_path)
169169
env_file["dependencies"].append(python)
170170

171-
with tempfile.NamedTemporaryFile(
172-
dir=env_path.parent, prefix="tox_conda_tmp", suffix=".yaml"
173-
) as tmp_env:
174-
yaml.dump(env_file, tmp_env)
175-
176-
args = [
177-
venv.envconfig.conda_exe,
178-
"env",
179-
"create",
180-
"-p",
181-
envdir,
182-
"--file",
183-
tmp_env.name,
184-
]
185-
186-
_run_conda_process(args, venv, action, basepath)
171+
tmp_env = tempfile.NamedTemporaryFile(
172+
dir=env_path.parent,
173+
prefix="tox_conda_tmp",
174+
suffix=".yaml",
175+
delete=False,
176+
)
177+
yaml.dump(env_file, tmp_env)
178+
179+
args = [
180+
venv.envconfig.conda_exe,
181+
"env",
182+
"create",
183+
"-p",
184+
envdir,
185+
"--file",
186+
tmp_env.name,
187+
]
188+
tmp_env.close()
189+
_run_conda_process(args, venv, action, basepath)
190+
Path(tmp_env.name).unlink()
191+
187192
else:
188193
args = [venv.envconfig.conda_exe, "create", "--yes", "-p", envdir]
189194
for channel in venv.envconfig.conda_channels:

0 commit comments

Comments
 (0)