Skip to content

Commit

Permalink
feat: drop Python <3.8 (#683)
Browse files Browse the repository at this point in the history
* feat: drop Python <3.8

Signed-off-by: Henry Schreiner <[email protected]>

* ci: re-add caching

Signed-off-by: Henry Schreiner <[email protected]>

* ci: only cache on pypy

Signed-off-by: Henry Schreiner <[email protected]>

---------

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored May 20, 2024
1 parent f2f6ee6 commit e35f2fd
Show file tree
Hide file tree
Showing 79 changed files with 225 additions and 148 deletions.
32 changes: 0 additions & 32 deletions .github/matchers/pylint.json

This file was deleted.

35 changes: 17 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,23 @@ jobs:
python-version: "3.x"
- uses: pre-commit/[email protected]
- name: pylint
run: |
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
pipx run --python python nox -s pylint
run: pipx run --python python nox -s pylint -- --output-format=github

tests:
name: Tests on 🐍 ${{ matrix.python-version }} ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.6", "3.8", "3.11", "3.12"]
python-version: ["3.8", "3.10", "3.12"]
os: [ubuntu-latest, windows-latest, macos-13]
include:
- python-version: 'pypy-3.8'
os: ubuntu-latest
- python-version: 'pypy-3.10'
os: ubuntu-latest
- python-version: '3.6'
os: ubuntu-20.04
exclude:
- python-version: '3.6'
- python-version: '3.9'
os: ubuntu-latest
- python-version: '3.13'
os: ubuntu-latest
runs-on: ${{ matrix.os }}

Expand All @@ -60,19 +57,21 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- uses: actions/cache@v4
if: runner.os == 'Linux' && startsWith(matrix.python-version, 'pypy')
- name: Setup uv (uncached)
uses: yezz123/setup-uv@v4
if: "!startsWith(matrix.python-version, 'pypy')"

- name: Setup uv (cached)
uses: hynek/setup-cached-uv@v1
if: "startsWith(matrix.python-version, 'pypy')"
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('setup.cfg') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pip-
cache-suffix: -${{ matrix.python-version }}

- name: Install
run: |
pip install wheel coveralls pytest-github-actions-annotate-failures
pip install -e .[dev]
uv pip install --system -e.[test] pytest-github-actions-annotate-failures --reinstall-package plumbum
- name: Setup SSH tests
if: runner.os != 'Windows'
Expand All @@ -92,15 +91,15 @@ jobs:
run: pytest --cov --run-optional-tests=ssh,sudo

- name: Upload coverage
run: coveralls --service=github
run: pipx run coveralls --service=github
env:
COVERALLS_PARALLEL: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: test-${{ matrix.os }}-${{ matrix.python-version }}

coverage:
needs: [tests]
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions examples/SimpleColorCLI.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from plumbum import cli, colors

# from plumbum.colorlib import HTMLStyle, StyleFactory
Expand Down
2 changes: 2 additions & 0 deletions examples/alignment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
from __future__ import annotations

from plumbum import cli


Expand Down
1 change: 1 addition & 0 deletions examples/color.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from __future__ import annotations

from plumbum import colors

Expand Down
2 changes: 2 additions & 0 deletions examples/filecopy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
from __future__ import annotations

import logging

from plumbum import cli, local
Expand Down
1 change: 1 addition & 0 deletions examples/fullcolor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from __future__ import annotations

from plumbum import colors

Expand Down
2 changes: 2 additions & 0 deletions examples/geet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
committing...
"""

from __future__ import annotations

try:
import colorama

Expand Down
1 change: 1 addition & 0 deletions examples/make_figures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from __future__ import annotations

from plumbum import FG, cli, local
from plumbum.cmd import convert, pdflatex
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
Compiling: ('x.cpp', 'y.cpp', 'z.cpp')
"""

from __future__ import annotations

import logging

from plumbum import cli
Expand Down
2 changes: 2 additions & 0 deletions experiments/parallel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from plumbum.commands.base import BaseCommand
from plumbum.commands.processes import CommandNotFound, ProcessExecutionError, run_proc

Expand Down
2 changes: 2 additions & 0 deletions experiments/test_parallel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import unittest

from parallel import Cluster
Expand Down
10 changes: 6 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import nox

ALL_PYTHONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
ALL_PYTHONS = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

nox.options.sessions = ["lint", "tests"]
nox.needs_version = ">=2024.3.2"
nox.options.sessions = ["lint", "pylint", "tests"]
nox.options.default_venv_backend = "uv|virtualenv"


@nox.session(reuse_venv=True)
Expand All @@ -22,7 +24,7 @@ def pylint(session):
Run pylint.
"""

session.install(".", "paramiko", "ipython", "pylint~=3.1.0")
session.install(".", "paramiko", "ipython", "pylint")
session.run("pylint", "plumbum", *session.posargs)


Expand All @@ -31,7 +33,7 @@ def tests(session):
"""
Run the unit and regular tests.
"""
session.install("-e", ".[dev]")
session.install("-e", ".[test]")
session.run("pytest", *session.posargs, env={"PYTHONTRACEMALLOC": "5"})


Expand Down
32 changes: 2 additions & 30 deletions plumbum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
See https://plumbum.readthedocs.io for full details
"""

import sys
from __future__ import annotations

# Avoids a circular import error later
import plumbum.path # noqa: F401
Expand Down Expand Up @@ -83,35 +83,7 @@
"cmd",
)

