From b7f994c9d13e70b597f42bce49ca6389cd21e2b2 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 12:13:30 -0800 Subject: convert pcreate and pdistreport to use argparse - add sphinxcontrib-autoprogram - attempt to render output of pcreate, but be unsuccessful --- docs/conf.py | 7 +++--- docs/pscripts/pcreate.rst | 5 ++-- pyramid/scaffolds/template.py | 8 +++--- pyramid/scripts/pcreate.py | 56 +++++++++++++++++++++--------------------- pyramid/scripts/pdistreport.py | 4 +-- setup.py | 2 +- 6 files changed, 40 insertions(+), 42 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 12dd27722..5496452bd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,11 +51,10 @@ book = os.environ.get('BOOK') extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.viewcode', 'repoze.sphinx.autointerface', - 'sphinxcontrib.programoutput', + 'sphinx.ext.viewcode', + 'sphinx.ext.intersphinx', + 'sphinxcontrib.autoprogram', # enable pylons_sphinx_latesturl when this branch is no longer "latest" # 'pylons_sphinx_latesturl', ] diff --git a/docs/pscripts/pcreate.rst b/docs/pscripts/pcreate.rst index b5ec3f4e2..7159395b7 100644 --- a/docs/pscripts/pcreate.rst +++ b/docs/pscripts/pcreate.rst @@ -6,8 +6,7 @@ ``pcreate`` ----------- -.. program-output:: pcreate --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.pcreate:PCreateCommand + :prog: pcreate.py .. seealso:: :ref:`creating_a_project` diff --git a/pyramid/scaffolds/template.py b/pyramid/scaffolds/template.py index d88f5b2a6..e5098e815 100644 --- a/pyramid/scaffolds/template.py +++ b/pyramid/scaffolds/template.py @@ -81,7 +81,7 @@ class Template(object): template_dir = self.template_dir() if not self.exists(output_dir): self.out("Creating directory %s" % output_dir) - if not command.options.simulate: + if not command.args.simulate: # Don't let copydir create this top-level directory, # since copydir will svn add it sometimes: self.makedirs(output_dir) @@ -90,9 +90,9 @@ class Template(object): output_dir, vars, verbosity=command.verbosity, - simulate=command.options.simulate, - interactive=command.options.interactive, - overwrite=command.options.overwrite, + simulate=command.args.simulate, + interactive=command.args.interactive, + overwrite=command.args.overwrite, indent=1, template_renderer=self.render_template, ) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index b3e3b65fa..ba4fcc8ae 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -2,7 +2,7 @@ # (http://pythonpaste.org) Licensed under the MIT license: # http://www.opensource.org/licenses/mit-license.php -import optparse +import argparse import os import os.path import pkg_resources @@ -22,79 +22,79 @@ def main(argv=sys.argv, quiet=False): class PCreateCommand(object): verbosity = 1 # required - description = """\ + parser = argparse.ArgumentParser(description="""\ Render Pyramid scaffolding to an output directory. Note: As of Pyramid 1.8, this command is deprecated. Use a specific cookiecutter instead: https://github.com/Pylons/?q=cookiecutter -""" - usage = "usage: %prog [options] -s output_directory" - parser = optparse.OptionParser(usage, description=description) - parser.add_option('-s', '--scaffold', +""") + parser.add_argument('-s', '--scaffold', dest='scaffold_name', action='append', help=("Add a scaffold to the create process " "(multiple -s args accepted)")) - parser.add_option('-t', '--template', + parser.add_argument('-t', '--template', dest='scaffold_name', action='append', help=('A backwards compatibility alias for ' '-s/--scaffold. Add a scaffold to the ' 'create process (multiple -t args accepted)')) - parser.add_option('-l', '--list', + parser.add_argument('-l', '--list', dest='list', action='store_true', help="List all available scaffold names") - parser.add_option('--list-templates', + parser.add_argument('--list-templates', dest='list', action='store_true', help=("A backwards compatibility alias for -l/--list. " "List all available scaffold names.")) - parser.add_option('--package-name', + parser.add_argument('--package-name', dest='package_name', action='store', - type='string', help='Package name to use. The name provided is assumed ' 'to be a valid Python package name, and will not ' 'be validated. By default the package name is ' 'derived from the value of output_directory.') - parser.add_option('--simulate', + parser.add_argument('--simulate', dest='simulate', action='store_true', help='Simulate but do no work') - parser.add_option('--overwrite', + parser.add_argument('--overwrite', dest='overwrite', action='store_true', help='Always overwrite') - parser.add_option('--interactive', + parser.add_argument('--interactive', dest='interactive', action='store_true', help='When a file would be overwritten, interrogate ' '(this is the default, but you may specify it to ' 'override --overwrite)') - parser.add_option('--ignore-conflicting-name', + parser.add_argument('--ignore-conflicting-name', dest='force_bad_name', action='store_true', default=False, help='Do create a project even if the chosen name ' 'is the name of an already existing / importable ' 'package.') + parser.add_argument('output_directory', + help='The directory where the project will be ' + 'created.') pyramid_dist = pkg_resources.get_distribution("pyramid") def __init__(self, argv, quiet=False): self.quiet = quiet - self.options, self.args = self.parser.parse_args(argv[1:]) - if not self.options.interactive and not self.options.overwrite: - self.options.interactive = True + self.args = self.parser.parse_args() + if not self.args.interactive and not self.args.overwrite: + self.args.interactive = True self.scaffolds = self.all_scaffolds() def run(self): self._warn_pcreate_deprecated() - if self.options.list: + if self.args.list: return self.show_scaffolds() - if not self.options.scaffold_name and not self.args: + if not self.args.scaffold_name and not self.args: if not self.quiet: # pragma: no cover self.parser.print_help() self.out('') @@ -108,18 +108,18 @@ https://github.com/Pylons/?q=cookiecutter @property def output_path(self): - return os.path.abspath(os.path.normpath(self.args[0])) + return os.path.abspath(os.path.normpath(self.args.output_directory)) @property def project_vars(self): output_dir = self.output_path project_name = os.path.basename(os.path.split(output_dir)[1]) - if self.options.package_name is None: + if self.args.package_name is None: pkg_name = _bad_chars_re.sub( '', project_name.lower().replace('-', '_')) safe_name = pkg_resources.safe_name(project_name) else: - pkg_name = self.options.package_name + pkg_name = self.args.package_name safe_name = pkg_name egg_name = pkg_resources.to_filename(safe_name) @@ -152,7 +152,7 @@ https://github.com/Pylons/?q=cookiecutter def render_scaffolds(self): props = self.project_vars output_dir = self.output_path - for scaffold_name in self.options.scaffold_name: + for scaffold_name in self.args.scaffold_name: for scaffold in self.scaffolds: if scaffold.name == scaffold_name: scaffold.run(self, output_dir, props) @@ -189,7 +189,7 @@ https://github.com/Pylons/?q=cookiecutter print(msg) def validate_input(self): - if not self.options.scaffold_name: + if not self.args.scaffold_name: self.out('You must provide at least one scaffold name: -s ') self.out('') self.show_scaffolds() @@ -198,14 +198,14 @@ https://github.com/Pylons/?q=cookiecutter self.out('You must provide a project name') return False available = [x.name for x in self.scaffolds] - diff = set(self.options.scaffold_name).difference(available) + diff = set(self.args.scaffold_name).difference(available) if diff: self.out('Unavailable scaffolds: %s' % ", ".join(sorted(diff))) return False pkg_name = self.project_vars['package'] - if pkg_name == 'site' and not self.options.force_bad_name: + if pkg_name == 'site' and not self.args.force_bad_name: self.out('The package name "site" has a special meaning in ' 'Python. Are you sure you want to use it as your ' 'project\'s name?') @@ -221,7 +221,7 @@ https://github.com/Pylons/?q=cookiecutter if not pkg_exists: return True - if self.options.force_bad_name: + if self.args.force_bad_name: return True self.out('A package named "{0}" already exists, are you sure you want ' 'to use it as your project\'s name?'.format(pkg_name)) diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index 61098dc27..a504c9545 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -1,7 +1,7 @@ import sys import platform import pkg_resources -import optparse +import argparse from operator import itemgetter def out(*args): # pragma: no cover @@ -15,7 +15,7 @@ def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform, # all args except argv are for unit testing purposes only description = "Show Python distribution versions and locations in use" usage = "usage: %prog" - parser = optparse.OptionParser(usage, description=description) + parser = argparse.ArgumentParser(usage, description=description) parser.parse_args(argv[1:]) packages = [] for distribution in pkg_resources.working_set: diff --git a/setup.py b/setup.py index 383991d73..63e82e707 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,7 @@ docs_extras = [ 'repoze.sphinx.autointerface', 'pylons_sphinx_latesturl', 'pylons-sphinx-themes', - 'sphinxcontrib-programoutput', + 'sphinxcontrib-autoprogram', ] testing_extras = tests_require + [ -- cgit v1.2.3 From bde0ef17af0461799f04ace144526a06c6215776 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 12:49:28 -0800 Subject: fix autoprogram argument - restore argv - use standard Python syntax for string formatting --- docs/pscripts/pcreate.rst | 2 +- pyramid/scripts/pcreate.py | 2 +- pyramid/scripts/pdistreport.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/pscripts/pcreate.rst b/docs/pscripts/pcreate.rst index 7159395b7..648491600 100644 --- a/docs/pscripts/pcreate.rst +++ b/docs/pscripts/pcreate.rst @@ -6,7 +6,7 @@ ``pcreate`` ----------- -.. autoprogram:: pyramid.scripts.pcreate:PCreateCommand +.. autoprogram:: pyramid.scripts.pcreate:PCreateCommand.parser :prog: pcreate.py .. seealso:: :ref:`creating_a_project` diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index ba4fcc8ae..027a52c06 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -85,7 +85,7 @@ https://github.com/Pylons/?q=cookiecutter def __init__(self, argv, quiet=False): self.quiet = quiet - self.args = self.parser.parse_args() + self.args = self.parser.parse_args(argv) if not self.args.interactive and not self.args.overwrite: self.args.interactive = True self.scaffolds = self.all_scaffolds() diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index a504c9545..c090d3311 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -14,7 +14,7 @@ def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform, out=out): # all args except argv are for unit testing purposes only description = "Show Python distribution versions and locations in use" - usage = "usage: %prog" + usage = "usage: %(prog)s" parser = argparse.ArgumentParser(usage, description=description) parser.parse_args(argv[1:]) packages = [] -- cgit v1.2.3 From 3fb84e950bd6f65dd298b08c86723b388c3b62f8 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 13:09:39 -0800 Subject: make usage parseable by argparse - PEP8 --- pyramid/scripts/pcreate.py | 80 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 027a52c06..49e5fbdf4 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -12,6 +12,7 @@ from pyramid.compat import input_ _bad_chars_re = re.compile('[^a-zA-Z0-9_]') + def main(argv=sys.argv, quiet=False): command = PCreateCommand(argv, quiet) try: @@ -30,53 +31,54 @@ cookiecutter instead: https://github.com/Pylons/?q=cookiecutter """) parser.add_argument('-s', '--scaffold', - dest='scaffold_name', - action='append', - help=("Add a scaffold to the create process " - "(multiple -s args accepted)")) + dest='scaffold_name', + action='append', + help=("Add a scaffold to the create process " + "(multiple -s args accepted)")) parser.add_argument('-t', '--template', - dest='scaffold_name', - action='append', - help=('A backwards compatibility alias for ' - '-s/--scaffold. Add a scaffold to the ' - 'create process (multiple -t args accepted)')) + dest='scaffold_name', + action='append', + help=('A backwards compatibility alias for ' + '-s/--scaffold. Add a scaffold to the ' + 'create process (multiple -t args accepted)')) parser.add_argument('-l', '--list', - dest='list', - action='store_true', - help="List all available scaffold names") + dest='list', + action='store_true', + help="List all available scaffold names") parser.add_argument('--list-templates', - dest='list', - action='store_true', - help=("A backwards compatibility alias for -l/--list. " - "List all available scaffold names.")) + dest='list', + action='store_true', + help=("A backwards compatibility alias for -l/--list. " + "List all available scaffold names.")) parser.add_argument('--package-name', - dest='package_name', - action='store', - help='Package name to use. The name provided is assumed ' - 'to be a valid Python package name, and will not ' - 'be validated. By default the package name is ' - 'derived from the value of output_directory.') + dest='package_name', + action='store', + help='Package name to use. The name provided is ' + 'assumed to be a valid Python package name, and ' + 'will not be validated. By default the package ' + 'name is derived from the value of ' + 'output_directory.') parser.add_argument('--simulate', - dest='simulate', - action='store_true', - help='Simulate but do no work') + dest='simulate', + action='store_true', + help='Simulate but do no work') parser.add_argument('--overwrite', - dest='overwrite', - action='store_true', - help='Always overwrite') + dest='overwrite', + action='store_true', + help='Always overwrite') parser.add_argument('--interactive', - dest='interactive', - action='store_true', - help='When a file would be overwritten, interrogate ' - '(this is the default, but you may specify it to ' - 'override --overwrite)') + dest='interactive', + action='store_true', + help='When a file would be overwritten, interrogate ' + '(this is the default, but you may specify it to ' + 'override --overwrite)') parser.add_argument('--ignore-conflicting-name', - dest='force_bad_name', - action='store_true', - default=False, - help='Do create a project even if the chosen name ' - 'is the name of an already existing / importable ' - 'package.') + dest='force_bad_name', + action='store_true', + default=False, + help='Do create a project even if the chosen name ' + 'is the name of an already existing / importable ' + 'package.') parser.add_argument('output_directory', help='The directory where the project will be ' 'created.') -- cgit v1.2.3 From f33a50c69bbb7790f612eebeb005e1137b5c252a Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 19:48:00 -0800 Subject: make usage parseable by argparse --- pyramid/scripts/pdistreport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index c090d3311..64837a36c 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -13,9 +13,9 @@ def out(*args): # pragma: no cover def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform, out=out): # all args except argv are for unit testing purposes only - description = "Show Python distribution versions and locations in use" - usage = "usage: %(prog)s" - parser = argparse.ArgumentParser(usage, description=description) + parser = argparse.ArgumentParser( + usage="%(prog)s", + description="Show Python distribution versions and locations in use") parser.parse_args(argv[1:]) packages = [] for distribution in pkg_resources.working_set: -- cgit v1.2.3 From b2f3ed007ef27d24690f40c2ad8415fab9400e98 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 20:01:36 -0800 Subject: still fumbling around with autoprogram, not successful --- docs/pscripts/pdistreport.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/pscripts/pdistreport.rst b/docs/pscripts/pdistreport.rst index 1c53fb6e9..3bcd96b00 100644 --- a/docs/pscripts/pdistreport.rst +++ b/docs/pscripts/pdistreport.rst @@ -6,8 +6,7 @@ ``pdistreport`` --------------- -.. program-output:: pdistreport --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.pdistreport:parser + :prog: pdistreport.py .. seealso:: :ref:`showing_distributions` -- cgit v1.2.3 From cae3840bc43f54ae55d1e2c97da90cecdf49a95e Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 20:03:45 -0800 Subject: drop '.py' from :prog: argument --- docs/pscripts/pcreate.rst | 2 +- docs/pscripts/pdistreport.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pscripts/pcreate.rst b/docs/pscripts/pcreate.rst index 648491600..476b3d577 100644 --- a/docs/pscripts/pcreate.rst +++ b/docs/pscripts/pcreate.rst @@ -7,6 +7,6 @@ ----------- .. autoprogram:: pyramid.scripts.pcreate:PCreateCommand.parser - :prog: pcreate.py + :prog: pcreate .. seealso:: :ref:`creating_a_project` diff --git a/docs/pscripts/pdistreport.rst b/docs/pscripts/pdistreport.rst index 3bcd96b00..8eebaf8cb 100644 --- a/docs/pscripts/pdistreport.rst +++ b/docs/pscripts/pdistreport.rst @@ -7,6 +7,6 @@ --------------- .. autoprogram:: pyramid.scripts.pdistreport:parser - :prog: pdistreport.py + :prog: pdistreport .. seealso:: :ref:`showing_distributions` -- cgit v1.2.3 From 0c208dd7bf66a41a056514025fa42be8fc428513 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 22:13:03 -0800 Subject: move parser outside of main into own function get_parser(), and call it from pdistreport.rst --- docs/pscripts/pdistreport.rst | 2 +- pyramid/scripts/pdistreport.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/pscripts/pdistreport.rst b/docs/pscripts/pdistreport.rst index 8eebaf8cb..f88ea7fe1 100644 --- a/docs/pscripts/pdistreport.rst +++ b/docs/pscripts/pdistreport.rst @@ -6,7 +6,7 @@ ``pdistreport`` --------------- -.. autoprogram:: pyramid.scripts.pdistreport:parser +.. autoprogram:: pyramid.scripts.pdistreport:get_parser() :prog: pdistreport .. seealso:: :ref:`showing_distributions` diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index 64837a36c..6622b4bd8 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -10,12 +10,16 @@ def out(*args): # pragma: no cover sys.stdout.write(' ') sys.stdout.write('\n') +def get_parser(): + _parser = argparse.ArgumentParser( + usage="%(prog)s", + description="Show Python distribution versions and locations in use") + return _parser + def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform, out=out): # all args except argv are for unit testing purposes only - parser = argparse.ArgumentParser( - usage="%(prog)s", - description="Show Python distribution versions and locations in use") + parser = get_parser() parser.parse_args(argv[1:]) packages = [] for distribution in pkg_resources.working_set: -- cgit v1.2.3 From e5b871d5afa0cb2772780013636ee2b830c1fdf1 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 22:19:08 -0800 Subject: remove duplicitous headings --- docs/pscripts/pcreate.rst | 3 --- docs/pscripts/pdistreport.rst | 3 --- 2 files changed, 6 deletions(-) diff --git a/docs/pscripts/pcreate.rst b/docs/pscripts/pcreate.rst index 476b3d577..0f23583ba 100644 --- a/docs/pscripts/pcreate.rst +++ b/docs/pscripts/pcreate.rst @@ -3,9 +3,6 @@ .. _pcreate_script: -``pcreate`` ------------ - .. autoprogram:: pyramid.scripts.pcreate:PCreateCommand.parser :prog: pcreate diff --git a/docs/pscripts/pdistreport.rst b/docs/pscripts/pdistreport.rst index f88ea7fe1..200218ad0 100644 --- a/docs/pscripts/pdistreport.rst +++ b/docs/pscripts/pdistreport.rst @@ -3,9 +3,6 @@ .. _pdistreport_script: -``pdistreport`` ---------------- - .. autoprogram:: pyramid.scripts.pdistreport:get_parser() :prog: pdistreport -- cgit v1.2.3 From 1efb3110d91a14a758366da6c5a489fc8b1c0def Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 22:57:06 -0800 Subject: rename local --- pyramid/scripts/pdistreport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index 6622b4bd8..e80ea20b6 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -11,10 +11,10 @@ def out(*args): # pragma: no cover sys.stdout.write('\n') def get_parser(): - _parser = argparse.ArgumentParser( + parser = argparse.ArgumentParser( usage="%(prog)s", description="Show Python distribution versions and locations in use") - return _parser + return parser def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform, out=out): -- cgit v1.2.3 From 6b229c9ef28556942845ac429e10e498fb5dea5f Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 23:56:21 -0800 Subject: indent 4 spaces --- docs/pscripts/pcreate.rst | 4 ++-- docs/pscripts/pdistreport.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/pscripts/pcreate.rst b/docs/pscripts/pcreate.rst index 0f23583ba..c48a70acd 100644 --- a/docs/pscripts/pcreate.rst +++ b/docs/pscripts/pcreate.rst @@ -1,9 +1,9 @@ .. index:: - single: pcreate; --help + single: pcreate; --help .. _pcreate_script: .. autoprogram:: pyramid.scripts.pcreate:PCreateCommand.parser - :prog: pcreate + :prog: pcreate .. seealso:: :ref:`creating_a_project` diff --git a/docs/pscripts/pdistreport.rst b/docs/pscripts/pdistreport.rst index 200218ad0..b3c9dffd8 100644 --- a/docs/pscripts/pdistreport.rst +++ b/docs/pscripts/pdistreport.rst @@ -1,9 +1,9 @@ .. index:: - single: pdistreport; --help + single: pdistreport; --help .. _pdistreport_script: .. autoprogram:: pyramid.scripts.pdistreport:get_parser() - :prog: pdistreport + :prog: pdistreport .. seealso:: :ref:`showing_distributions` -- cgit v1.2.3 From 9a22d66e011f93135fa12c1ab1738b7f1ee90312 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 27 Nov 2016 23:57:22 -0800 Subject: use argparse in prequest; use autoprogram --- docs/pscripts/prequest.rst | 10 +++------- pyramid/scripts/prequest.py | 47 +++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/docs/pscripts/prequest.rst b/docs/pscripts/prequest.rst index a15827767..64ed01739 100644 --- a/docs/pscripts/prequest.rst +++ b/docs/pscripts/prequest.rst @@ -1,13 +1,9 @@ .. index:: - single: prequest; --help + single: prequest; --help .. _prequest_script: -``prequest`` ------------- - -.. program-output:: prequest --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.prequest:PRequestCommand.parser + :prog: prequest .. seealso:: :ref:`invoking_a_request` diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 14a132bdb..880eae5b0 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -1,5 +1,5 @@ import base64 -import optparse +import argparse import sys import textwrap @@ -45,58 +45,63 @@ class PRequestCommand(object): the request's WSGI environment, so your application can distinguish these calls from normal requests. """ - usage = "usage: %prog config_uri path_info [args/options]" - parser = optparse.OptionParser( - usage=usage, + parser = argparse.ArgumentParser( + usage="%(prog)s config_uri path_info [args/options]", description=textwrap.dedent(description) ) - parser.add_option( + parser.add_argument( '-n', '--app-name', dest='app_name', metavar='NAME', help=( "Load the named application from the config file (default 'main')" ), - type="string", ) - parser.add_option( + parser.add_argument( '--header', dest='headers', metavar='NAME:VALUE', - type='string', action='append', help=( "Header to add to request (you can use this option multiple times)" ), ) - parser.add_option( + parser.add_argument( '-d', '--display-headers', dest='display_headers', action='store_true', help='Display status and headers before the response body' ) - parser.add_option( + parser.add_argument( '-m', '--method', dest='method', choices=['GET', 'HEAD', 'POST', 'PUT', 'PATCH','DELETE', 'PROPFIND', 'OPTIONS'], - type='choice', help='Request method type (GET, POST, PUT, PATCH, DELETE, ' 'PROPFIND, OPTIONS)', ) - parser.add_option( + parser.add_argument( '-l', '--login', dest='login', - type='string', help='HTTP basic auth username:password pair', ) + parser.add_argument( + 'config_uri', + help='The URI to the configuration file.', + ) + + parser.add_argument( + 'path_info', + help='The path of the request.', + ) + get_app = staticmethod(get_app) stdin = sys.stdin def __init__(self, argv, quiet=False): self.quiet = quiet - self.options, self.args = self.parser.parse_args(argv[1:]) + self.args = self.parser.parse_args(argv[1:]) def out(self, msg): # pragma: no cover if not self.quiet: @@ -125,12 +130,12 @@ class PRequestCommand(object): path = url_unquote(path) headers = {} - if self.options.login: - enc = base64.b64encode(self.options.login.encode('ascii')) + if self.args.login: + enc = base64.b64encode(self.args.login.encode('ascii')) headers['Authorization'] = 'Basic ' + enc.decode('ascii') - if self.options.headers: - for item in self.options.headers: + if self.args.headers: + for item in self.args.headers: if ':' not in item: self.out( "Bad --header=%s option, value must be in the form " @@ -139,10 +144,10 @@ class PRequestCommand(object): name, value = item.split(':', 1) headers[name] = value.strip() - app = self.get_app(app_spec, self.options.app_name, + app = self.get_app(app_spec, self.args.app_name, options=parse_vars(self.args[2:])) - request_method = (self.options.method or 'GET').upper() + request_method = (self.args.method or 'GET').upper() environ = { 'REQUEST_METHOD': request_method, @@ -177,7 +182,7 @@ class PRequestCommand(object): request = Request.blank(path, environ=environ) response = request.get_response(app) - if self.options.display_headers: + if self.args.display_headers: self.out(response.status) for name, value in response.headerlist: self.out('%s: %s' % (name, value)) -- cgit v1.2.3 From 83ebd45272bee27a56aaf9a6494382da1499c12d Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 01:48:38 -0800 Subject: use argparse in prequest; use autoprogram --- docs/pscripts/proutes.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/pscripts/proutes.rst b/docs/pscripts/proutes.rst index 09ed013e1..ee7c209e3 100644 --- a/docs/pscripts/proutes.rst +++ b/docs/pscripts/proutes.rst @@ -3,11 +3,7 @@ .. _proutes_script: -``proutes`` ------------ - -.. program-output:: proutes --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.proutes:PRoutesCommand.parser + :prog: proutes .. seealso:: :ref:`displaying_application_routes` -- cgit v1.2.3 From 616f40a660d1f095241a7c46ff3d68e69b07c900 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 01:55:43 -0800 Subject: use argparse in proutes; use autoprogram --- pyramid/scripts/proutes.py | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index f75810c06..640cd20a3 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -1,5 +1,5 @@ import fnmatch -import optparse +import argparse import sys import textwrap import re @@ -249,22 +249,31 @@ class PRoutesCommand(object): stdout = sys.stdout usage = '%prog config_uri' ConfigParser = configparser.ConfigParser # testing - parser = optparse.OptionParser( + parser = argparse.ArgumentParser( usage, description=textwrap.dedent(description) ) - parser.add_option('-g', '--glob', - action='store', type='string', dest='glob', - default='', help='Display routes matching glob pattern') - - parser.add_option('-f', '--format', - action='store', type='string', dest='format', - default='', help=('Choose which columns to display, this ' - 'will override the format key in the ' - '[proutes] ini section')) + parser.add_argument('-g', '--glob', + action='store', + dest='glob', + default='', + help='Display routes matching glob pattern') + + parser.add_argument('-f', '--format', + action='store', + dest='format', + default='', + help=('Choose which columns to display, this will ' + 'override the format key in the [proutes] ini ' + 'section')) + + parser.add_argument( + 'config_uri', + help='The URI to the configuration file.', + ) def __init__(self, argv, quiet=False): - self.options, self.args = self.parser.parse_args(argv[1:]) + self.args = self.parser.parse_args(argv[1:]) self.quiet = quiet self.available_formats = [ 'name', 'pattern', 'view', 'method' @@ -323,8 +332,8 @@ class PRoutesCommand(object): self.proutes_file_config(config_uri) - if self.options.format: - columns = self.options.format.split(',') + if self.args.format: + columns = self.args.format.split(',') self.column_format = [x.strip() for x in columns] is_valid = self.validate_formats(self.column_format) @@ -361,9 +370,9 @@ class PRoutesCommand(object): route_data = get_route_data(route, registry) for name, pattern, view, method in route_data: - if self.options.glob: - match = (fnmatch.fnmatch(name, self.options.glob) or - fnmatch.fnmatch(pattern, self.options.glob)) + if self.args.glob: + match = (fnmatch.fnmatch(name, self.args.glob) or + fnmatch.fnmatch(pattern, self.args.glob)) if not match: continue -- cgit v1.2.3 From 506d3c7fd5cd6cf3bd0c46f06f85c9cdf6795d18 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 01:56:15 -0800 Subject: add line feed to avoid Sphinx error --- pyramid/scripts/prequest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 880eae5b0..021b83f6c 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -45,6 +45,7 @@ class PRequestCommand(object): the request's WSGI environment, so your application can distinguish these calls from normal requests. """ + parser = argparse.ArgumentParser( usage="%(prog)s config_uri path_info [args/options]", description=textwrap.dedent(description) -- cgit v1.2.3 From 894534b26edcd1701dcf2c5f93377bf0d86dc51a Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 01:58:46 -0800 Subject: fix quote mismatch --- pyramid/scripts/prequest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 021b83f6c..9e807896d 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -39,7 +39,7 @@ class PRequestCommand(object): If the path is relative (doesn't begin with "/") it is interpreted as relative to "/". The path passed to this script should be URL-quoted. - The path can be succeeded with a query string (e.g. `/path?a=1&=b2'). + The path can be succeeded with a query string (e.g. '/path?a=1&=b2'). The variable "environ['paste.command_request']" will be set to "True" in the request's WSGI environment, so your application can distinguish these -- cgit v1.2.3 From 6e14f62f24dcff03ebc6d27c0c756db449082cfd Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 02:05:21 -0800 Subject: use argparse and autoprogram for pserve --- docs/pscripts/pserve.rst | 8 ++----- pyramid/scripts/pserve.py | 55 +++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/docs/pscripts/pserve.rst b/docs/pscripts/pserve.rst index d33d4a484..991976aea 100644 --- a/docs/pscripts/pserve.rst +++ b/docs/pscripts/pserve.rst @@ -3,11 +3,7 @@ .. _pserve_script: -``pserve`` ----------- - -.. program-output:: pserve --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.pserve:PServeCommand.parser + :prog: pserve .. seealso:: :ref:`running_the_project_application` diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index b8776d44f..f3515804d 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -8,7 +8,7 @@ # Code taken also from QP: http://www.mems-exchange.org/software/qp/ From # lib/site.py -import optparse +import argparse import os import re import sys @@ -41,7 +41,6 @@ def main(argv=sys.argv, quiet=False): class PServeCommand(object): - usage = '%prog config_uri [var=value]' description = """\ This command serves a web application that uses a PasteDeploy configuration file for the server and application. @@ -51,54 +50,58 @@ class PServeCommand(object): """ default_verbosity = 1 - parser = optparse.OptionParser( - usage, + parser = argparse.ArgumentParser( + usage="%(prog)s config_uri [var=value]", description=textwrap.dedent(description) ) - parser.add_option( + parser.add_argument( '-n', '--app-name', dest='app_name', metavar='NAME', help="Load the named application (default main)") - parser.add_option( + parser.add_argument( '-s', '--server', dest='server', metavar='SERVER_TYPE', help="Use the named server.") - parser.add_option( + parser.add_argument( '--server-name', dest='server_name', metavar='SECTION_NAME', help=("Use the named server as defined in the configuration file " "(default: main)")) - parser.add_option( + parser.add_argument( '--reload', dest='reload', action='store_true', help="Use auto-restart file monitor") - parser.add_option( + parser.add_argument( '--reload-interval', dest='reload_interval', default=1, help=("Seconds between checking files (low number can cause " "significant CPU usage)")) - parser.add_option( + parser.add_argument( '-b', '--browser', dest='browser', action='store_true', help="Open a web browser to server url") - parser.add_option( + parser.add_argument( '-v', '--verbose', default=default_verbosity, dest='verbose', action='count', help="Set verbose level (default " + str(default_verbosity) + ")") - parser.add_option( + parser.add_argument( '-q', '--quiet', action='store_const', const=0, dest='verbose', help="Suppress verbose output") + parser.add_argument( + 'config_uri', + help='The URI to the configuration file.', + ) ConfigParser = configparser.ConfigParser # testing loadapp = staticmethod(loadapp) # testing @@ -107,13 +110,13 @@ class PServeCommand(object): _scheme_re = re.compile(r'^[a-z][a-z]+:', re.I) def __init__(self, argv, quiet=False): - self.options, self.args = self.parser.parse_args(argv[1:]) + self.args = self.parser.parse_args(argv[1:]) if quiet: - self.options.verbose = 0 + self.args.verbose = 0 self.watch_files = [] def out(self, msg): # pragma: no cover - if self.options.verbose > 0: + if self.args.verbose > 0: print(msg) def get_options(self): @@ -153,7 +156,7 @@ class PServeCommand(object): app_spec = self.args[0] vars = self.get_options() - app_name = self.options.app_name + app_name = self.args.app_name base = os.getcwd() if not self._scheme_re.search(app_spec): @@ -161,16 +164,16 @@ class PServeCommand(object): app_spec = 'config:' + app_spec else: config_path = None - server_name = self.options.server_name - if self.options.server: + server_name = self.args.server_name + if self.args.server: server_spec = 'egg:pyramid' assert server_name is None - server_name = self.options.server + server_name = self.args.server else: server_spec = app_spec # do not open the browser on each reload so check hupper first - if self.options.browser and not hupper.is_active(): + if self.args.browser and not hupper.is_active(): def open_browser(): context = loadcontext( SERVER, app_spec, name=server_name, relative_to=base, @@ -182,13 +185,13 @@ class PServeCommand(object): t.setDaemon(True) t.start() - if self.options.reload and not hupper.is_active(): - if self.options.verbose > 1: + if self.args.reload and not hupper.is_active(): + if self.args.verbose > 1: self.out('Running reloading file monitor') hupper.start_reloader( 'pyramid.scripts.pserve.main', - reload_interval=int(self.options.reload_interval), - verbose=self.options.verbose, + reload_interval=int(self.args.reload_interval), + verbose=self.args.verbose, ) return 0 @@ -207,7 +210,7 @@ class PServeCommand(object): app = self.loadapp( app_spec, name=app_name, relative_to=base, global_conf=vars) - if self.options.verbose > 0: + if self.args.verbose > 0: if hasattr(os, 'getpid'): msg = 'Starting server in PID %i.' % os.getpid() else: @@ -217,7 +220,7 @@ class PServeCommand(object): try: server(app) except (SystemExit, KeyboardInterrupt) as e: - if self.options.verbose > 1: + if self.args.verbose > 1: raise if str(e): msg = ' ' + str(e) -- cgit v1.2.3 From 5ad647c869c90a6a64fb557d6a28b0d09d7e7354 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 02:10:59 -0800 Subject: use argparse and autoprogram for pshell --- docs/pscripts/pshell.rst | 8 ++------ pyramid/scripts/pshell.py | 50 ++++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/docs/pscripts/pshell.rst b/docs/pscripts/pshell.rst index cfd84d4f8..4e2ce74cb 100644 --- a/docs/pscripts/pshell.rst +++ b/docs/pscripts/pshell.rst @@ -3,11 +3,7 @@ .. _pshell_script: -``pshell`` ----------- - -.. program-output:: pshell --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.pshell:PShellCommand.parser + :prog: pshell .. seealso:: :ref:`interactive_shell` diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 56b1a15fa..7e00eeaac 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -1,5 +1,5 @@ from code import interact -import optparse +import argparse import os import sys import textwrap @@ -28,7 +28,6 @@ def python_shell_runner(env, help, interact=interact): class PShellCommand(object): - usage = '%prog config_uri' description = """\ Open an interactive shell with a Pyramid app loaded. This command accepts one positional argument named "config_uri" which specifies the @@ -45,26 +44,29 @@ class PShellCommand(object): bootstrap = (bootstrap,) # for testing pkg_resources = pkg_resources # for testing - parser = optparse.OptionParser( - usage, + parser = argparse.ArgumentParser( + usage="%(prog)s config_uri", description=textwrap.dedent(description) ) - parser.add_option('-p', '--python-shell', - action='store', type='string', dest='python_shell', - default='', - help=('Select the shell to use. A list of possible ' - 'shells is available using the --list-shells ' - 'option.')) - parser.add_option('-l', '--list-shells', - dest='list', - action='store_true', - help='List all available shells.') - parser.add_option('--setup', - dest='setup', - help=("A callable that will be passed the environment " - "before it is made available to the shell. This " - "option will override the 'setup' key in the " - "[pshell] ini section.")) + parser.add_argument('-p', '--python-shell', + action='store', + dest='python_shell', + default='', + help=('Select the shell to use. A list of possible ' + 'shells is available using the --list-shells ' + 'option.')) + parser.add_argument('-l', '--list-shells', + dest='list', + action='store_true', + help='List all available shells.') + parser.add_argument('--setup', + dest='setup', + help=("A callable that will be passed the environment " + "before it is made available to the shell. This " + "option will override the 'setup' key in the " + "[pshell] ini section.")) + parser.add_argument('config_uri', + help='The URI to the configuration file.') ConfigParser = configparser.ConfigParser # testing default_runner = python_shell_runner # testing @@ -77,7 +79,7 @@ class PShellCommand(object): def __init__(self, argv, quiet=False): self.quiet = quiet - self.options, self.args = self.parser.parse_args(argv[1:]) + self.args = self.parser.parse_args(argv[1:]) def pshell_file_config(self, filename): config = self.ConfigParser() @@ -132,8 +134,8 @@ class PShellCommand(object): 'Default root factory used to create `root`.') # override use_script with command-line options - if self.options.setup: - self.setup = self.options.setup + if self.args.setup: + self.setup = self.args.setup if self.setup: # store the env before muddling it with the script @@ -214,7 +216,7 @@ class PShellCommand(object): shells = self.find_all_shells() shell = None - user_shell = self.options.python_shell.lower() + user_shell = self.args.python_shell.lower() if not user_shell: preferred_shells = self.preferred_shells -- cgit v1.2.3 From 7dd4214cccdc417d78a78391cf387ff62489beb0 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 02:15:11 -0800 Subject: use argparse and autoprogram for ptweens --- docs/pscripts/ptweens.rst | 8 ++------ pyramid/scripts/ptweens.py | 12 +++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/pscripts/ptweens.rst b/docs/pscripts/ptweens.rst index 02e23e49a..f586e1467 100644 --- a/docs/pscripts/ptweens.rst +++ b/docs/pscripts/ptweens.rst @@ -3,11 +3,7 @@ .. _ptweens_script: -``ptweens`` ------------ - -.. program-output:: ptweens --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.ptweens:PTweensCommand.parser + :prog: ptweens .. seealso:: :ref:`displaying_tweens` diff --git a/pyramid/scripts/ptweens.py b/pyramid/scripts/ptweens.py index a7aa009da..3f8c9871e 100644 --- a/pyramid/scripts/ptweens.py +++ b/pyramid/scripts/ptweens.py @@ -1,4 +1,4 @@ -import optparse +import argparse import sys import textwrap @@ -14,7 +14,6 @@ def main(argv=sys.argv, quiet=False): return command.run() class PTweensCommand(object): - usage = '%prog config_uri' description = """\ Print all implicit and explicit tween objects used by a Pyramid application. The handler output includes whether the system is using an @@ -28,17 +27,20 @@ class PTweensCommand(object): will be assumed. Example: "ptweens myapp.ini#main". """ - parser = optparse.OptionParser( - usage, + parser = argparse.ArgumentParser( + usage="%(prog)s config_uri", description=textwrap.dedent(description), ) + parser.add_argument('config_uri', + help='The URI to the configuration file.') + stdout = sys.stdout bootstrap = (bootstrap,) # testing def __init__(self, argv, quiet=False): self.quiet = quiet - self.options, self.args = self.parser.parse_args(argv[1:]) + self.args = self.parser.parse_args(argv[1:]) def _get_tweens(self, registry): from pyramid.config import Configurator -- cgit v1.2.3 From 812bc62a37205353de1d1719b82718dd0699bf1a Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 02:17:45 -0800 Subject: use argparse and autoprogram for ptviews --- docs/pscripts/pviews.rst | 8 ++------ pyramid/scripts/pviews.py | 12 +++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/pscripts/pviews.rst b/docs/pscripts/pviews.rst index b4de5c054..da4660779 100644 --- a/docs/pscripts/pviews.rst +++ b/docs/pscripts/pviews.rst @@ -3,11 +3,7 @@ .. _pviews_script: -``pviews`` ----------- - -.. program-output:: pviews --help - :prompt: - :shell: +.. autoprogram:: pyramid.scripts.pviews:PViewsCommand.parser + :prog: pviews .. seealso:: :ref:`displaying_matching_views` diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index 9018eddb4..81150a801 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -1,4 +1,4 @@ -import optparse +import argparse import sys import textwrap @@ -13,7 +13,6 @@ def main(argv=sys.argv, quiet=False): return command.run() class PViewsCommand(object): - usage = '%prog config_uri url' description = """\ Print, for a given URL, the views that might match. Underneath each potentially matching route, list the predicates required. Underneath @@ -28,16 +27,19 @@ class PViewsCommand(object): """ stdout = sys.stdout - parser = optparse.OptionParser( - usage, + parser = argparse.ArgumentParser( + usage="%(prog)s config_uri url", description=textwrap.dedent(description) ) + parser.add_argument('config_uri', + help='The URI to the configuration file.') + bootstrap = (bootstrap,) # testing def __init__(self, argv, quiet=False): self.quiet = quiet - self.options, self.args = self.parser.parse_args(argv[1:]) + self.args = self.parser.parse_args(argv[1:]) def out(self, msg): # pragma: no cover if not self.quiet: -- cgit v1.2.3 From c47bfc66d61a692d9790ae1f8cf79599a7e2bbb5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 28 Nov 2016 16:32:15 -0800 Subject: restore slice of argv --- pyramid/scripts/pcreate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 49e5fbdf4..671233337 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -87,7 +87,7 @@ https://github.com/Pylons/?q=cookiecutter def __init__(self, argv, quiet=False): self.quiet = quiet - self.args = self.parser.parse_args(argv) + self.args = self.parser.parse_args(argv[1:]) if not self.args.interactive and not self.args.overwrite: self.args.interactive = True self.scaffolds = self.all_scaffolds() -- cgit v1.2.3 From 8d6301820dd4f13d2ab0424764d6969a8508b2a8 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 5 Dec 2016 23:14:05 -0800 Subject: make output_directory optional for argparse --- pyramid/scripts/pcreate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 671233337..278727308 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -80,6 +80,8 @@ https://github.com/Pylons/?q=cookiecutter 'is the name of an already existing / importable ' 'package.') parser.add_argument('output_directory', + nargs = '?', + default = None, help='The directory where the project will be ' 'created.') -- cgit v1.2.3 From 4996dbe000774b8d6fe015dd5d29b9bd9bfc827d Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 5 Dec 2016 23:15:17 -0800 Subject: add new test in attempt to catch status code and stderr --- pyramid/tests/test_scripts/test_pcreate.py | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pyramid/tests/test_scripts/test_pcreate.py b/pyramid/tests/test_scripts/test_pcreate.py index 0286614ce..d6e6814fa 100644 --- a/pyramid/tests/test_scripts/test_pcreate.py +++ b/pyramid/tests/test_scripts/test_pcreate.py @@ -1,6 +1,32 @@ +from contextlib import contextmanager import unittest +@contextmanager +def patch_argparser(parser): + result = {} + old_exit = parser.exit + old_error = parser.error + try: + def dummy_exit(status=0, message=None): + result['status'] = status + result['message'] = message + raise ArgumentParserExit + + def dummy_error(message): + result['message'] = message + + parser.exit = dummy_exit + parser.error = dummy_error + yield result + finally: + parser.exit = old_exit + parser.error = old_error + +class ArgumentParserExit(Exception): + pass + + class TestPCreateCommand(unittest.TestCase): def setUp(self): from pyramid.compat import NativeIO @@ -49,6 +75,19 @@ class TestPCreateCommand(unittest.TestCase): self.assertTrue(out.count( 'You must provide at least one scaffold name')) + def test_test_no_project_name(self): + cmd = self._makeOne('-s', 'dummy') + with patch_argparser(cmd.parser) as result: + try: + cmd.run() + except ArgumentParserExit: + self.assertEqual(result['status'], 2) + self.assertTrue(result['message'].startswith( + 'usage: pcreate [-h] [-s SCAFFOLD_NAME] [-t SCAFFOLD_NAME] [-l]' + )) + else: # pragma: no cover + raise AssertionError + def test_no_project_name(self): cmd = self._makeOne('-s', 'dummy') result = cmd.run() -- cgit v1.2.3 From 74bed06995593b967afb626c6b3754861afb35b8 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 5 Dec 2016 23:49:31 -0800 Subject: tear out irrelevant test code, fix pcreate validation to test for output_directory --- pyramid/scripts/pcreate.py | 2 +- pyramid/tests/test_scripts/test_pcreate.py | 39 ------------------------------ 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 278727308..076b727a2 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -198,7 +198,7 @@ https://github.com/Pylons/?q=cookiecutter self.out('') self.show_scaffolds() return False - if not self.args: + if not self.args.output_directory: self.out('You must provide a project name') return False available = [x.name for x in self.scaffolds] diff --git a/pyramid/tests/test_scripts/test_pcreate.py b/pyramid/tests/test_scripts/test_pcreate.py index d6e6814fa..0286614ce 100644 --- a/pyramid/tests/test_scripts/test_pcreate.py +++ b/pyramid/tests/test_scripts/test_pcreate.py @@ -1,32 +1,6 @@ -from contextlib import contextmanager import unittest -@contextmanager -def patch_argparser(parser): - result = {} - old_exit = parser.exit - old_error = parser.error - try: - def dummy_exit(status=0, message=None): - result['status'] = status - result['message'] = message - raise ArgumentParserExit - - def dummy_error(message): - result['message'] = message - - parser.exit = dummy_exit - parser.error = dummy_error - yield result - finally: - parser.exit = old_exit - parser.error = old_error - -class ArgumentParserExit(Exception): - pass - - class TestPCreateCommand(unittest.TestCase): def setUp(self): from pyramid.compat import NativeIO @@ -75,19 +49,6 @@ class TestPCreateCommand(unittest.TestCase): self.assertTrue(out.count( 'You must provide at least one scaffold name')) - def test_test_no_project_name(self): - cmd = self._makeOne('-s', 'dummy') - with patch_argparser(cmd.parser) as result: - try: - cmd.run() - except ArgumentParserExit: - self.assertEqual(result['status'], 2) - self.assertTrue(result['message'].startswith( - 'usage: pcreate [-h] [-s SCAFFOLD_NAME] [-t SCAFFOLD_NAME] [-l]' - )) - else: # pragma: no cover - raise AssertionError - def test_no_project_name(self): cmd = self._makeOne('-s', 'dummy') result = cmd.run() -- cgit v1.2.3 From 6293d331046c78e27a0065d39a5277040391dd2d Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 6 Dec 2016 00:14:00 -0800 Subject: use ArgumentParser's default usage, specify prog argument --- pyramid/scripts/pdistreport.py | 2 +- pyramid/scripts/prequest.py | 2 +- pyramid/scripts/proutes.py | 5 ++--- pyramid/scripts/pshell.py | 2 +- pyramid/scripts/ptweens.py | 2 +- pyramid/scripts/pviews.py | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index e80ea20b6..e5928bde4 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -12,7 +12,7 @@ def out(*args): # pragma: no cover def get_parser(): parser = argparse.ArgumentParser( - usage="%(prog)s", + prog="pdistreport", description="Show Python distribution versions and locations in use") return parser diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 9e807896d..84e84e1c8 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -47,7 +47,7 @@ class PRequestCommand(object): """ parser = argparse.ArgumentParser( - usage="%(prog)s config_uri path_info [args/options]", + prog="prequest", description=textwrap.dedent(description) ) parser.add_argument( diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 640cd20a3..e745e19fd 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -247,10 +247,9 @@ class PRoutesCommand(object): """ bootstrap = (bootstrap,) stdout = sys.stdout - usage = '%prog config_uri' - ConfigParser = configparser.ConfigParser # testing + ConfigParser = configparser.ConfigParser # testing parser = argparse.ArgumentParser( - usage, + prog="proutes", description=textwrap.dedent(description) ) parser.add_argument('-g', '--glob', diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 7e00eeaac..4289f10c4 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -45,7 +45,7 @@ class PShellCommand(object): pkg_resources = pkg_resources # for testing parser = argparse.ArgumentParser( - usage="%(prog)s config_uri", + prog="pshell", description=textwrap.dedent(description) ) parser.add_argument('-p', '--python-shell', diff --git a/pyramid/scripts/ptweens.py b/pyramid/scripts/ptweens.py index 3f8c9871e..ed91757ab 100644 --- a/pyramid/scripts/ptweens.py +++ b/pyramid/scripts/ptweens.py @@ -28,7 +28,7 @@ class PTweensCommand(object): """ parser = argparse.ArgumentParser( - usage="%(prog)s config_uri", + prog="ptweens", description=textwrap.dedent(description), ) diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index 81150a801..e93d90a53 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -28,7 +28,7 @@ class PViewsCommand(object): stdout = sys.stdout parser = argparse.ArgumentParser( - usage="%(prog)s config_uri url", + prog="pviews", description=textwrap.dedent(description) ) -- cgit v1.2.3 From 31be0f5f72acf412486c66f2d423bbbec30091d5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 6 Dec 2016 00:43:00 -0800 Subject: make prequest tests pass --- pyramid/scripts/prequest.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 84e84e1c8..e4595a9cd 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -89,11 +89,15 @@ class PRequestCommand(object): parser.add_argument( 'config_uri', + nargs='?', + default=None, help='The URI to the configuration file.', ) parser.add_argument( 'path_info', + nargs='?', + default=None, help='The path of the request.', ) @@ -112,11 +116,11 @@ class PRequestCommand(object): setup_logging(app_spec) def run(self): - if not len(self.args) >= 2: + if not self.args.config_uri and not self.args.path_info: self.out('You must provide at least two arguments') return 2 - app_spec = self.args[0] - path = self.args[1] + app_spec = self.args.config_uri + path = self.args.path_info self.configure_logging(app_spec) @@ -146,7 +150,7 @@ class PRequestCommand(object): headers[name] = value.strip() app = self.get_app(app_spec, self.args.app_name, - options=parse_vars(self.args[2:])) + options=self.args) request_method = (self.args.method or 'GET').upper() -- cgit v1.2.3 From 307ee47697125ee34c615b44c57a9d84dd24d732 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 6 Dec 2016 02:39:17 -0800 Subject: update remaining pscripts to use nargs --- pyramid/scripts/proutes.py | 2 ++ pyramid/scripts/pshell.py | 2 ++ pyramid/scripts/ptweens.py | 2 ++ pyramid/scripts/pviews.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index e745e19fd..a957b622a 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -268,6 +268,8 @@ class PRoutesCommand(object): parser.add_argument( 'config_uri', + nargs='?', + default=None, help='The URI to the configuration file.', ) diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 4289f10c4..a7fa121cf 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -66,6 +66,8 @@ class PShellCommand(object): "option will override the 'setup' key in the " "[pshell] ini section.")) parser.add_argument('config_uri', + nargs='?', + default=None, help='The URI to the configuration file.') ConfigParser = configparser.ConfigParser # testing diff --git a/pyramid/scripts/ptweens.py b/pyramid/scripts/ptweens.py index ed91757ab..4c1555473 100644 --- a/pyramid/scripts/ptweens.py +++ b/pyramid/scripts/ptweens.py @@ -33,6 +33,8 @@ class PTweensCommand(object): ) parser.add_argument('config_uri', + nargs='?', + default=None, help='The URI to the configuration file.') stdout = sys.stdout diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index e93d90a53..7776077a8 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -33,6 +33,8 @@ class PViewsCommand(object): ) parser.add_argument('config_uri', + nargs='?', + default=None, help='The URI to the configuration file.') bootstrap = (bootstrap,) # testing -- cgit v1.2.3 From a4f18f93ecaf1fcd0bfb78aba7c6faf99762d253 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 7 Dec 2016 20:31:45 -0800 Subject: update proutes with argparse-ish stuff --- pyramid/scripts/proutes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index a957b622a..696bdd953 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -326,8 +326,8 @@ class PRoutesCommand(object): self.out('requires a config file argument') return 2 - config_uri = self.args[0] - env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:])) + config_uri = self.args.config_uri + env = self.bootstrap[0](config_uri, options=vars(self.args)) registry = env['registry'] mapper = self._get_mapper(registry) -- cgit v1.2.3 From 83fb105cd8a5c0fff4aa8da35ee43c48c7b0424e Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 7 Dec 2016 20:49:16 -0800 Subject: test for the attribute config_uri --- pyramid/scripts/proutes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 696bdd953..92ec48ed1 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -322,7 +322,7 @@ class PRoutesCommand(object): return config.get_routes_mapper() def run(self, quiet=False): - if not self.args: + if not self.args.config_uri: self.out('requires a config file argument') return 2 -- cgit v1.2.3 From e96b2b5d5b9ebab33cd6eb84ef498dbaf4da18cb Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 7 Dec 2016 22:26:54 -0800 Subject: add an argument `config_args` to be parsed and passed into bootstrap's options --- pyramid/scripts/proutes.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 92ec48ed1..cf3ae5e9c 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -273,6 +273,14 @@ class PRoutesCommand(object): help='The URI to the configuration file.', ) + parser.add_argument( + 'config_args', + nargs='*', + default=(), + help='Arbitrary options to override those in the [app:main] section ' + 'of the configuration file.', + ) + def __init__(self, argv, quiet=False): self.args = self.parser.parse_args(argv[1:]) self.quiet = quiet @@ -327,7 +335,7 @@ class PRoutesCommand(object): return 2 config_uri = self.args.config_uri - env = self.bootstrap[0](config_uri, options=vars(self.args)) + env = self.bootstrap[0](config_uri, options=parse_vars(self.args.config_args)) registry = env['registry'] mapper = self._get_mapper(registry) -- cgit v1.2.3 From 0be0f1028ff8f996147ab275a403d6b99e43b932 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 7 Dec 2016 23:10:02 -0800 Subject: fix proutes tests --- pyramid/tests/test_scripts/test_proutes.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index aeaa57060..e0a5be93a 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -20,7 +20,7 @@ class TestPRoutesCommand(unittest.TestCase): def _makeOne(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_uri = ('/foo/bar/myapp.ini#myapp',) return cmd @@ -38,7 +38,8 @@ class TestPRoutesCommand(unittest.TestCase): def test_good_args(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args = ('/foo/bar/myapp.ini#myapp', 'a=1') + cmd.args.config_uri = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_args = ('a=1',) route = dummy.DummyRoute('a', '/a') mapper = dummy.DummyMapper(route) cmd._get_mapper = lambda *arg: mapper @@ -52,7 +53,8 @@ class TestPRoutesCommand(unittest.TestCase): def test_bad_args(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args = ('/foo/bar/myapp.ini#myapp', 'a') + cmd.args.config_uri = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_args = ('a',) route = dummy.DummyRoute('a', '/a') mapper = dummy.DummyMapper(route) cmd._get_mapper = lambda *arg: mapper @@ -586,7 +588,7 @@ class TestPRoutesCommand(unittest.TestCase): ) command = self._makeOne() - command.options.glob = '*foo*' + command.args.glob = '*foo*' L = [] command.out = L.append @@ -618,8 +620,8 @@ class TestPRoutesCommand(unittest.TestCase): ) command = self._makeOne() - command.options.glob = '*foo*' - command.options.format = 'method,name' + command.args.glob = '*foo*' + command.args.format = 'method,name' L = [] command.out = L.append command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),) @@ -648,8 +650,8 @@ class TestPRoutesCommand(unittest.TestCase): ) command = self._makeOne() - command.options.glob = '*foo*' - command.options.format = 'predicates,name,pattern' + command.args.glob = '*foo*' + command.args.format = 'predicates,name,pattern' L = [] command.out = L.append command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),) -- cgit v1.2.3 From 9de2cd1d05ff62e3f75930559c2d83553df45d80 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 05:08:32 -0800 Subject: fix pserve to allow 4 of 5 tests to pass --- pyramid/scripts/pserve.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index f3515804d..50f4ac1d2 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -100,8 +100,18 @@ class PServeCommand(object): help="Suppress verbose output") parser.add_argument( 'config_uri', + nargs='?', + default=None, help='The URI to the configuration file.', ) + parser.add_argument( + 'config_args', + nargs='*', + default=(), + help='Arbitrary options to override those in the [app:main] section ' + 'of the configuration file.', + ) + ConfigParser = configparser.ConfigParser # testing loadapp = staticmethod(loadapp) # testing @@ -120,7 +130,7 @@ class PServeCommand(object): print(msg) def get_options(self): - restvars = self.args[1:] + restvars = self.args.config_args return parse_vars(restvars) def pserve_file_config(self, filename, global_conf=None): @@ -150,10 +160,10 @@ class PServeCommand(object): self.watch_files.append(os.path.abspath(file)) def run(self): # pragma: no cover - if not self.args: + if not self.args.config_uri: self.out('You must give a config file') return 2 - app_spec = self.args[0] + app_spec = self.args.config_uri vars = self.get_options() app_name = self.args.app_name -- cgit v1.2.3 From 3b72e86a4dc05086fb06b89f108d4e8129ec7d7c Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 15:28:51 -0800 Subject: refactor get_options to get_config_args --- pyramid/scripts/pserve.py | 4 ++-- pyramid/tests/test_scripts/test_pserve.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 50f4ac1d2..6581c1b7a 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -129,7 +129,7 @@ class PServeCommand(object): if self.args.verbose > 0: print(msg) - def get_options(self): + def get_config_args(self): restvars = self.args.config_args return parse_vars(restvars) @@ -165,7 +165,7 @@ class PServeCommand(object): return 2 app_spec = self.args.config_uri - vars = self.get_options() + vars = self.get_config_args() app_name = self.args.app_name base = os.getcwd() diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index 18f7c8c2f..9934fc441 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -36,10 +36,10 @@ class TestPServeCommand(unittest.TestCase): self.assertEqual(result, 2) self.assertEqual(self.out_.getvalue(), 'You must give a config file') - def test_get_options_no_command(self): + def test_config_args_no_command(self): inst = self._makeOne() inst.args = ['foo', 'a=1', 'b=2'] - result = inst.get_options() + result = inst.get_config_args() self.assertEqual(result, {'a': '1', 'b': '2'}) def test_parse_vars_good(self): -- cgit v1.2.3 From 7ff9e9a3229a709f357a88d39763e34d9fb62206 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 15:46:52 -0800 Subject: get final pserve test to pass - ping @mmerickel or @bertjwregeer for review. I'm uncertain about what was the original test's intent, and whether this test still tests what was originally intended. --- pyramid/tests/test_scripts/test_pserve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index 9934fc441..f19985b35 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -38,7 +38,7 @@ class TestPServeCommand(unittest.TestCase): def test_config_args_no_command(self): inst = self._makeOne() - inst.args = ['foo', 'a=1', 'b=2'] + inst.args.config_args = ['a=1', 'b=2'] result = inst.get_config_args() self.assertEqual(result, {'a': '1', 'b': '2'}) -- cgit v1.2.3 From be51e57ac1f423579dc7426f93e957e3bf8ef450 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 17:04:22 -0800 Subject: test for self.args.output_directory instead of just self.args --- pyramid/scripts/pcreate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 076b727a2..b3181c2b3 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -98,7 +98,7 @@ https://github.com/Pylons/?q=cookiecutter self._warn_pcreate_deprecated() if self.args.list: return self.show_scaffolds() - if not self.args.scaffold_name and not self.args: + if not self.args.scaffold_name and not self.args.output_directory: if not self.quiet: # pragma: no cover self.parser.print_help() self.out('') -- cgit v1.2.3 From 5320e7e0d4b465a7c38004652c3ccf4c5b4e79c7 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 17:11:30 -0800 Subject: add config_args option, fix nonsense options parameter --- pyramid/scripts/prequest.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index e4595a9cd..2025ecccc 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -101,6 +101,14 @@ class PRequestCommand(object): help='The path of the request.', ) + parser.add_argument( + 'config_args', + nargs='*', + default=(), + help='Arbitrary options to override those in the [app:main] section ' + 'of the configuration file.', + ) + get_app = staticmethod(get_app) stdin = sys.stdin @@ -150,7 +158,7 @@ class PRequestCommand(object): headers[name] = value.strip() app = self.get_app(app_spec, self.args.app_name, - options=self.args) + options=self.args.config_args) request_method = (self.args.method or 'GET').upper() -- cgit v1.2.3 From 898014c2e3b3fcebe5c5e7040ff3ca1409422873 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 17:11:49 -0800 Subject: use default usage --- pyramid/scripts/pserve.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 6581c1b7a..3816e7c75 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -51,7 +51,6 @@ class PServeCommand(object): default_verbosity = 1 parser = argparse.ArgumentParser( - usage="%(prog)s config_uri [var=value]", description=textwrap.dedent(description) ) parser.add_argument( -- cgit v1.2.3 From 1fc1b819f9364c0d64fc4e60c514141a58d641da Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 18:06:59 -0800 Subject: test for self.args.list and self.args.config_uri --- pyramid/scripts/pshell.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index a7fa121cf..9268c6e10 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -110,12 +110,12 @@ class PShellCommand(object): print(msg) def run(self, shell=None): - if self.options.list: + if self.args.list: return self.show_shells() - if not self.args: + if not self.args.config_uri: self.out('Requires a config file argument') return 2 - config_uri = self.args[0] + config_uri = self.args.config_uri config_file = config_uri.split('#', 1)[0] setup_logging(config_file) self.pshell_file_config(config_file) -- cgit v1.2.3 From d631aff9fd4a144cb9fce265b644aa3affbb6188 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 18:14:13 -0800 Subject: remove prog argument --- pyramid/scripts/pdistreport.py | 1 - pyramid/scripts/prequest.py | 1 - pyramid/scripts/proutes.py | 3 +-- pyramid/scripts/pshell.py | 1 - pyramid/scripts/ptweens.py | 1 - 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pyramid/scripts/pdistreport.py b/pyramid/scripts/pdistreport.py index e5928bde4..1952e5d39 100644 --- a/pyramid/scripts/pdistreport.py +++ b/pyramid/scripts/pdistreport.py @@ -12,7 +12,6 @@ def out(*args): # pragma: no cover def get_parser(): parser = argparse.ArgumentParser( - prog="pdistreport", description="Show Python distribution versions and locations in use") return parser diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 2025ecccc..1da54b8c0 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -47,7 +47,6 @@ class PRequestCommand(object): """ parser = argparse.ArgumentParser( - prog="prequest", description=textwrap.dedent(description) ) parser.add_argument( diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index cf3ae5e9c..26c112cde 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -249,9 +249,8 @@ class PRoutesCommand(object): stdout = sys.stdout ConfigParser = configparser.ConfigParser # testing parser = argparse.ArgumentParser( - prog="proutes", description=textwrap.dedent(description) - ) + ) parser.add_argument('-g', '--glob', action='store', dest='glob', diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 9268c6e10..08aae6980 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -45,7 +45,6 @@ class PShellCommand(object): pkg_resources = pkg_resources # for testing parser = argparse.ArgumentParser( - prog="pshell", description=textwrap.dedent(description) ) parser.add_argument('-p', '--python-shell', diff --git a/pyramid/scripts/ptweens.py b/pyramid/scripts/ptweens.py index 4c1555473..7f0101323 100644 --- a/pyramid/scripts/ptweens.py +++ b/pyramid/scripts/ptweens.py @@ -28,7 +28,6 @@ class PTweensCommand(object): """ parser = argparse.ArgumentParser( - prog="ptweens", description=textwrap.dedent(description), ) -- cgit v1.2.3 From a8667577659a2622973dc80d177ac143fd161587 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 18:56:58 -0800 Subject: refactor config_args to config_vars --- pyramid/scripts/prequest.py | 4 ++-- pyramid/scripts/proutes.py | 4 ++-- pyramid/scripts/pserve.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 1da54b8c0..714aedf10 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -101,7 +101,7 @@ class PRequestCommand(object): ) parser.add_argument( - 'config_args', + 'config_vars', nargs='*', default=(), help='Arbitrary options to override those in the [app:main] section ' @@ -157,7 +157,7 @@ class PRequestCommand(object): headers[name] = value.strip() app = self.get_app(app_spec, self.args.app_name, - options=self.args.config_args) + options=self.args.config_vars) request_method = (self.args.method or 'GET').upper() diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 26c112cde..df8e51e39 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -273,7 +273,7 @@ class PRoutesCommand(object): ) parser.add_argument( - 'config_args', + 'config_vars', nargs='*', default=(), help='Arbitrary options to override those in the [app:main] section ' @@ -334,7 +334,7 @@ class PRoutesCommand(object): return 2 config_uri = self.args.config_uri - env = self.bootstrap[0](config_uri, options=parse_vars(self.args.config_args)) + env = self.bootstrap[0](config_uri, options=parse_vars(self.args.config_vars)) registry = env['registry'] mapper = self._get_mapper(registry) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 3816e7c75..51cdd235a 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -104,7 +104,7 @@ class PServeCommand(object): help='The URI to the configuration file.', ) parser.add_argument( - 'config_args', + 'config_vars', nargs='*', default=(), help='Arbitrary options to override those in the [app:main] section ' @@ -128,8 +128,8 @@ class PServeCommand(object): if self.args.verbose > 0: print(msg) - def get_config_args(self): - restvars = self.args.config_args + def get_config_vars(self): + restvars = self.args.config_vars return parse_vars(restvars) def pserve_file_config(self, filename, global_conf=None): @@ -164,7 +164,7 @@ class PServeCommand(object): return 2 app_spec = self.args.config_uri - vars = self.get_config_args() + vars = self.get_config_vars() app_name = self.args.app_name base = os.getcwd() -- cgit v1.2.3 From b5faf2f17baddbc08bf43da2d244f6970ce9b012 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 19:05:39 -0800 Subject: update help for pserve config_vars --- pyramid/scripts/pserve.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 51cdd235a..845933c27 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -107,9 +107,10 @@ class PServeCommand(object): 'config_vars', nargs='*', default=(), - help='Arbitrary options to override those in the [app:main] section ' - 'of the configuration file.', - ) + help="Variables required by the config file. For example, " + "`http_port=%%(http_port)s` would expect `http_port=8080` to be " + "passed here.", + ) ConfigParser = configparser.ConfigParser # testing -- cgit v1.2.3 From a63b0f56e02f8b59cb4c36f1b1facf8dd48766af Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 10 Dec 2016 19:23:45 -0800 Subject: - change from tuple to string - refactor config_args to config_vars --- pyramid/tests/test_scripts/test_proutes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index e0a5be93a..3c51ea6b4 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -20,7 +20,7 @@ class TestPRoutesCommand(unittest.TestCase): def _makeOne(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args.config_uri = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_uri = '/foo/bar/myapp.ini#myapp' return cmd @@ -53,8 +53,8 @@ class TestPRoutesCommand(unittest.TestCase): def test_bad_args(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args.config_uri = ('/foo/bar/myapp.ini#myapp',) - cmd.args.config_args = ('a',) + cmd.args.config_uri = '/foo/bar/myapp.ini#myapp' + cmd.args.config_vars = ('a',) route = dummy.DummyRoute('a', '/a') mapper = dummy.DummyMapper(route) cmd._get_mapper = lambda *arg: mapper -- cgit v1.2.3 From 67f0c2f626036f404c46982ba0ac58ea513f0e10 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 00:39:53 -0800 Subject: restore parse_vars --- pyramid/scripts/prequest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 714aedf10..f0ac0dfa9 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -157,7 +157,7 @@ class PRequestCommand(object): headers[name] = value.strip() app = self.get_app(app_spec, self.args.app_name, - options=self.args.config_vars) + options=parse_vars(self.args.config_vars)) request_method = (self.args.method or 'GET').upper() -- cgit v1.2.3 From 81e59a914c151d65cdd45d5f6f8c53b889aa77b8 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 00:40:43 -0800 Subject: remove prog argument --- pyramid/scripts/pviews.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index 7776077a8..4c511a102 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -28,7 +28,6 @@ class PViewsCommand(object): stdout = sys.stdout parser = argparse.ArgumentParser( - prog="pviews", description=textwrap.dedent(description) ) -- cgit v1.2.3 From aa1ce33153eaa0c44ddfe5e0be173cbbd915c477 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 00:42:04 -0800 Subject: change config to tuple from string --- pyramid/tests/test_scripts/test_proutes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index 3c51ea6b4..74293a112 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -38,7 +38,7 @@ class TestPRoutesCommand(unittest.TestCase): def test_good_args(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args.config_uri = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_uri = '/foo/bar/myapp.ini#myapp' cmd.args.config_args = ('a=1',) route = dummy.DummyRoute('a', '/a') mapper = dummy.DummyMapper(route) -- cgit v1.2.3 From 931cbd9df499dc9c82c30081757a1d315cf89083 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 00:43:54 -0800 Subject: one more refactor of config_args to config_vars; bring back 'foo' as an arg --- pyramid/tests/test_scripts/test_pserve.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index f19985b35..5f6d6ee57 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -38,8 +38,8 @@ class TestPServeCommand(unittest.TestCase): def test_config_args_no_command(self): inst = self._makeOne() - inst.args.config_args = ['a=1', 'b=2'] - result = inst.get_config_args() + inst.args.config_args = ['foo', 'a=1', 'b=2'] + result = inst.get_config_vars() self.assertEqual(result, {'a': '1', 'b': '2'}) def test_parse_vars_good(self): -- cgit v1.2.3 From 2b7d128b9c5f1587f22c651ae44f71c331b22827 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 00:47:56 -0800 Subject: one more refactor of config_args to config_vars --- pyramid/tests/test_scripts/test_pserve.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index 5f6d6ee57..4eb85edf9 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -36,9 +36,9 @@ class TestPServeCommand(unittest.TestCase): self.assertEqual(result, 2) self.assertEqual(self.out_.getvalue(), 'You must give a config file') - def test_config_args_no_command(self): + def test_config_vars_no_command(self): inst = self._makeOne() - inst.args.config_args = ['foo', 'a=1', 'b=2'] + inst.args.config_vars = ['foo', 'a=1', 'b=2'] result = inst.get_config_vars() self.assertEqual(result, {'a': '1', 'b': '2'}) -- cgit v1.2.3 From 74b2368db37f360bf1021ab8b1d35961944597b5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 00:55:53 -0800 Subject: brain function temporarily restored, split config_vars into _vars and _uri - herpderp --- pyramid/tests/test_scripts/test_pserve.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index 4eb85edf9..18b0c84b6 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -38,7 +38,8 @@ class TestPServeCommand(unittest.TestCase): def test_config_vars_no_command(self): inst = self._makeOne() - inst.args.config_vars = ['foo', 'a=1', 'b=2'] + inst.args.config_uri = 'foo' + inst.args.config_vars = ['a=1', 'b=2'] result = inst.get_config_vars() self.assertEqual(result, {'a': '1', 'b': '2'}) -- cgit v1.2.3 From 0a3a208cb1bbe21c8e350f83a47bade71cdb8f4f Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 03:06:35 -0800 Subject: add missing period --- pyramid/scripts/pshell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 08aae6980..7fa2f04a1 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -33,7 +33,7 @@ class PShellCommand(object): accepts one positional argument named "config_uri" which specifies the PasteDeploy config file to use for the interactive shell. The format is "inifile#name". If the name is left off, the Pyramid default application - will be assumed. Example: "pshell myapp.ini#main" + will be assumed. Example: "pshell myapp.ini#main". If you do not point the loader directly at the section of the ini file containing your Pyramid application, the command will attempt to -- cgit v1.2.3 From 53937c4083a06479050400f96b4eae2f0795c064 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 03:17:38 -0800 Subject: change command.options to command.args --- pyramid/tests/test_scripts/test_pshell.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pshell.py b/pyramid/tests/test_scripts/test_pshell.py index f98ded6d3..45d21015b 100644 --- a/pyramid/tests/test_scripts/test_pshell.py +++ b/pyramid/tests/test_scripts/test_pshell.py @@ -71,7 +71,7 @@ class TestPShellCommand(unittest.TestCase): self._makeEntryPoints(command, {}) command.default_runner = shell - command.options.python_shell = 'unknown_python_shell' + command.args.python_shell = 'unknown_python_shell' result = command.run() self.assertEqual(result, 1) self.assertEqual( @@ -95,7 +95,7 @@ class TestPShellCommand(unittest.TestCase): } ) - command.options.python_shell = 'ipython' + command.args.python_shell = 'ipython' command.run() self.assertTrue(self.config_factory.parser) @@ -140,7 +140,7 @@ class TestPShellCommand(unittest.TestCase): shell = command.make_shell() self.assertEqual(shell, dshell) - command.options.python_shell = 'ipython' + command.args.python_shell = 'ipython' self.assertRaises(ValueError, command.make_shell) self._makeEntryPoints( @@ -152,15 +152,15 @@ class TestPShellCommand(unittest.TestCase): } ) - command.options.python_shell = 'ipython' + command.args.python_shell = 'ipython' shell = command.make_shell() self.assertEqual(shell, ipshell) - command.options.python_shell = 'bpython' + command.args.python_shell = 'bpython' shell = command.make_shell() self.assertEqual(shell, bpshell) - command.options.python_shell = 'python' + command.args.python_shell = 'python' shell = command.make_shell() self.assertEqual(shell, dshell) @@ -291,7 +291,7 @@ class TestPShellCommand(unittest.TestCase): model = dummy.Dummy() self.config_factory.items = [('setup', 'abc'), ('m', model)] - command.options.setup = setup + command.args.setup = setup shell = dummy.DummyShell() command.run(shell) self.assertTrue(self.config_factory.parser) @@ -365,7 +365,7 @@ class TestPShellCommand(unittest.TestCase): } ) - command.options.list = True + command.args.list = True result = command.run() self.assertEqual(result, 0) self.assertEqual(out_calls, [ -- cgit v1.2.3 From ba93133ee29ecacad04770af7dffc39f2b2d3aff Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 04:02:01 -0800 Subject: update ptweens with config_vars argument - replace self.args with self.args.config_uri --- pyramid/scripts/ptweens.py | 14 +++++++++++--- pyramid/tests/test_scripts/test_ptweens.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyramid/scripts/ptweens.py b/pyramid/scripts/ptweens.py index 7f0101323..348f2b372 100644 --- a/pyramid/scripts/ptweens.py +++ b/pyramid/scripts/ptweens.py @@ -36,6 +36,14 @@ class PTweensCommand(object): default=None, help='The URI to the configuration file.') + parser.add_argument( + 'config_vars', + nargs='*', + default=(), + help='Arbitrary options to override those in the [app:main] section ' + 'of the configuration file.', + ) + stdout = sys.stdout bootstrap = (bootstrap,) # testing @@ -62,11 +70,11 @@ class PTweensCommand(object): self.out(fmt % ('-', MAIN)) def run(self): - if not self.args: + if not self.args.config_uri: self.out('Requires a config file argument') return 2 - config_uri = self.args[0] - env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:])) + config_uri = self.args.config_uri + env = self.bootstrap[0](config_uri, options=parse_vars(self.args.config_vars)) registry = env['registry'] tweens = self._get_tweens(registry) if tweens is not None: diff --git a/pyramid/tests/test_scripts/test_ptweens.py b/pyramid/tests/test_scripts/test_ptweens.py index f39f84b68..f63069fed 100644 --- a/pyramid/tests/test_scripts/test_ptweens.py +++ b/pyramid/tests/test_scripts/test_ptweens.py @@ -9,7 +9,7 @@ class TestPTweensCommand(unittest.TestCase): def _makeOne(self): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(),) - cmd.args = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_uri = '/foo/bar/myapp.ini#myapp' return cmd def test_command_no_tweens(self): -- cgit v1.2.3 From 5b40cd38daf5c1a58810a0bff364be0043bc46ba Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 04:15:53 -0800 Subject: update pviews with url, config_vars arguments - fix run(self) method - use correct self.args.config_url and .url in tests --- pyramid/scripts/pviews.py | 22 ++++++++++++++---- pyramid/tests/test_scripts/test_pviews.py | 38 ++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index 4c511a102..c109f884a 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -36,6 +36,20 @@ class PViewsCommand(object): default=None, help='The URI to the configuration file.') + parser.add_argument('url', + nargs='?', + default=None, + help='The path info portion of the URL.') + parser.add_argument( + 'config_vars', + nargs='*', + default=(), + help="Variables required by the config file. For example, " + "`http_port=%%(http_port)s` would expect `http_port=8080` to be " + "passed here.", + ) + + bootstrap = (bootstrap,) # testing def __init__(self, argv, quiet=False): @@ -233,16 +247,16 @@ class PViewsCommand(object): self.out("%sview predicates (%s)" % (indent, predicate_text)) def run(self): - if len(self.args) < 2: + if not self.args.config_uri and not self.args.url: self.out('Command requires a config file arg and a url arg') return 2 - config_uri = self.args[0] - url = self.args[1] + config_uri = self.args.config_uri + url = self.args.url if not url.startswith('/'): url = '/%s' % url request = Request.blank(url) - env = self.bootstrap[0](config_uri, options=parse_vars(self.args[2:]), + env = self.bootstrap[0](config_uri, options=parse_vars(self.args.config_vars), request=request) view = self._find_view(request) self.out('') diff --git a/pyramid/tests/test_scripts/test_pviews.py b/pyramid/tests/test_scripts/test_pviews.py index b162144a7..a67a8c4d6 100644 --- a/pyramid/tests/test_scripts/test_pviews.py +++ b/pyramid/tests/test_scripts/test_pviews.py @@ -9,7 +9,7 @@ class TestPViewsCommand(unittest.TestCase): def _makeOne(self, registry=None): cmd = self._getTargetClass()([]) cmd.bootstrap = (dummy.DummyBootstrap(registry=registry),) - cmd.args = ('/foo/bar/myapp.ini#myapp',) + cmd.args.config_uri = '/foo/bar/myapp.ini#myapp' return cmd def _makeRequest(self, url, registry): @@ -242,7 +242,8 @@ class TestPViewsCommand(unittest.TestCase): L = [] command.out = L.append command._find_view = lambda arg1: None - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -255,7 +256,8 @@ class TestPViewsCommand(unittest.TestCase): L = [] command.out = L.append command._find_view = lambda arg1: None - command.args = ('/foo/bar/myapp.ini#myapp', 'a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -269,7 +271,8 @@ class TestPViewsCommand(unittest.TestCase): command.out = L.append view = dummy.DummyView(context='context', view_name='a') command._find_view = lambda arg1: view - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -287,7 +290,8 @@ class TestPViewsCommand(unittest.TestCase): def view(): pass view.__request_attrs__ = {'context': 'context', 'view_name': 'a'} command._find_view = lambda arg1: view - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -305,7 +309,8 @@ class TestPViewsCommand(unittest.TestCase): view = dummy.DummyView(context='context', view_name='a') view.__permission__ = 'test' command._find_view = lambda arg1: view - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -326,7 +331,8 @@ class TestPViewsCommand(unittest.TestCase): view = dummy.DummyView(context='context', view_name='a') view.__predicates__ = [predicate] command._find_view = lambda arg1: view - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -346,7 +352,8 @@ class TestPViewsCommand(unittest.TestCase): view = dummy.DummyView(context='context', view_name='a', matched_route=route, subpath='') command._find_view = lambda arg1: view - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -374,7 +381,8 @@ class TestPViewsCommand(unittest.TestCase): multiview2 = dummy.DummyMultiView(multiview1, context='context', view_name='a') command._find_view = lambda arg1: multiview2 - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -397,7 +405,8 @@ class TestPViewsCommand(unittest.TestCase): view = dummy.DummyView(context='context', view_name='a', matched_route=route, subpath='') command._find_view = lambda arg1: view - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -423,7 +432,8 @@ class TestPViewsCommand(unittest.TestCase): view.__view_attr__ = 'call' multiview = dummy.DummyMultiView(view, context='context', view_name='a') command._find_view = lambda arg1: multiview - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -444,7 +454,8 @@ class TestPViewsCommand(unittest.TestCase): view.__permission__ = 'test' multiview = dummy.DummyMultiView(view, context='context', view_name='a') command._find_view = lambda arg1: multiview - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') @@ -468,7 +479,8 @@ class TestPViewsCommand(unittest.TestCase): view.__predicates__ = [predicate] multiview = dummy.DummyMultiView(view, context='context', view_name='a') command._find_view = lambda arg1: multiview - command.args = ('/foo/bar/myapp.ini#myapp', '/a') + command.args.config_uri = '/foo/bar/myapp.ini#myapp' + command.args.url = '/a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') -- cgit v1.2.3 From 3c431019de4899e6a71cc5650ec52df65d56b2d7 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 04:35:04 -0800 Subject: update pshell with config_vars argument --- pyramid/scripts/pshell.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 7fa2f04a1..d8abf6619 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -68,6 +68,14 @@ class PShellCommand(object): nargs='?', default=None, help='The URI to the configuration file.') + parser.add_argument( + 'config_vars', + nargs='*', + default=(), + help="Variables required by the config file. For example, " + "`http_port=%%(http_port)s` would expect `http_port=8080` to be " + "passed here.", + ) ConfigParser = configparser.ConfigParser # testing default_runner = python_shell_runner # testing @@ -120,7 +128,8 @@ class PShellCommand(object): self.pshell_file_config(config_file) # bootstrap the environ - env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:])) + env = self.bootstrap[0](config_uri, + options=parse_vars(self.args.config_vars)) # remove the closer from the env self.closer = env.pop('closer') -- cgit v1.2.3 From 2d9c134245614026ec9528e5a9e78ba1d923f64b Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 22:37:47 -0800 Subject: add an Args class, following pattern for OPtions; pshell tests now pass --- pyramid/tests/test_scripts/test_pshell.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pshell.py b/pyramid/tests/test_scripts/test_pshell.py index 45d21015b..303964b2b 100644 --- a/pyramid/tests/test_scripts/test_pshell.py +++ b/pyramid/tests/test_scripts/test_pshell.py @@ -19,8 +19,10 @@ class TestPShellCommand(unittest.TestCase): self.config_factory = dummy.DummyConfigParserFactory() cmd.ConfigParser = self.config_factory if patch_args: - self.args = ('/foo/bar/myapp.ini#myapp',) - cmd.args = self.args + class Args(object): pass + self.args = Args() + self.args.config_uri = '/foo/bar/myapp.ini#myapp' + cmd.args.config_uri = self.args.config_uri if patch_options: class Options(object): pass self.options = Options() -- cgit v1.2.3 From 2fcfda1392b99cc403c99328b1b197432c3ea145 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 22:57:42 -0800 Subject: change options to args for test_template. This now aligns with pcreate, which the test uses --- pyramid/tests/test_scaffolds/test_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/tests/test_scaffolds/test_template.py b/pyramid/tests/test_scaffolds/test_template.py index 2e961c516..98f2daf73 100644 --- a/pyramid/tests/test_scaffolds/test_template.py +++ b/pyramid/tests/test_scaffolds/test_template.py @@ -143,13 +143,13 @@ class DummyCopydir(object): self.vars = vars self.kw = kw -class DummyOptions(object): +class DummyArgs(object): simulate = False overwrite = False interactive = False class DummyCommand(object): - options = DummyOptions() + args = DummyArgs() verbosity = 1 -- cgit v1.2.3 From 0183e44b667fa03fbb437398778fefc7d09d142d Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 23:03:32 -0800 Subject: PEP8 --- pyramid/scripts/pcreate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index b3181c2b3..790fac230 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -80,8 +80,8 @@ https://github.com/Pylons/?q=cookiecutter 'is the name of an already existing / importable ' 'package.') parser.add_argument('output_directory', - nargs = '?', - default = None, + nargs='?', + default=None, help='The directory where the project will be ' 'created.') -- cgit v1.2.3 From 79f067b570cd8e23ee09a5b1de4b2fb3ec589a00 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 23:07:52 -0800 Subject: add sphinx.ext.todo, support for todo items --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 5496452bd..b9d2958b0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,6 +55,7 @@ extensions = [ 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx', 'sphinxcontrib.autoprogram', + 'sphinx.ext.todo', # enable pylons_sphinx_latesturl when this branch is no longer "latest" # 'pylons_sphinx_latesturl', ] -- cgit v1.2.3 From 8529b334e96078bac6c626da764db8f8e111ad72 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sun, 11 Dec 2016 23:14:20 -0800 Subject: fix test that caused coverage to drop one line --- pyramid/tests/test_scripts/test_pviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/tests/test_scripts/test_pviews.py b/pyramid/tests/test_scripts/test_pviews.py index a67a8c4d6..7bdab5804 100644 --- a/pyramid/tests/test_scripts/test_pviews.py +++ b/pyramid/tests/test_scripts/test_pviews.py @@ -257,7 +257,7 @@ class TestPViewsCommand(unittest.TestCase): command.out = L.append command._find_view = lambda arg1: None command.args.config_uri = '/foo/bar/myapp.ini#myapp' - command.args.url = '/a' + command.args.url = 'a' result = command.run() self.assertEqual(result, 0) self.assertEqual(L[1], 'URL = /a') -- cgit v1.2.3 From 258f8482549a75a627e5b80790ca7f7f84308684 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 13 Dec 2016 23:31:48 -0800 Subject: fix faulty logic in prequest and pviews --- pyramid/scripts/prequest.py | 2 +- pyramid/scripts/pviews.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index f0ac0dfa9..1136dd409 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -123,7 +123,7 @@ class PRequestCommand(object): setup_logging(app_spec) def run(self): - if not self.args.config_uri and not self.args.path_info: + if not self.args.config_uri or not self.args.path_info: self.out('You must provide at least two arguments') return 2 app_spec = self.args.config_uri diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index c109f884a..64408bdad 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -247,7 +247,7 @@ class PViewsCommand(object): self.out("%sview predicates (%s)" % (indent, predicate_text)) def run(self): - if not self.args.config_uri and not self.args.url: + if not self.args.config_uri or not self.args.url: self.out('Command requires a config file arg and a url arg') return 2 config_uri = self.args.config_uri -- cgit v1.2.3 From f5ae217a444b9ba3598038d55204df35cb624a42 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 13 Dec 2016 23:47:46 -0800 Subject: move deprecation warning further down in the logic to avoid it from being emitted for invalid commands --- pyramid/scripts/pcreate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 790fac230..d1200da42 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -95,7 +95,6 @@ https://github.com/Pylons/?q=cookiecutter self.scaffolds = self.all_scaffolds() def run(self): - self._warn_pcreate_deprecated() if self.args.list: return self.show_scaffolds() if not self.args.scaffold_name and not self.args.output_directory: @@ -107,6 +106,7 @@ https://github.com/Pylons/?q=cookiecutter if not self.validate_input(): return 2 + self._warn_pcreate_deprecated() return self.render_scaffolds() -- cgit v1.2.3 From 91db73661dfc4deccb68698a95004f2871aafcf1 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 13 Dec 2016 23:55:15 -0800 Subject: PEP8 --- pyramid/scripts/pcreate.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index d1200da42..75e3b1fdc 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -17,12 +17,12 @@ def main(argv=sys.argv, quiet=False): command = PCreateCommand(argv, quiet) try: return command.run() - except KeyboardInterrupt: # pragma: no cover + except KeyboardInterrupt: # pragma: no cover return 1 class PCreateCommand(object): - verbosity = 1 # required + verbosity = 1 # required parser = argparse.ArgumentParser(description="""\ Render Pyramid scaffolding to an output directory. @@ -98,7 +98,7 @@ https://github.com/Pylons/?q=cookiecutter if self.args.list: return self.show_scaffolds() if not self.args.scaffold_name and not self.args.output_directory: - if not self.quiet: # pragma: no cover + if not self.quiet: # pragma: no cover self.parser.print_help() self.out('') self.show_scaffolds() @@ -130,7 +130,7 @@ https://github.com/Pylons/?q=cookiecutter # get pyramid package version pyramid_version = self.pyramid_dist.version - ## map pyramid package version of the documentation branch ## + # map pyramid package version of the documentation branch ## # if version ends with 'dev' then docs version is 'master' if self.pyramid_dist.version[-3:] == 'dev': pyramid_docs_branch = 'master' @@ -152,7 +152,6 @@ https://github.com/Pylons/?q=cookiecutter 'pyramid_docs_branch': pyramid_docs_branch, } - def render_scaffolds(self): props = self.project_vars output_dir = self.output_path @@ -183,18 +182,19 @@ https://github.com/Pylons/?q=cookiecutter scaffold_class = entry.load() scaffold = scaffold_class(entry.name) scaffolds.append(scaffold) - except Exception as e: # pragma: no cover + except Exception as e: # pragma: no cover self.out('Warning: could not load entry point %s (%s: %s)' % ( entry.name, e.__class__.__name__, e)) return scaffolds - def out(self, msg): # pragma: no cover + def out(self, msg): # pragma: no cover if not self.quiet: print(msg) def validate_input(self): if not self.args.scaffold_name: - self.out('You must provide at least one scaffold name: -s ') + self.out('You must provide at least one scaffold name: ' + '-s ') self.out('') self.show_scaffolds() return False @@ -213,13 +213,15 @@ https://github.com/Pylons/?q=cookiecutter self.out('The package name "site" has a special meaning in ' 'Python. Are you sure you want to use it as your ' 'project\'s name?') - return self.confirm_bad_name('Really use "{0}"?: '.format(pkg_name)) + return self.confirm_bad_name('Really use "{0}"?: '.format( + pkg_name)) # check if pkg_name can be imported (i.e. already exists in current # $PYTHON_PATH, if so - let the user confirm pkg_exists = True try: - __import__(pkg_name, globals(), locals(), [], 0) # use absolute imports + # use absolute imports + __import__(pkg_name, globals(), locals(), [], 0) except ImportError as error: pkg_exists = False if not pkg_exists: @@ -231,7 +233,7 @@ https://github.com/Pylons/?q=cookiecutter 'to use it as your project\'s name?'.format(pkg_name)) return self.confirm_bad_name('Really use "{0}"?: '.format(pkg_name)) - def confirm_bad_name(self, prompt): # pragma: no cover + def confirm_bad_name(self, prompt): # pragma: no cover answer = input_('{0} [y|N]: '.format(prompt)) return answer.strip().lower() == 'y' @@ -242,5 +244,5 @@ cookiecutter instead: https://github.com/pylons/?query=cookiecutter ''') -if __name__ == '__main__': # pragma: no cover +if __name__ == '__main__': # pragma: no cover sys.exit(main() or 0) -- cgit v1.2.3