Skip to content
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

Move plumbum.cmd hack into __init__.py #45

Merged
merged 1 commit into from
Nov 10, 2012
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
18 changes: 18 additions & 0 deletions plumbum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

See http://plumbum.readthedocs.org for full details
"""
import sys
from types import ModuleType

from plumbum.commands import FG, BG, ERROUT
from plumbum.commands import ProcessExecutionError, CommandNotFound, ProcessTimedOut
from plumbum.path import Path
Expand All @@ -43,3 +46,18 @@

__author__ = "Tomer Filiba ([email protected])"

#===================================================================================================
# Module hack: ``from plumbum.cmd import ls``
#===================================================================================================
class LocalModule(ModuleType):
"""The module-hack that allows us to use ``from plumbum.cmd import some_program``"""
__file__ = None
__package__ = __name__
__getattr__ = local.__getitem__

cmd = LocalModule(__name__ + ".cmd")
sys.modules[cmd.__name__] = cmd

del sys
del ModuleType
del LocalModule
16 changes: 0 additions & 16 deletions plumbum/local_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from tempfile import mkdtemp
from subprocess import Popen, PIPE
from contextlib import contextmanager
from types import ModuleType

from plumbum.path import Path, FSUser
from plumbum.remote_path import RemotePath
Expand Down Expand Up @@ -583,18 +582,3 @@ def tempdir(self):
* ``env`` - the local environment
* ``encoding`` - the local machine's default encoding (``sys.getfilesystemencoding()``)
"""

#===================================================================================================
# Module hack: ``from plumbum.cmd import ls``
#===================================================================================================
class LocalModule(ModuleType):
"""The module-hack that allows us to use ``from plumbum.cmd import some_program``"""
def __init__(self, name):
ModuleType.__init__(self, name, __doc__)
self.__file__ = None
self.__package__ = ".".join(name.split(".")[:-1])
def __getattr__(self, name):
return local[name]

LocalModule = LocalModule("plumbum.cmd")
sys.modules[LocalModule.__name__] = LocalModule