Skip to content

Commit

Permalink
tests: include Python 3.10 (linux only) (#560)
Browse files Browse the repository at this point in the history
* tests: include Python 3.10

* chore: bump pre-commit and add some checks

* style: fix some flake8 suggestions

* style: improve mypy compliance a bit

* ci: only run linux 3.10 for now

* fix: restore pytest
  • Loading branch information
henryiii authored Oct 7, 2021
1 parent ab09c76 commit 731e7e0
Show file tree
Hide file tree
Showing 28 changed files with 228 additions and 138 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.5, 3.7, 3.9]
python-version: ["2.7", "3.5", "3.7", "3.9"]
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- python-version: 'pypy-2.7'
os: ubuntu-latest
- python-version: 'pypy-3.7'
os: ubuntu-latest
- python-version: '3.10'
os: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
Expand Down
28 changes: 19 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -17,39 +21,45 @@ repos:
- id: fix-encoding-pragma

- repo: https://github.com/psf/black
rev: 20.8b1
rev: "21.9b0"
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.7.0
rev: "5.9.3"
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v2.10.0
rev: "v2.29.0"
hooks:
- id: pyupgrade

- repo: https://github.com/asottile/setup-cfg-fmt
rev: "v1.18.0"
hooks:
- id: setup-cfg-fmt
args: [--min-py3-version=3.5]

- repo: https://github.com/pycqa/flake8
rev: 3.8.4
rev: "3.9.2"
hooks:
- id: flake8
exclude: docs/conf.py
additional_dependencies: [flake8-bugbear, flake8-print]
additional_dependencies: [flake8-bugbear, flake8-print, flake8-2020]
stages: [manual]


- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.800
rev: "v0.910-1"
hooks:
- id: mypy
files: plumbum
stages: [manual]
additional_dependencies: [typed-ast, types-paramiko]

