Skip to content

Run isort and black #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions rethinkdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import imp
import os

import pkg_resources

from rethinkdb import errors, version


# The builtins here defends against re-importing something obscuring `object`.
try:
import __builtin__ as builtins # Python 2
except ImportError:
import builtins # Python 3


__all__ = ['RethinkDB'] + errors.__all__
__all__ = ["RethinkDB"] + errors.__all__
__version__ = version.VERSION


Expand All @@ -41,7 +41,7 @@ def __init__(self):
_restore,
ast,
query,
net
net,
)

self._dump = _dump
Expand All @@ -65,15 +65,17 @@ def set_loop_type(self, library=None):

# find module file
manager = pkg_resources.ResourceManager()
libPath = '%(library)s_net/net_%(library)s.py' % {'library': library}
libPath = "%(library)s_net/net_%(library)s.py" % {"library": library}
if not manager.resource_exists(__name__, libPath):
raise ValueError('Unknown loop type: %r' % library)
raise ValueError("Unknown loop type: %r" % library)

# load the module
modulePath = manager.resource_filename(__name__, libPath)
moduleName = 'net_%s' % library
moduleFile, pathName, desc = imp.find_module(moduleName, [os.path.dirname(modulePath)])
module = imp.load_module('rethinkdb.' + moduleName, moduleFile, pathName, desc)
moduleName = "net_%s" % library
moduleFile, pathName, desc = imp.find_module(
moduleName, [os.path.dirname(modulePath)]
)
module = imp.load_module("rethinkdb." + moduleName, moduleFile, pathName, desc)

# set the connection type
self.connection_type = module.Connection
Expand Down
73 changes: 46 additions & 27 deletions rethinkdb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

'''Dispatcher for interactive functions such as repl and backup'''
"""Dispatcher for interactive functions such as repl and backup"""

import code
import sys
Expand All @@ -27,68 +27,87 @@


def startInterpreter(argv=None, prog=None):
repl_variables = {'r': net.Connection._r, 'rethinkdb': net.Connection._r}
banner = 'The RethinkDB driver has been imported as `r`.'
repl_variables = {"r": net.Connection._r, "rethinkdb": net.Connection._r}
banner = "The RethinkDB driver has been imported as `r`."

# -- get host/port setup

# - parse command line
parser = utils_common.CommonOptionsParser(
prog=prog, description='An interactive Python shell (repl) with the RethinkDB driver imported')
options, args = parser.parse_args(argv if argv is not None else sys.argv[1:], connect=False)
prog=prog,
description="An interactive Python shell (repl) with the RethinkDB driver imported",
)
options, args = parser.parse_args(
argv if argv is not None else sys.argv[1:], connect=False
)

if args:
parser.error('No positional arguments supported. Unrecognized option(s): %s' % args)
parser.error(
"No positional arguments supported. Unrecognized option(s): %s" % args
)

# -- open connection

try:
repl_variables['conn'] = options.retryQuery.conn()
repl_variables['conn'].repl()
banner += '''
repl_variables["conn"] = options.retryQuery.conn()
repl_variables["conn"].repl()
banner += """
A connection to %s:%d has been established as `conn`
and can be used by calling `run()` on a query without any arguments.''' % (options.hostname, options.driver_port)
and can be used by calling `run()` on a query without any arguments.""" % (
options.hostname,
options.driver_port,
)
except errors.ReqlDriverError as e:
banner += '\nWarning: %s' % str(e)
banner += "\nWarning: %s" % str(e)
if options.debug:
banner += '\n' + traceback.format_exc()
banner += "\n" + traceback.format_exc()

# -- start interpreter

code.interact(banner=banner + '\n==========', local=repl_variables)
code.interact(banner=banner + "\n==========", local=repl_variables)


if __name__ == '__main__':
if __name__ == "__main__":
if __package__ is None:
__package__ = 'rethinkdb'
__package__ = "rethinkdb"

# -- figure out which mode we are in
modes = ['dump', 'export', 'import', 'index_rebuild', 'repl', 'restore']
modes = ["dump", "export", "import", "index_rebuild", "repl", "restore"]

if len(sys.argv) < 2 or sys.argv[1] not in modes:
sys.exit('ERROR: Must be called with one of the following verbs: %s' % ', '.join(modes))
sys.exit(
"ERROR: Must be called with one of the following verbs: %s"
% ", ".join(modes)
)

verb = sys.argv[1]
prog = 'python -m rethinkdb'
if sys.version_info < (2, 7) or (sys.version_info >= (3, 0) and sys.version_info < (3, 4)):
prog += '.__main__' # Python versions 2.6, 3.0, 3.1 and 3.3 do not support running packages
prog += ' ' + verb
prog = "python -m rethinkdb"
if sys.version_info < (2, 7) or (
sys.version_info >= (3, 0) and sys.version_info < (3, 4)
):
prog += ".__main__" # Python versions 2.6, 3.0, 3.1 and 3.3 do not support running packages
prog += " " + verb
argv = sys.argv[2:]

if verb == 'dump':
if verb == "dump":
from . import _dump

exit(_dump.main(argv, prog=prog))
elif verb == 'export':
elif verb == "export":
from . import _export

exit(_export.main(argv, prog=prog))
elif verb == 'import':
elif verb == "import":
from . import _import

exit(_import.main(argv, prog=prog))
elif verb == 'index_rebuild':
elif verb == "index_rebuild":
from . import _index_rebuild

exit(_index_rebuild.main(argv, prog=prog))
elif verb == 'repl':
elif verb == "repl":
startInterpreter(argv, prog=prog)
elif verb == 'restore':
elif verb == "restore":
from . import _restore

exit(_restore.main(argv, prog=prog))
Loading