# ===================================================================================================
# Module hack: ``from plumbum.cmd import ls``
# Can be replaced by a real module with __getattr__ after Python 3.6 is dropped
# ===================================================================================================


if sys.version_info < (3, 7): # noqa: UP036
from types import ModuleType
from typing import List

class LocalModule(ModuleType):
"""The module-hack that allows us to use ``from plumbum.cmd import some_program``"""

__all__ = () # to make help() happy
__package__ = __name__

def __getattr__(self, name):
try:
return local[name]
except CommandNotFound:
raise AttributeError(name) from None

__path__: List[str] = []
__file__ = __file__

cmd = LocalModule(__name__ + ".cmd", LocalModule.__doc__)
sys.modules[cmd.__name__] = cmd
else:
from . import cmd
from . import cmd


def __dir__():
Expand Down
2 changes: 2 additions & 0 deletions plumbum/_testtools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import platform
import sys
Expand Down
2 changes: 2 additions & 0 deletions plumbum/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .application import Application
from .config import Config, ConfigINI
from .switches import (
Expand Down
2 changes: 2 additions & 0 deletions plumbum/cli/application.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import functools
import inspect
import os
Expand Down
2 changes: 2 additions & 0 deletions plumbum/cli/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import contextlib
from abc import ABC, abstractmethod
from configparser import ConfigParser, NoOptionError, NoSectionError
Expand Down
2 changes: 2 additions & 0 deletions plumbum/cli/i18n.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import locale

# High performance method for English (no translation needed)
Expand Down
2 changes: 2 additions & 0 deletions plumbum/cli/image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys

from plumbum import colors
Expand Down
2 changes: 2 additions & 0 deletions plumbum/cli/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
------------
"""

from __future__ import annotations

import datetime
import sys
import warnings
Expand Down
12 changes: 7 additions & 5 deletions plumbum/cli/switches.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import collections.abc
import contextlib
import inspect
from abc import ABC, abstractmethod
from typing import Callable, Generator, List, Union
from typing import Callable, Generator

from plumbum import local
from plumbum.cli.i18n import get_translation_for
Expand Down Expand Up @@ -464,10 +466,10 @@ class MyApp(Application):

def __init__(
self,
*values: Union[str, Callable[[str], str]],
*values: str | Callable[[str], str],
case_sensitive: bool = False,
csv: Union[bool, str] = False,
all_markers: "collections.abc.Set[str]" = frozenset(),
csv: bool | str = False,
all_markers: collections.abc.Set[str] = frozenset(),
) -> None:
self.case_sensitive = case_sensitive
if isinstance(csv, bool):
Expand Down Expand Up @@ -501,7 +503,7 @@ def _call_iter(
with contextlib.suppress(ValueError):
yield opt(value)

def __call__(self, value: str, check_csv: bool = True) -> Union[str, List[str]]:
def __call__(self, value: str, check_csv: bool = True) -> str | list[str]:
items = list(self._call_iter(value, check_csv))
if not items:
msg = f"Invalid value: {value} (Expected one of {self.values})"
Expand Down
7 changes: 4 additions & 3 deletions plumbum/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
--------------------------
"""

from __future__ import annotations

import contextlib
import os
import sys
from typing import List, Optional

from plumbum import local

Expand All @@ -24,7 +25,7 @@
]


def __dir__() -> List[str]:
def __dir__() -> list[str]:
return __all__


Expand All @@ -35,7 +36,7 @@ def readline(message: str = "") -> str:
return sys.stdin.readline()


def ask(question: str, default: Optional[bool] = None) -> bool:
def ask(question: str, default: bool | None = None) -> bool:
"""
Presents the user with a yes/no question.
Expand Down
Loading

0 comments on commit e35f2fd

Please sign in to comment.