Skip to content

Commit a448192

Browse files
committed
Merge remote-tracking branch 'origin/master' into autocompleter
Updated AutoCompleter (#349) to match new directory structure from packaging effort.
2 parents 93cc246 + 01e4341 commit a448192

16 files changed

Lines changed: 60 additions & 73 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ This bit is up to you!
236236
#### How to find the code in the cmd2 codebase to fix/edit?
237237

238238
The cmd2 project directory structure is pretty simple and straightforward. All actual code for cmd2
239-
is located in a single file, `cmd2.py`. The code to generate the documentation is in the `docs` directory. Unit tests are in the `tests` directory. The `examples` directory contains examples of how
239+
is located underneath the `cmd2` directory. The code to generate the documentation is in the `docs` directory. Unit tests are in the `tests` directory. The `examples` directory contains examples of how
240240
to use cmd2. There are various other files in the root directory, but these are primarily related to
241241
continuous integration and to release deployment.
242242

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re as _re
44
import sys
55
from argparse import OPTIONAL, ZERO_OR_MORE, ONE_OR_MORE, REMAINDER, PARSER, ArgumentError, _
6-
from rl_utils import rl_force_redisplay
6+
from .rl_utils import rl_force_redisplay
77
try:
88
from typing import List, Dict, Tuple, Callable, Union
99
except:

cmd2/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# -*- coding: utf-8 -*-
3+
#
4+
from .cmd2 import __version__, Cmd, set_posix_shlex, set_strip_quotes, AddSubmenu, CmdResult, categorize
5+
from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category

cmd2.py renamed to cmd2/cmd2.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import pyperclip
5050

5151
# Set up readline
52-
from rl_utils import rl_force_redisplay, readline, rl_type, RlType
52+
from .rl_utils import rl_force_redisplay, readline, rl_type, RlType
5353

5454
if rl_type == RlType.PYREADLINE:
5555

@@ -70,13 +70,6 @@
7070
rl_basic_quote_characters = ctypes.c_char_p.in_dll(readline_lib, "rl_basic_quote_characters")
7171
orig_rl_basic_quote_characters_addr = ctypes.cast(rl_basic_quote_characters, ctypes.c_void_p).value
7272

73-
# Newer versions of pyperclip are released as a single file, but older versions had a more complicated structure
74-
try:
75-
from pyperclip.exceptions import PyperclipException
76-
except ImportError:
77-
# noinspection PyUnresolvedReferences
78-
from pyperclip import PyperclipException
79-
8073
# Collection is a container that is sizable and iterable
8174
# It was introduced in Python 3.6. We will try to import it, otherwise use our implementation
8275
try:
@@ -351,6 +344,12 @@ def cmd_wrapper(instance, cmdline):
351344
can_clip = True
352345

353346

347+
def disable_clip():
348+
""" Allows user of cmd2 to manually disable clipboard cut-and-paste functionality."""
349+
global can_clip
350+
can_clip = False
351+
352+
354353
def get_paste_buffer():
355354
"""Get the contents of the clipboard / paste buffer.
356355
File renamed without changes.

docs/install.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ This will also install the required 3rd-party dependencies.
8888
Deploy cmd2.py with your project
8989
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9090

91-
``cmd2`` is contained in only one Python file (**cmd2.py**), so it can be easily copied into your project. *The
91+
``cmd2`` is contained in a small number of Python files, which can be easily copied into your project. *The
9292
copyright and license notice must be retained*.
9393

94-
This is an option suitable for advanced Python users. You can simply include this file within your project's hierarchy.
94+
This is an option suitable for advanced Python users. You can simply include the files within your project's hierarchy.
9595
If you want to modify ``cmd2``, this may be a reasonable option. Though, we encourage you to use stock ``cmd2`` and
9696
either composition or inheritance to achieve the same goal.
9797

examples/tab_autocompletion.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"""A simple example demonstrating how to use flag and index based tab-completion functions
44
"""
55
import argparse
6-
import AutoCompleter
76
import itertools
87
from typing import List
98

109
import cmd2
11-
from cmd2 import with_argparser, with_category
10+
from cmd2 import with_argparser, with_category, AutoCompleter
1211

1312

1413
class TabCompleteExample(cmd2.Cmd):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
url='https://github.com/python-cmd2/cmd2',
9797
license='MIT',
9898
platforms=['any'],
99-
py_modules=["cmd2"],
99+
packages=['cmd2'],
100100
keywords='command prompt console cmd',
101101
install_requires=INSTALL_REQUIRES,
102102
extras_require=EXTRAS_REQUIRE,

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#
2+
# -*- coding: utf-8 -*-
3+
#
4+

tests/test_acargparse.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,8 @@
77
Copyright 2017 Todd Leonhardt <todd.leonhardt@gmail.com>
88
Released under MIT license, see LICENSE file
99
"""
10-
import argparse
11-
import os
12-
import sys
13-
14-
import cmd2
15-
from unittest import mock
1610
import pytest
17-
from AutoCompleter import ACArgumentParser
18-
19-
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
20-
try:
21-
import gnureadline as readline
22-
except ImportError:
23-
# Try to import readline, but allow failure for convenience in Windows unit testing
24-
# Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
25-
try:
26-
# noinspection PyUnresolvedReferences
27-
import readline
28-
except ImportError:
29-
pass
11+
from cmd2.AutoCompleter import ACArgumentParser
3012

3113

3214
def test_acarg_narg_empty_tuple():

0 commit comments

Comments
 (0)