From bfbc61a4b7846710d422700a8aad4bf98398a33a Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Mon, 10 Aug 2020 11:58:17 +0200 Subject: [PATCH] Avoid requiring admin rights on Windows This fixes an error on Windows (I'm on with Python 3.7) where the symlink cannot be created without admin rights. https://github.com/fedora-python/tox-current-env/pull/24 --- src/tox_current_env/hooks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index 2dd90b9..16dd679 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -1,5 +1,6 @@ import os import shutil +import subprocess import sys import tox @@ -134,7 +135,11 @@ def tox_testenv_create(venv, action): target = sys.executable rm_venv(venv) os.makedirs(os.path.dirname(link)) - os.symlink(target, link) + if sys.platform == "win32": + # Avoid requiring admin rights on Windows + subprocess.check_call(f'mklink /J "{link}" "{target}"', shell=True) + else: + os.symlink(target, link) # prevent tox from creating the venv return True if not is_proper_venv(venv):