Skip to content

Commit

Permalink
chore: remove setdoc (not needed in Py3) (#577)
Browse files Browse the repository at this point in the history
* chore: remove setdoc (not needed in Py3)

* chore: minor Python 2 cleanup
  • Loading branch information
henryiii committed Jan 27, 2022
1 parent bd29e7f commit e6fe1a9
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 128 deletions.
3 changes: 1 addition & 2 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ pass the validators in the decorator matching the names in the main function. Fo
def main(self, infile, *outfiles):
"infile is a path, outfiles are a list of paths, proper errors are given"

If you only want to run your application in Python 3, you can also use annotations to
specify the validators. For example::
You can also use annotations to specify the validators. For example::

class MyApp(cli.Application):
def main(self, infile : cli.ExistingFile, *outfiles : cli.NonexistentPath):
Expand Down
5 changes: 0 additions & 5 deletions plumbum/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from configparser import ConfigParser, NoOptionError, NoSectionError

from plumbum import local
from plumbum.lib import _setdoc


class ConfigBase(ABC):
Expand Down Expand Up @@ -85,12 +84,10 @@ def __init__(self, filename):
super().__init__(filename)
self.parser = ConfigParser()

@_setdoc(ConfigBase)
def read(self):
self.parser.read(self.filename)
super().read()

@_setdoc(ConfigBase)
def write(self):
with open(self.filename, "w") as f:
self.parser.write(f)
Expand All @@ -104,7 +101,6 @@ def _sec_opt(cls, option):
sec, option = option.split(".", 1)
return sec, option

@_setdoc(ConfigBase)
def _get(self, option):
sec, option = self._sec_opt(option)

Expand All @@ -113,7 +109,6 @@ def _get(self, option):
except (NoSectionError, NoOptionError):
raise KeyError(f"{sec}:{option}")

@_setdoc(ConfigBase)
def _set(self, option, value):
sec, option = self._sec_opt(option)
try:
Expand Down
11 changes: 0 additions & 11 deletions plumbum/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
IS_WIN32 = sys.platform == "win32"


def _setdoc(super): # @ReservedAssignment
"""This inherits the docs on the current class. Not really needed for Python 3.5,
due to new behavior of inspect.getdoc, but still doesn't hurt."""

def deco(func):
func.__doc__ = getattr(getattr(super, func.__name__, None), "__doc__", None)
return func

return deco


class ProcInfo:
def __init__(self, pid, uid, stat, args):
self.pid = pid
Expand Down
5 changes: 0 additions & 5 deletions plumbum/machines/paramiko_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from plumbum.commands.base import shquote
from plumbum.commands.processes import ProcessLineTimedOut, iter_lines
from plumbum.lib import _setdoc
from plumbum.machines.base import PopenAddons
from plumbum.machines.remote import BaseRemoteMachine
from plumbum.machines.session import ShellSession
Expand Down Expand Up @@ -286,7 +285,6 @@ def sftp(self):
self._sftp = self._client.open_sftp()
return self._sftp

@_setdoc(BaseRemoteMachine)
def session(
self, isatty=False, term="vt100", width=80, height=24, new_session=False
):
Expand All @@ -304,7 +302,6 @@ def session(
proc = ParamikoPopen(["<shell>"], stdin, stdout, stderr, self.custom_encoding)
return ShellSession(proc, self.custom_encoding, isatty)

@_setdoc(BaseRemoteMachine)
def popen(
self,
args,
Expand Down Expand Up @@ -339,7 +336,6 @@ def popen(
stderr_file=stderr,
)

@_setdoc(BaseRemoteMachine)
def download(self, src, dst):
if isinstance(src, LocalPath):
raise TypeError(f"src of download cannot be {src!r}")
Expand All @@ -363,7 +359,6 @@ def _download(self, src, dst):
else:
self.sftp.get(str(src), str(dst))

@_setdoc(BaseRemoteMachine)
def upload(self, src, dst):
if isinstance(src, RemotePath):
raise TypeError(f"src of upload cannot be {src!r}")
Expand Down
8 changes: 1 addition & 7 deletions plumbum/machines/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tempfile import NamedTemporaryFile

from plumbum.commands import CommandNotFound, ConcreteCommand, shquote
from plumbum.lib import ProcInfo, _setdoc
from plumbum.lib import ProcInfo
from plumbum.machines.base import BaseMachine
from plumbum.machines.env import BaseEnv
from plumbum.machines.local import LocalPath
Expand Down Expand Up @@ -39,22 +39,18 @@ def __init__(self, remote):
self._orig = self._curr.copy()
BaseEnv.__init__(self, self.remote.path, ":")

@_setdoc(BaseEnv)
def __delitem__(self, name):
BaseEnv.__delitem__(self, name)
self.remote._session.run(f"unset {name}")

@_setdoc(BaseEnv)
def __setitem__(self, name, value):
BaseEnv.__setitem__(self, name, value)
self.remote._session.run(f"export {name}={shquote(value)}")

@_setdoc(BaseEnv)
def pop(self, name, *default):
BaseEnv.pop(self, name, *default)
self.remote._session.run(f"unset {name}")

@_setdoc(BaseEnv)
def update(self, *args, **kwargs):
BaseEnv.update(self, *args, **kwargs)
self.remote._session.run(
Expand Down Expand Up @@ -435,11 +431,9 @@ def _path_link(self, src, dst, symlink):
"ln {} {} {}".format("-s" if symlink else "", shquote(src), shquote(dst))
)

@_setdoc(BaseEnv)
def expand(self, expr):
return self._session.run(f"echo {expr}")[1].strip()

@_setdoc(BaseEnv)
def expanduser(self, expr):
if not any(part.startswith("~") for part in expr.split("/")):
return expr
Expand Down
7 changes: 1 addition & 6 deletions plumbum/machines/ssh_machine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings

from plumbum.commands import ProcessExecutionError, shquote
from plumbum.lib import IS_WIN32, _setdoc
from plumbum.lib import IS_WIN32
from plumbum.machines.local import local
from plumbum.machines.remote import BaseRemoteMachine
from plumbum.machines.session import ShellSession
Expand Down Expand Up @@ -131,7 +131,6 @@ def __init__(
def __str__(self):
return f"ssh://{self._fqhost}"

@_setdoc(BaseRemoteMachine)
def popen(self, args, ssh_opts=(), env=None, cwd=None, **kwargs):
cmdline = []
cmdline.extend(ssh_opts)
Expand Down Expand Up @@ -203,7 +202,6 @@ def daemonic_popen(self, command, cwd=".", stdout=None, stderr=None, append=True
proc.stdout.close()
proc.stderr.close()

@_setdoc(BaseRemoteMachine)
def session(self, isatty=False, new_session=False):
return ShellSession(
self.popen(
Expand Down Expand Up @@ -299,7 +297,6 @@ def _translate_drive_letter(self, path):
path = "/" + path.replace(":", "").replace("\\", "/")
return path

@_setdoc(BaseRemoteMachine)
def download(self, src, dst):
if isinstance(src, LocalPath):
raise TypeError(f"src of download cannot be {src!r}")
Expand All @@ -312,7 +309,6 @@ def download(self, src, dst):
dst = self._translate_drive_letter(dst)
self._scp_command(f"{self._fqhost}:{shquote(src)}", dst)

@_setdoc(BaseRemoteMachine)
def upload(self, src, dst):
if isinstance(src, RemotePath):
raise TypeError(f"src of upload cannot be {src!r}")
Expand Down Expand Up @@ -382,7 +378,6 @@ def _translate_drive_letter(self, path):
# pscp takes care of windows paths automatically
return path

@_setdoc(BaseRemoteMachine)
def session(self, isatty=False, new_session=False):
return ShellSession(
self.popen((), (["-t"] if isatty else ["-T"]), new_session=new_session),
Expand Down
8 changes: 2 additions & 6 deletions plumbum/path/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ def __hash__(self):
else:
return hash(str(self).lower())

def __nonzero__(self):
def __bool__(self):
return bool(str(self))

__bool__ = __nonzero__

def __fspath__(self):
"""Added for Python 3.6 support"""
return str(self)
Expand Down Expand Up @@ -478,11 +476,9 @@ def __le__(self, other):
def __hash__(self):
return hash(str(self))

def __nonzero__(self):
def __bool__(self):
return bool(str(self))

__bool__ = __nonzero__

def up(self, count=1):
return RelativePath(self.parts[:-count])

Expand Down
Loading

0 comments on commit e6fe1a9

Please sign in to comment.