From cbdc4b9ad9bdb20a4e0ad17f9d5af26147b771f9 Mon Sep 17 00:00:00 2001 From: adroullier Date: Thu, 19 Oct 2023 17:40:31 +0200 Subject: [PATCH 1/7] Adding script name to 'global_config' during application setup as '__script__' --- docs/narr/startup.rst | 4 +++- src/pyramid/scripts/prequest.py | 4 ++++ src/pyramid/scripts/proutes.py | 4 ++++ src/pyramid/scripts/pserve.py | 4 ++++ src/pyramid/scripts/pshell.py | 4 ++++ src/pyramid/scripts/ptweens.py | 4 ++++ src/pyramid/scripts/pviews.py | 4 ++++ tests/test_scripts/test_prequest.py | 7 ++++++- tests/test_scripts/test_pserve.py | 2 +- 9 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/narr/startup.rst b/docs/narr/startup.rst index 37825d2dad..27970ed88b 100644 --- a/docs/narr/startup.rst +++ b/docs/narr/startup.rst @@ -101,7 +101,9 @@ Here's a high-level time-ordered overview of what happens when you press Note that the constructor function accepts a ``global_config`` argument, which is a dictionary of key/value pairs mentioned in the ``[DEFAULT]`` section of an ``.ini`` file (if :ref:`[DEFAULT] - ` is present). It also accepts a + ` is present) and the executing + script name ``__script__`` like ``pserve``, ``prequest`` or ``pshell``. + It also accepts a ``**settings`` argument, which collects another set of arbitrary key/value pairs. The arbitrary key/value pairs received by this function in ``**settings`` will be composed of all the key/value pairs that are present diff --git a/src/pyramid/scripts/prequest.py b/src/pyramid/scripts/prequest.py index ab5e81dfc3..b7f1484302 100644 --- a/src/pyramid/scripts/prequest.py +++ b/src/pyramid/scripts/prequest.py @@ -45,6 +45,7 @@ class PRequestCommand: the request's WSGI environment, so your application can distinguish these calls from normal requests. """ + script_name = 'prequest' parser = argparse.ArgumentParser( description=textwrap.dedent(description), @@ -136,6 +137,9 @@ def run(self): return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) + # bw update 2.1 don't overwrite if set + if not '__script__' in config_vars: + config_vars['__script__'] = self.script_name path = self.args.path_info loader = self._get_config_loader(config_uri) diff --git a/src/pyramid/scripts/proutes.py b/src/pyramid/scripts/proutes.py index 9c54c06ccd..ec3075be68 100644 --- a/src/pyramid/scripts/proutes.py +++ b/src/pyramid/scripts/proutes.py @@ -224,6 +224,7 @@ class PRoutesCommand: will be assumed. Example: 'proutes myapp.ini'. """ + script_name = 'proutes' bootstrap = staticmethod(bootstrap) # testing get_config_loader = staticmethod(get_config_loader) # testing stdout = sys.stdout @@ -316,6 +317,9 @@ def run(self, quiet=False): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) + # bw update 2.1 don't overwrite if set + if not '__script__' in config_vars: + config_vars['__script__'] = self.script_name loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) self.proutes_file_config(loader, config_vars) diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py index 0c4782ce59..48048f8931 100644 --- a/src/pyramid/scripts/pserve.py +++ b/src/pyramid/scripts/pserve.py @@ -39,6 +39,7 @@ class PServeCommand: You can also include variable assignments like 'http_port=8080' and then use %(http_port)s in your config files. """ + script_name = 'pserve' default_verbosity = 1 parser = argparse.ArgumentParser( @@ -183,6 +184,9 @@ def run(self): # pragma: no cover return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) + # bw update 2.1 don't overwrite if set + if not '__script__' in config_vars: + config_vars['__script__'] = self.script_name app_spec = self.args.config_uri app_name = self.args.app_name diff --git a/src/pyramid/scripts/pshell.py b/src/pyramid/scripts/pshell.py index 09baf17363..c5e5c2fb29 100644 --- a/src/pyramid/scripts/pshell.py +++ b/src/pyramid/scripts/pshell.py @@ -38,6 +38,7 @@ class PShellCommand: than one Pyramid application within it, the loader will use the last one. """ + script_name = 'pshell' bootstrap = staticmethod(bootstrap) # for testing get_config_loader = staticmethod(get_config_loader) # for testing pkg_resources = pkg_resources # for testing @@ -130,6 +131,9 @@ def run(self, shell=None): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) + # bw update 2.1 don't overwrite if set + if not '__script__' in config_vars: + config_vars['__script__'] = self.script_name loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) self.pshell_file_config(loader, config_vars) diff --git a/src/pyramid/scripts/ptweens.py b/src/pyramid/scripts/ptweens.py index 494575ff72..ca84691692 100644 --- a/src/pyramid/scripts/ptweens.py +++ b/src/pyramid/scripts/ptweens.py @@ -27,6 +27,7 @@ class PTweensCommand: will be assumed. Example: "ptweens myapp.ini#main". """ + script_name = 'ptweens' parser = argparse.ArgumentParser( description=textwrap.dedent(description), formatter_class=argparse.RawDescriptionHelpFormatter, @@ -81,6 +82,9 @@ def run(self): return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) + # bw update 2.1 don't overwrite if set + if not '__script__' in config_vars: + config_vars['__script__'] = self.script_name self.setup_logging(config_uri, global_conf=config_vars) env = self.bootstrap(config_uri, options=config_vars) registry = env['registry'] diff --git a/src/pyramid/scripts/pviews.py b/src/pyramid/scripts/pviews.py index f35daad457..da9881434b 100644 --- a/src/pyramid/scripts/pviews.py +++ b/src/pyramid/scripts/pviews.py @@ -27,6 +27,7 @@ class PViewsCommand: specifies the path info portion of a URL that will be used to find matching views. Example: 'proutes myapp.ini#main /url' """ + script_name = 'pviews' stdout = sys.stdout parser = argparse.ArgumentParser( @@ -248,6 +249,9 @@ def run(self): return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) + # bw update 2.1 don't overwrite if set + if not '__script__' in config_vars: + config_vars['__script__'] = self.script_name url = self.args.url self.setup_logging(config_uri, global_conf=config_vars) diff --git a/tests/test_scripts/test_prequest.py b/tests/test_scripts/test_prequest.py index 2214f63501..97786ec83c 100644 --- a/tests/test_scripts/test_prequest.py +++ b/tests/test_scripts/test_prequest.py @@ -234,10 +234,15 @@ def test_command_response_has_no_charset(self): self.assertEqual(self._out, [b'abc']) def test_command_method_configures_logging(self): - command = self._makeOne(['', 'development.ini', '/']) + command = self._makeOne(['', '--method=GET', 'development.ini', '/']) command.run() self.assertEqual(self.loader.calls[0]['op'], 'logging') + def test_command_script_name(self): + command = self._makeOne(['', '--method=GET', 'development.ini', '/'],) + command.run() + self.assertEqual(self.loader.calls[0]['defaults']['__script__'], 'prequest') + class Test_main(unittest.TestCase): def _callFUT(self, argv): diff --git a/tests/test_scripts/test_pserve.py b/tests/test_scripts/test_pserve.py index 5e5c28c7bb..0b010692ab 100644 --- a/tests/test_scripts/test_pserve.py +++ b/tests/test_scripts/test_pserve.py @@ -47,7 +47,7 @@ def get_app(name, global_conf): self.loader.server = lambda x: x inst.run() - self.assertEqual(app.global_conf, {'a': '1', 'b': '2'}) + self.assertEqual(app.global_conf, {'a': '1', 'b': '2', '__script__': 'pserve'}) def test_original_ignore_files(self): msg = 'A change to "ignore_files" was detected' From 3851999c01da2983b794ab2eef38141a1f57350b Mon Sep 17 00:00:00 2001 From: adroullier Date: Tue, 24 Oct 2023 14:01:24 +0200 Subject: [PATCH 2/7] Fix 'tox -e lint' tests --- src/pyramid/scripts/prequest.py | 2 +- src/pyramid/scripts/proutes.py | 2 +- src/pyramid/scripts/pserve.py | 2 +- src/pyramid/scripts/pshell.py | 2 +- src/pyramid/scripts/ptweens.py | 2 +- src/pyramid/scripts/pviews.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pyramid/scripts/prequest.py b/src/pyramid/scripts/prequest.py index b7f1484302..3db2688966 100644 --- a/src/pyramid/scripts/prequest.py +++ b/src/pyramid/scripts/prequest.py @@ -138,7 +138,7 @@ def run(self): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name path = self.args.path_info diff --git a/src/pyramid/scripts/proutes.py b/src/pyramid/scripts/proutes.py index ec3075be68..fdafc68803 100644 --- a/src/pyramid/scripts/proutes.py +++ b/src/pyramid/scripts/proutes.py @@ -318,7 +318,7 @@ def run(self, quiet=False): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py index 48048f8931..55878c3fa4 100644 --- a/src/pyramid/scripts/pserve.py +++ b/src/pyramid/scripts/pserve.py @@ -185,7 +185,7 @@ def run(self): # pragma: no cover config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name app_spec = self.args.config_uri app_name = self.args.app_name diff --git a/src/pyramid/scripts/pshell.py b/src/pyramid/scripts/pshell.py index c5e5c2fb29..ba51745f35 100644 --- a/src/pyramid/scripts/pshell.py +++ b/src/pyramid/scripts/pshell.py @@ -132,7 +132,7 @@ def run(self, shell=None): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) diff --git a/src/pyramid/scripts/ptweens.py b/src/pyramid/scripts/ptweens.py index ca84691692..1722d92617 100644 --- a/src/pyramid/scripts/ptweens.py +++ b/src/pyramid/scripts/ptweens.py @@ -83,7 +83,7 @@ def run(self): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name self.setup_logging(config_uri, global_conf=config_vars) env = self.bootstrap(config_uri, options=config_vars) diff --git a/src/pyramid/scripts/pviews.py b/src/pyramid/scripts/pviews.py index da9881434b..94c8438212 100644 --- a/src/pyramid/scripts/pviews.py +++ b/src/pyramid/scripts/pviews.py @@ -250,7 +250,7 @@ def run(self): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name url = self.args.url From 74d675cea04335a17600a65bee8e0b0c5ca058a7 Mon Sep 17 00:00:00 2001 From: adroullier Date: Tue, 24 Oct 2023 14:01:24 +0200 Subject: [PATCH 3/7] Fix 'tox -e lint' tests --- src/pyramid/scripts/prequest.py | 2 +- src/pyramid/scripts/proutes.py | 2 +- src/pyramid/scripts/pserve.py | 2 +- src/pyramid/scripts/pshell.py | 2 +- src/pyramid/scripts/ptweens.py | 2 +- src/pyramid/scripts/pviews.py | 2 +- tests/test_scripts/test_prequest.py | 5 ++++- tests/test_scripts/test_pserve.py | 5 ++++- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pyramid/scripts/prequest.py b/src/pyramid/scripts/prequest.py index b7f1484302..3db2688966 100644 --- a/src/pyramid/scripts/prequest.py +++ b/src/pyramid/scripts/prequest.py @@ -138,7 +138,7 @@ def run(self): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name path = self.args.path_info diff --git a/src/pyramid/scripts/proutes.py b/src/pyramid/scripts/proutes.py index ec3075be68..fdafc68803 100644 --- a/src/pyramid/scripts/proutes.py +++ b/src/pyramid/scripts/proutes.py @@ -318,7 +318,7 @@ def run(self, quiet=False): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py index 48048f8931..55878c3fa4 100644 --- a/src/pyramid/scripts/pserve.py +++ b/src/pyramid/scripts/pserve.py @@ -185,7 +185,7 @@ def run(self): # pragma: no cover config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name app_spec = self.args.config_uri app_name = self.args.app_name diff --git a/src/pyramid/scripts/pshell.py b/src/pyramid/scripts/pshell.py index c5e5c2fb29..ba51745f35 100644 --- a/src/pyramid/scripts/pshell.py +++ b/src/pyramid/scripts/pshell.py @@ -132,7 +132,7 @@ def run(self, shell=None): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) diff --git a/src/pyramid/scripts/ptweens.py b/src/pyramid/scripts/ptweens.py index ca84691692..1722d92617 100644 --- a/src/pyramid/scripts/ptweens.py +++ b/src/pyramid/scripts/ptweens.py @@ -83,7 +83,7 @@ def run(self): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name self.setup_logging(config_uri, global_conf=config_vars) env = self.bootstrap(config_uri, options=config_vars) diff --git a/src/pyramid/scripts/pviews.py b/src/pyramid/scripts/pviews.py index da9881434b..94c8438212 100644 --- a/src/pyramid/scripts/pviews.py +++ b/src/pyramid/scripts/pviews.py @@ -250,7 +250,7 @@ def run(self): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) # bw update 2.1 don't overwrite if set - if not '__script__' in config_vars: + if '__script__' not in config_vars: config_vars['__script__'] = self.script_name url = self.args.url diff --git a/tests/test_scripts/test_prequest.py b/tests/test_scripts/test_prequest.py index 97786ec83c..d13010d5b9 100644 --- a/tests/test_scripts/test_prequest.py +++ b/tests/test_scripts/test_prequest.py @@ -241,7 +241,10 @@ def test_command_method_configures_logging(self): def test_command_script_name(self): command = self._makeOne(['', '--method=GET', 'development.ini', '/'],) command.run() - self.assertEqual(self.loader.calls[0]['defaults']['__script__'], 'prequest') + self.assertEqual( + self.loader.calls[0]['defaults']['__script__'], + 'prequest' + ) class Test_main(unittest.TestCase): diff --git a/tests/test_scripts/test_pserve.py b/tests/test_scripts/test_pserve.py index 0b010692ab..bdc225c5e5 100644 --- a/tests/test_scripts/test_pserve.py +++ b/tests/test_scripts/test_pserve.py @@ -47,7 +47,10 @@ def get_app(name, global_conf): self.loader.server = lambda x: x inst.run() - self.assertEqual(app.global_conf, {'a': '1', 'b': '2', '__script__': 'pserve'}) + self.assertEqual( + app.global_conf, + {'a': '1', 'b': '2', '__script__': 'pserve'} + ) def test_original_ignore_files(self): msg = 'A change to "ignore_files" was detected' From caa712662d79005854b8bb5870f5cbe2da7f3029 Mon Sep 17 00:00:00 2001 From: adroullier Date: Tue, 24 Oct 2023 14:34:21 +0200 Subject: [PATCH 4/7] Fix 'tox -e lint' tests --- tests/test_scripts/test_prequest.py | 5 ++--- tests/test_scripts/test_pserve.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_scripts/test_prequest.py b/tests/test_scripts/test_prequest.py index d13010d5b9..4ff6cb34c5 100644 --- a/tests/test_scripts/test_prequest.py +++ b/tests/test_scripts/test_prequest.py @@ -239,11 +239,10 @@ def test_command_method_configures_logging(self): self.assertEqual(self.loader.calls[0]['op'], 'logging') def test_command_script_name(self): - command = self._makeOne(['', '--method=GET', 'development.ini', '/'],) + command = self._makeOne(['', '--method=GET', 'development.ini', '/']) command.run() self.assertEqual( - self.loader.calls[0]['defaults']['__script__'], - 'prequest' + self.loader.calls[0]['defaults']['__script__'], 'prequest' ) diff --git a/tests/test_scripts/test_pserve.py b/tests/test_scripts/test_pserve.py index bdc225c5e5..a56f255979 100644 --- a/tests/test_scripts/test_pserve.py +++ b/tests/test_scripts/test_pserve.py @@ -48,8 +48,7 @@ def get_app(name, global_conf): inst.run() self.assertEqual( - app.global_conf, - {'a': '1', 'b': '2', '__script__': 'pserve'} + app.global_conf, {'a': '1', 'b': '2', '__script__': 'pserve'} ) def test_original_ignore_files(self): From 93140efbfca56a183fe70256fe34c83b607b58d7 Mon Sep 17 00:00:00 2001 From: adroullier Date: Mon, 30 Oct 2023 16:11:11 +0100 Subject: [PATCH 5/7] set script name via dict.setdefault() --- src/pyramid/scripts/prequest.py | 4 +--- src/pyramid/scripts/proutes.py | 4 +--- src/pyramid/scripts/pserve.py | 4 +--- src/pyramid/scripts/pshell.py | 4 +--- src/pyramid/scripts/ptweens.py | 4 +--- src/pyramid/scripts/pviews.py | 4 +--- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/pyramid/scripts/prequest.py b/src/pyramid/scripts/prequest.py index 3db2688966..c537ae6775 100644 --- a/src/pyramid/scripts/prequest.py +++ b/src/pyramid/scripts/prequest.py @@ -137,9 +137,7 @@ def run(self): return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) - # bw update 2.1 don't overwrite if set - if '__script__' not in config_vars: - config_vars['__script__'] = self.script_name + config_vars.setdefault('__script__', self.script_name) path = self.args.path_info loader = self._get_config_loader(config_uri) diff --git a/src/pyramid/scripts/proutes.py b/src/pyramid/scripts/proutes.py index fdafc68803..9d419bd8b6 100644 --- a/src/pyramid/scripts/proutes.py +++ b/src/pyramid/scripts/proutes.py @@ -317,9 +317,7 @@ def run(self, quiet=False): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) - # bw update 2.1 don't overwrite if set - if '__script__' not in config_vars: - config_vars['__script__'] = self.script_name + config_vars.setdefault('__script__', self.script_name) loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) self.proutes_file_config(loader, config_vars) diff --git a/src/pyramid/scripts/pserve.py b/src/pyramid/scripts/pserve.py index 55878c3fa4..b4a4af9775 100644 --- a/src/pyramid/scripts/pserve.py +++ b/src/pyramid/scripts/pserve.py @@ -184,9 +184,7 @@ def run(self): # pragma: no cover return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) - # bw update 2.1 don't overwrite if set - if '__script__' not in config_vars: - config_vars['__script__'] = self.script_name + config_vars.setdefault('__script__', self.script_name) app_spec = self.args.config_uri app_name = self.args.app_name diff --git a/src/pyramid/scripts/pshell.py b/src/pyramid/scripts/pshell.py index ba51745f35..9122ab32ea 100644 --- a/src/pyramid/scripts/pshell.py +++ b/src/pyramid/scripts/pshell.py @@ -131,9 +131,7 @@ def run(self, shell=None): config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) - # bw update 2.1 don't overwrite if set - if '__script__' not in config_vars: - config_vars['__script__'] = self.script_name + config_vars.setdefault('__script__', self.script_name) loader = self.get_config_loader(config_uri) loader.setup_logging(config_vars) self.pshell_file_config(loader, config_vars) diff --git a/src/pyramid/scripts/ptweens.py b/src/pyramid/scripts/ptweens.py index 1722d92617..cb19eec123 100644 --- a/src/pyramid/scripts/ptweens.py +++ b/src/pyramid/scripts/ptweens.py @@ -82,9 +82,7 @@ def run(self): return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) - # bw update 2.1 don't overwrite if set - if '__script__' not in config_vars: - config_vars['__script__'] = self.script_name + config_vars.setdefault('__script__', self.script_name) self.setup_logging(config_uri, global_conf=config_vars) env = self.bootstrap(config_uri, options=config_vars) registry = env['registry'] diff --git a/src/pyramid/scripts/pviews.py b/src/pyramid/scripts/pviews.py index 94c8438212..be19e48bca 100644 --- a/src/pyramid/scripts/pviews.py +++ b/src/pyramid/scripts/pviews.py @@ -249,9 +249,7 @@ def run(self): return 2 config_uri = self.args.config_uri config_vars = parse_vars(self.args.config_vars) - # bw update 2.1 don't overwrite if set - if '__script__' not in config_vars: - config_vars['__script__'] = self.script_name + config_vars.setdefault('__script__', self.script_name) url = self.args.url self.setup_logging(config_uri, global_conf=config_vars) From 13b86c1cbacde80f806df01adf5a59d7f97cee6c Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sat, 27 Jan 2024 17:46:01 -0700 Subject: [PATCH 6/7] add bootstrap value when an app is loaded via bootstrap --- src/pyramid/paster.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pyramid/paster.py b/src/pyramid/paster.py index f14acacf73..30e4f3e27a 100644 --- a/src/pyramid/paster.py +++ b/src/pyramid/paster.py @@ -114,6 +114,8 @@ def bootstrap(config_uri, request=None, options=None): by the ``closer``. """ + options = dict(options or {}) + options.setdefault('__script__', 'bootstrap') app = get_app(config_uri, options=options) env = prepare(request) env['app'] = app From fd42b0c8d08f69f88e3728b1c1ff3f50071f4b30 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sat, 27 Jan 2024 18:17:21 -0700 Subject: [PATCH 7/7] add changelog --- CHANGES.rst | 11 +++++++++++ tests/test_paster.py | 1 + 2 files changed, 12 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 46f7fbc18d..a717c5b59e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,17 @@ Features - Coverage reports in tests based on Python 3.11 instead of Python 3.8. +- All scripts now pass a new option ``__script__`` when loading the WSGI app. + For example, ``pserve`` sets ``__script__ == 'pserve'``. This works for + ``pserve``, ``pshell``, ``prequest``, ``proutes``, ``ptweens``, ``pviews``, + as well as when using ``pyramid.paster.bootstrap`` directly. + + When using ``plaster-pastedeploy`` to load an INI file, this option will + manifest as a new value passed into the ``global_conf`` arg of your + application factory, where you can use it as part of initializing your app. + + See https://github.com/Pylons/pyramid/pull/3735 + Bug Fixes --------- diff --git a/tests/test_paster.py b/tests/test_paster.py index 09e3bb868b..e787e6973c 100644 --- a/tests/test_paster.py +++ b/tests/test_paster.py @@ -159,6 +159,7 @@ def test_it_request_with_registry(self): result = self._callFUT('/foo/bar/myapp.ini', request) self.assertEqual(result['app'], self.app) self.assertEqual(result['root'], self.root) + self.assertEqual(self.get_app.kw['options']['__script__'], 'bootstrap') self.assertTrue('closer' in result)