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