# This wants the .mo files removed
- repo: https://github.com/mgedmin/check-manifest
rev: "0.46"
rev: "0.47"
hooks:
- id: check-manifest
stages: [manual]
31 changes: 30 additions & 1 deletion plumbum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"""

# Avoids a circular import error later
import plumbum.path
import plumbum.path # noqa: F401
from plumbum.commands import (
BG,
ERROUT,
Expand All @@ -58,6 +58,30 @@
__author__ = "Tomer Filiba ([email protected])"
__version__ = version

__all__ = (
"BG",
"ERROUT",
"FG",
"NOHUP",
"RETCODE",
"TEE",
"TF",
"CommandNotFound",
"ProcessExecutionError",
"ProcessLineTimedOut",
"ProcessTimedOut",
"BaseRemoteMachine",
"PuttyMachine",
"SshMachine",
"local",
"LocalPath",
"Path",
"RemotePath",
"__author__",
"__version__",
"cmd",
)

# ===================================================================================================
# Module hack: ``from plumbum.cmd import ls``
# ===================================================================================================
Expand Down Expand Up @@ -92,3 +116,8 @@ def __getattr__(self, name):
del sys
del ModuleType
del LocalModule


def __dir__():
"Support nice tab completion"
return __all__
20 changes: 20 additions & 0 deletions plumbum/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@
positional,
switch,
)

__all__ = (
"Application",
"Config",
"ConfigINI",
"CSV",
"CountOf",
"ExistingDirectory",
"ExistingFile",
"Flag",
"NonexistentPath",
"Predicate",
"Range",
"Set",
"SwitchAttr",
"SwitchError",
"autoswitch",
"positional",
"switch",
)
2 changes: 1 addition & 1 deletion plumbum/cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def _validate_args(self, swfuncs, tailargs):

ordered = [
(f, a)
for _, f, a in sorted([(sf.index, f, sf.val) for f, sf in swfuncs.items()])
for _, f, a in sorted((sf.index, f, sf.val) for f, sf in swfuncs.items())
]
return ordered, tailargs

Expand Down
10 changes: 5 additions & 5 deletions plumbum/cli/config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import division, print_function

import os
import sys
from abc import abstractmethod

from plumbum import local
from plumbum.lib import _setdoc, six

try:
from configparser import ConfigParser, NoOptionError, NoSectionError # Py3
except ImportError:
from ConfigParser import ConfigParser, NoOptionError, NoSectionError # type: ignore
if sys.version_info >= (3,):
from configparser import ConfigParser, NoOptionError, NoSectionError
else:
from ConfigParser import ConfigParser, NoOptionError, NoSectionError


class ConfigBase(six.ABC):
Expand Down
10 changes: 5 additions & 5 deletions plumbum/cli/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@ def __init__(self, *args, **kargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
try:
from ipywidgets import HTML, HBox, IntProgress # type: ignore
from ipywidgets import HTML, HBox, IntProgress
except ImportError: # Support IPython < 4.0
from IPython.html.widgets import HTML, HBox, IntProgress # type: ignore
from IPython.html.widgets import HTML, HBox, IntProgress

super(ProgressIPy, self).__init__(*args, **kargs)
self.prog = IntProgress(max=self.length)
self._label = HTML()
self._box = HBox((self.prog, self._label))

def start(self):
from IPython.display import display # type: ignore
from IPython.display import display

display(self._box)
super(ProgressIPy, self).start()
Expand Down Expand Up @@ -248,9 +248,9 @@ def __new__(cls, *args, **kargs):
try: # pragma: no cover
__IPYTHON__
try:
from traitlets import TraitError # type: ignore
from traitlets import TraitError
except ImportError: # Support for IPython < 4.0
from IPython.utils.traitlets import TraitError # type: ignore
from IPython.utils.traitlets import TraitError

try:
return ProgressIPy(*args, **kargs)
Expand Down
14 changes: 14 additions & 0 deletions plumbum/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
from .progress import Progress
from .termsize import get_terminal_size

__all__ = (
"readline",
"ask",
"choose",
"prompt",
"get_terminal_size",
"Progress",
"get_terminal_size",
)


def __dir__():
return __all__


def readline(message=""):
"""Gets a line of input from the user (stdin)"""
Expand Down
2 changes: 1 addition & 1 deletion plumbum/cli/termsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_terminal_size(default=(80, 25)):

def _get_terminal_size_windows(): # pragma: no cover
try:
from ctypes import create_string_buffer, windll # type: ignore
from ctypes import create_string_buffer, windll

STDERR_HANDLE = -12
h = windll.kernel32.GetStdHandle(STDERR_HANDLE)
Expand Down
14 changes: 7 additions & 7 deletions plumbum/colorlib/_ipython_ext.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
import IPython.display # type: ignore
from IPython.core.magic import magics_class # type: ignore; type: ignore
from IPython.core.magic import Magics, cell_magic, needs_local_scope
import sys

import IPython.display
from IPython.core.magic import Magics, cell_magic, magics_class, needs_local_scope

try:
if sys.version_info >= (3,):
from io import StringIO
except ImportError:
else:
try:
from cStringIO import StringIO # type: ignore
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO # type: ignore

import sys

valid_choices = [x[8:] for x in dir(IPython.display) if "display_" == x[:8]]

Expand Down
8 changes: 4 additions & 4 deletions plumbum/colorlib/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
from_html,
)

try:
if sys.version_info >= (3,):
from abc import ABC
except ImportError:
from abc import ABCMeta # type: ignore
else:
from abc import ABCMeta

ABC = ABCMeta(
"ABC", (object,), {"__module__": __name__, "__slots__": ("__weakref__")}
) # type: ignore
)

try:
from typing import IO, Dict, Union
Expand Down
25 changes: 25 additions & 0 deletions plumbum/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@
ProcessTimedOut,
run_proc,
)

__all__ = (
"BaseCommand",
"ConcreteCommand",
"shquote",
"shquote_list",
"ERROUT",
"BG",
"FG",
"NOHUP",
"RETCODE",
"TEE",
"TF",
"ExecutionModifier",
"Future",
"CommandNotFound",
"ProcessExecutionError",
"ProcessLineTimedOut",
"ProcessTimedOut",
"run_proc",
)


def __dir__():
return __all__
7 changes: 4 additions & 3 deletions plumbum/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def popen(self, args=(), **kwargs):
class BoundEnvCommand(BaseCommand):
__slots__ = ("cmd", "env", "cwd")

def __init__(self, cmd, env={}, cwd=None):
def __init__(self, cmd, env=None, cwd=None):
self.cmd = cmd
self.env = env
self.env = env or {}
self.cwd = cwd

def __repr__(self):
Expand All @@ -341,7 +341,8 @@ def formulate(self, level=0, args=()):
def machine(self):
return self.cmd.machine

def popen(self, args=(), cwd=None, env={}, **kwargs):
def popen(self, args=(), cwd=None, env=None, **kwargs):
env = env or {}
return self.cmd.popen(
args,
cwd=self.cwd if cwd is None else cwd,
Expand Down
2 changes: 1 addition & 1 deletion plumbum/commands/daemons.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def posix_daemonize(command, cwd, stdout=None, stderr=None, append=True):
stderr=stderr.fileno(),
)
os.write(wfd, str(proc.pid).encode("utf8"))
except:
except Exception:
rc = 1
tbtext = "".join(traceback.format_exception(*sys.exc_info()))[-MAX_SIZE:]
os.write(wfd, tbtext.encode("utf8"))
Expand Down
14 changes: 6 additions & 8 deletions plumbum/commands/processes.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# -*- coding: utf-8 -*-
import atexit
import heapq
import sys
import time
from threading import Thread

from plumbum.lib import IS_WIN32, six

try:
if sys.version_info >= (3,):
from io import StringIO
from queue import Empty as QueueEmpty
from queue import Queue
except ImportError:
from Queue import Empty as QueueEmpty # type: ignore
else:
from cStringIO import StringIO
from Queue import Empty as QueueEmpty
from Queue import Queue

try:
from io import StringIO
except ImportError:
from cStringIO import StringIO # type: ignore


# ===================================================================================================
# utility functions
Expand Down
Loading

0 comments on commit 731e7e0

Please sign in to comment.