Commit 4873e177 by Sébastien Eustace

Add a Shell class

parent 99f62087
import os
from shellingham import detect_shell
from shellingham import ShellDetectionFailure
class Shell:
"""
Represents the current shell.
"""
_shell = None
def __init__(self, name, path): # type: (str, str) -> None
self._name = name
self._path = path
@property
def name(self): # type: () -> str
return self._name
@property
def path(self): # type: () -> str
return self._path
@classmethod
def get(cls): # type: () -> Shell
"""
Retrieve the current shell.
"""
if cls._shell is not None:
return cls._shell
try:
name, path = detect_shell(os.getpid())
except (RuntimeError, ShellDetectionFailure):
raise RuntimeError("Unable to detect the current shell.")
cls._shell = cls(name, path)
return cls._shell
def __repr__(self): # type: () -> str
return '{}("{}", "{}")'.format(self.__class__.__name__, self._name, self._path)
...@@ -34,6 +34,7 @@ pyparsing = "^2.2" ...@@ -34,6 +34,7 @@ pyparsing = "^2.2"
cachecontrol = { version = "^0.12.4", extras = ["filecache"] } cachecontrol = { version = "^0.12.4", extras = ["filecache"] }
pkginfo = "^1.4" pkginfo = "^1.4"
html5lib = "^1.0" html5lib = "^1.0"
shellingham = "^1.1"
# The typing module is not in the stdlib in Python 2.7 and 3.4 # The typing module is not in the stdlib in Python 2.7 and 3.4
typing = { version = "^3.6", python = "~2.7 || ~3.4" } typing = { version = "^3.6", python = "~2.7 || ~3.4" }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment