From f5989d4ed907a2a35c90c8f713159cd278b010c9 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Thu, 22 Apr 2021 15:41:32 +0100 Subject: [PATCH] Make `pip.*` operation virtualenv management idempotent. --- pyinfra/operations/pip.py | 7 +++++++ .../pip.packages/add_new_virtualenv_packages.json | 3 +-- tests/operations/pip.venv/add_virtualenv.json | 3 +-- tests/operations/pip.virtualenv/add_virtualenv.json | 3 +-- tests/operations/pip.virtualenv/add_virtualenv_py3.json | 3 +-- tests/operations/pip.virtualenv/add_with_options.json | 3 +-- .../operations/pip.virtualenv/present_empty_directory.json | 3 +-- tests/operations/pip.virtualenv/use_stdlib_venv.json | 3 +-- tests/operations/pip.virtualenv/use_stdlib_venv_py3.json | 3 +-- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pyinfra/operations/pip.py b/pyinfra/operations/pip.py index d2e2ba58f..0f350a4a2 100644 --- a/pyinfra/operations/pip.py +++ b/pyinfra/operations/pip.py @@ -43,6 +43,7 @@ def virtualenv( if present is False: if host.fact.file(activate_script_path): yield files.directory(path, present=False, state=state, host=host) + host.fact._delete('file', args=(activate_script_path,)) else: host.noop('virtualenv {0} does not exist'.format(path)) @@ -68,6 +69,12 @@ def virtualenv( command.append(path) yield ' '.join(command) + + host.fact._create( + 'file', + args=(activate_script_path,), + data={'user': None, 'group': None}, + ) else: host.noop('virtualenv {0} exists'.format(path)) diff --git a/tests/operations/pip.packages/add_new_virtualenv_packages.json b/tests/operations/pip.packages/add_new_virtualenv_packages.json index c72eec9c1..61165d1c0 100644 --- a/tests/operations/pip.packages/add_new_virtualenv_packages.json +++ b/tests/operations/pip.packages/add_new_virtualenv_packages.json @@ -20,6 +20,5 @@ "commands": [ "virtualenv --system-site-packages testdir", "testdir/bin/pip install elasticquery==1.1 flask" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.venv/add_virtualenv.json b/tests/operations/pip.venv/add_virtualenv.json index 3449a93b0..1f8d0e4a8 100644 --- a/tests/operations/pip.venv/add_virtualenv.json +++ b/tests/operations/pip.venv/add_virtualenv.json @@ -10,6 +10,5 @@ }, "commands": [ "python -m venv --copies /some/virtualenv" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.virtualenv/add_virtualenv.json b/tests/operations/pip.virtualenv/add_virtualenv.json index 96b84e387..3d32703bc 100644 --- a/tests/operations/pip.virtualenv/add_virtualenv.json +++ b/tests/operations/pip.virtualenv/add_virtualenv.json @@ -9,6 +9,5 @@ }, "commands": [ "virtualenv /some/virtualenv" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.virtualenv/add_virtualenv_py3.json b/tests/operations/pip.virtualenv/add_virtualenv_py3.json index 810b3fb1b..cd3d4fe06 100644 --- a/tests/operations/pip.virtualenv/add_virtualenv_py3.json +++ b/tests/operations/pip.virtualenv/add_virtualenv_py3.json @@ -10,6 +10,5 @@ }, "commands": [ "virtualenv -p python3 /some/virtualenv" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.virtualenv/add_with_options.json b/tests/operations/pip.virtualenv/add_with_options.json index e55574c8f..730b36f25 100644 --- a/tests/operations/pip.virtualenv/add_with_options.json +++ b/tests/operations/pip.virtualenv/add_with_options.json @@ -12,6 +12,5 @@ }, "commands": [ "virtualenv -p python2 --system-site-packages --always-copy /some/virtualenv" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.virtualenv/present_empty_directory.json b/tests/operations/pip.virtualenv/present_empty_directory.json index 8ce8d6d8a..6a5478cf8 100644 --- a/tests/operations/pip.virtualenv/present_empty_directory.json +++ b/tests/operations/pip.virtualenv/present_empty_directory.json @@ -12,6 +12,5 @@ }, "commands": [ "virtualenv /some/virtualenv" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.virtualenv/use_stdlib_venv.json b/tests/operations/pip.virtualenv/use_stdlib_venv.json index 4fb29199d..38848af23 100644 --- a/tests/operations/pip.virtualenv/use_stdlib_venv.json +++ b/tests/operations/pip.virtualenv/use_stdlib_venv.json @@ -11,6 +11,5 @@ }, "commands": [ "python -m venv --copies /some/virtualenv" - ], - "idempotent": false + ] } diff --git a/tests/operations/pip.virtualenv/use_stdlib_venv_py3.json b/tests/operations/pip.virtualenv/use_stdlib_venv_py3.json index 6a7298411..2cdc0eb1c 100644 --- a/tests/operations/pip.virtualenv/use_stdlib_venv_py3.json +++ b/tests/operations/pip.virtualenv/use_stdlib_venv_py3.json @@ -11,6 +11,5 @@ }, "commands": [ "python3 -m venv /some/virtualenv" - ], - "idempotent": false + ] }