Skip to content

Commit 97668f9

Browse files
committed
Restored legacy cmd/self access when locals_in_py is True. Changed default to False
1 parent 2528fb5 commit 97668f9

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See the [tab_autocompletion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_autocompletion.py) example for a demonstration of how to use this feature
55
* ``cmd2`` no longer depends on the ``six`` module
66
* ``cmd2`` is now a multi-file Python package instead of a single-file module
7+
* New pyscript approach that provides a pythonic interface to commands in the cmd2 application.
78
* Deletions (potentially breaking changes)
89
* Deleted all ``optparse`` code which had previously been deprecated in release 0.8.0
910
* The ``options`` decorator no longer exists
@@ -12,6 +13,7 @@
1213
* Alternatively, see the [argparse_example.py](https://github.com/python-cmd2/cmd2/blob/master/examples/argparse_example.py)
1314
* Deleted ``cmd_with_subs_completer``, ``get_subcommands``, and ``get_subcommand_completer``
1415
* Replaced by default AutoCompleter implementation for all commands using argparse
16+
* Deleted support for old method of calling application commands with ``cmd()`` and ``self``
1517
* Python 2 no longer supported
1618
* ``cmd2`` now supports Python 3.4+
1719

cmd2/cmd2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class Cmd(cmd.Cmd):
699699
if _which(editor):
700700
break
701701
feedback_to_output = False # Do not include nonessentials in >, | output by default (things like timing)
702-
locals_in_py = True
702+
locals_in_py = False
703703
quiet = False # Do not suppress nonessential output
704704
timing = False # Prints elapsed time for each command
705705

@@ -2907,7 +2907,11 @@ def onecmd_plus_hooks(cmd_plus_args):
29072907
self.pystate['run'] = run
29082908
self.pystate[self.pyscript_name] = bridge
29092909

2910-
localvars = (self.locals_in_py and self.pystate) or {}
2910+
if self.locals_in_py:
2911+
self.pystate['self'] = self
2912+
self.pystate['cmd'] = onecmd_plus_hooks
2913+
2914+
localvars = self.pystate
29112915
interp = InteractiveConsole(locals=localvars)
29122916
interp.runcode('import sys, os;sys.path.insert(0, os.getcwd())')
29132917

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
echo: False
9090
editor: vim
9191
feedback_to_output: False
92-
locals_in_py: True
92+
locals_in_py: False
9393
prompt: (Cmd)
9494
quiet: False
9595
timing: False
@@ -106,7 +106,7 @@
106106
echo: False # Echo command issued into output
107107
editor: vim # Program used by ``edit``
108108
feedback_to_output: False # Include nonessentials in `|`, `>` results
109-
locals_in_py: True # Allow access to your application in py via self
109+
locals_in_py: False # Allow access to your application in py via self
110110
prompt: (Cmd) # The prompt issued to solicit input
111111
quiet: False # Don't print nonessential feedback
112112
timing: False # Report execution times

tests/transcripts/regex_set.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ debug: False
1010
echo: False
1111
editor: /.*/
1212
feedback_to_output: False
13-
locals_in_py: True
13+
locals_in_py: False
1414
maxrepeats: 3
1515
prompt: (Cmd)/ /
1616
quiet: False

0 commit comments

Comments
 (0)