1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
From 02dbaa46ef2c75c5863628cc8f77d37a18d2c051 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Arnold=20Cz=C3=A9m=C3=A1n?= <arnold.czeman@balabit.com>
Date: Thu, 22 Oct 2020 14:26:56 +0200
Subject: [PATCH] dh_virtualenv/deployment.py: fix virtualenv options
The built-in python3 venv has neither '--setuptools',
nor '--verbose' switch.
---
dh_virtualenv/cmdline.py | 30 ++++++++++++++++++++++++++++--
dh_virtualenv/deployment.py | 8 ++++----
doc/changes.rst | 5 +++++
doc/usage.rst | 1 +
test/test_cmdline.py | 16 ++++++++++++++++
test/test_deployment.py | 14 ++++++++++++++
6 files changed, 68 insertions(+), 6 deletions(-)
Index: dh-virtualenv-1.2.2/dh_virtualenv/cmdline.py
===================================================================
--- dh-virtualenv-1.2.2.orig/dh_virtualenv/cmdline.py 2025-05-04 20:04:23.607140286 +0200
+++ dh-virtualenv-1.2.2/dh_virtualenv/cmdline.py 2025-05-04 20:04:23.599140410 +0200
@@ -77,6 +77,28 @@
setattr(parser.values, '_test_flag_seen', True)
+def _set_builtin_venv(
+ option, opt_str, value, parser, *args, **kwargs
+):
+ if parser.values.setuptools:
+ raise OptionValueError(
+ '--setuptools flag is not supported by builtin venv module'
+ )
+ else:
+ parser.values.builtin_venv = True
+
+
+def _set_setuptools(
+ option, opt_str, value, parser, *args, **kwargs
+):
+ if parser.values.builtin_venv:
+ raise OptionValueError(
+ '--setuptools flag is not supported by builtin venv module'
+ )
+ else:
+ parser.values.setuptools = True
+
+
def get_default_parser():
usage = '%prog [options]'
parser = DebhelperOptionParser(usage, version='%prog ' + version)
@@ -86,7 +108,9 @@
help='Do not act on the specified package(s)')
parser.add_option('-v', '--verbose', action='store_true',
default=False, help='Turn on verbose mode')
- parser.add_option('-s', '--setuptools', action='store_true',
+ parser.add_option('-s', '--setuptools', action='callback',
+ dest='setuptools',
+ callback=_set_setuptools,
default=False, help='Use Setuptools instead of Distribute')
parser.add_option('--extra-index-url', action='append', metavar='URL',
help='Extra index URL(s) to pass to pip.',
@@ -124,7 +148,9 @@
callback=_check_for_deprecated_options)
parser.add_option('--python', metavar='EXECUTABLE',
help='The Python command to use')
- parser.add_option('--builtin-venv', action='store_true',
+ parser.add_option('--builtin-venv', action='callback',
+ dest='builtin_venv',
+ callback=_set_builtin_venv,
help='Use the built-in venv module. Only works on '
'Python 3.4 and later.')
parser.add_option('-D', '--sourcedirectory', dest='sourcedirectory',
Index: dh-virtualenv-1.2.2/dh_virtualenv/deployment.py
===================================================================
--- dh-virtualenv-1.2.2.orig/dh_virtualenv/deployment.py 2025-05-04 20:04:23.607140286 +0200
+++ dh-virtualenv-1.2.2/dh_virtualenv/deployment.py 2025-05-04 20:04:23.599140410 +0200
@@ -150,11 +150,11 @@
if self.python:
virtualenv.extend(('--python', self.python))
- if self.setuptools:
- virtualenv.append('--setuptools')
+ if self.setuptools:
+ virtualenv.append('--setuptools')
- if self.verbose:
- virtualenv.append('--verbose')
+ if self.verbose:
+ virtualenv.append('--verbose')
# Add in any user supplied virtualenv args
if self.extra_virtualenv_arg:
Index: dh-virtualenv-1.2.2/doc/changes.rst
===================================================================
--- dh-virtualenv-1.2.2.orig/doc/changes.rst 2025-05-04 20:04:23.607140286 +0200
+++ dh-virtualenv-1.2.2/doc/changes.rst 2025-05-04 20:04:23.603140347 +0200
@@ -8,6 +8,11 @@
.. _`git history`: https://github.com/spotify/dh-virtualenv/commits/master
+Unreleased
+==========
+
+* Fix --verbose and --setuptools command line argument usage together with --builtin-venv
+
1.2.2
=====
Index: dh-virtualenv-1.2.2/doc/usage.rst
===================================================================
--- dh-virtualenv-1.2.2.orig/doc/usage.rst 2025-05-04 20:04:23.607140286 +0200
+++ dh-virtualenv-1.2.2/doc/usage.rst 2025-05-04 20:04:23.603140347 +0200
@@ -189,6 +189,7 @@
.. option:: --setuptools
Use setuptools instead of distribute in the virtualenv.
+ Not supported when using builtin `venv` module with :option:`--builtin-venv`.
.. option:: --setuptools-test
Index: dh-virtualenv-1.2.2/test/test_cmdline.py
===================================================================
--- dh-virtualenv-1.2.2.orig/test/test_cmdline.py 2025-05-04 20:04:23.607140286 +0200
+++ dh-virtualenv-1.2.2/test/test_cmdline.py 2025-05-04 20:04:23.603140347 +0200
@@ -170,3 +170,19 @@
parser = cmdline.get_default_parser()
opts, args = parser.parse_args(['--use-system-packages'])
eq_(True, opts.use_system_packages)
+
+
+def test_builtin_venv_and_setuptools_conflict():
+ error_message = '--setuptools flag is not supported by builtin venv module'
+ args_list = [
+ ['--builtin-venv', '--setuptools'],
+ ['--setuptools', '--builtin-venv'],
+ ]
+
+ for args in args_list:
+ f = get_mocked_stderr()
+ with patch('sys.stderr', f), patch('sys.exit') as sysexit:
+ parser = cmdline.get_default_parser()
+ parser.parse_args(args)
+ ok_(error_message in f.getvalue())
+ sysexit.assert_called_once_with(2)
Index: dh-virtualenv-1.2.2/test/test_deployment.py
===================================================================
--- dh-virtualenv-1.2.2.orig/test/test_deployment.py 2025-05-04 20:04:23.607140286 +0200
+++ dh-virtualenv-1.2.2/test/test_deployment.py 2025-05-04 20:04:23.603140347 +0200
@@ -355,6 +355,20 @@
@patch('tempfile.NamedTemporaryFile', FakeTemporaryFile)
@patch('subprocess.check_call')
+def test_create_builtin_venv_with_unsupported_options(callmock):
+ d = Deployment(
+ 'test', python='python_interpreter',
+ builtin_venv=True, setuptools=True, verbose=True
+ )
+ d.create_virtualenv()
+ eq_(TEST_VENV_PATH, d.package_dir)
+ callmock.assert_called_with(
+ ['python_interpreter', '-m', 'venv', TEST_VENV_PATH]
+ )
+
+
+@patch('tempfile.NamedTemporaryFile', FakeTemporaryFile)
+@patch('subprocess.check_call')
def test_install_package(callmock):
d = Deployment('test')
d.bin_dir = 'derp'
|