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

Drop support for Python 2, Python 3.6, and IPython 5 #248

Merged
merged 2 commits into from
Aug 14, 2022
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
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/python/black
rev: 20.8b1
rev: 22.6.0
hooks:
- id: black
exclude: docopt.py
language_version: python3
additional_dependencies:
# Python 2 shenanigans. Black v20-21 is not compatible
# with click 8. But Black v22 is not compatible with Python 2.
- "click<8"

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear==20.1.2; python_version >= "3.5"']
additional_dependencies: ['flake8-bugbear==20.1.2']
- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
additional_dependencies: [black==22.6.0]
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
---------

5.0.0 (unreleased)
******************

Support:

* Drop support for Python 2 (:issue:`202`), Python 3.6, and IPython 5.

4.4.0 (2022-08-14)
******************

Expand Down
18 changes: 8 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,35 @@

## Setting up for development

* Create and activate a new virtual environment
* `pip install -e '.[dev]'`
* (Optional but recommended) If you're using a Python 3.6 virtual
environment, install the pre-commit hooks, which will
format and lint your git staged files:

- Create and activate a new virtual environment
- `pip install -e '.[dev]'`
- (Optional but recommended) Install the pre-commit hooks, which will
format and lint your git staged files:

```
# The pre-commit CLI was installed above
pre-commit install
```

* To run tests:
- To run tests:

```
pytest
```

* To run syntax checks:
- To run syntax checks:

```
tox -e lint
```

* To build the docs:
- To build the docs:

```
tox -e watch-docs
```

* (Optional) To run tests on Python 2.7, 3.5, 3.6, and 3.7 virtual environments (must have each interpreter installed):
- (Optional) To run tests on all suported versions (must have each interpreter installed):

```
tox
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ With pip:
$ pip install doitlive


Requires Python >= 2.7 or >= 3.5 with pip.
Requires Python >= 3.7 with pip.

Quickstart
----------
Expand Down
28 changes: 9 additions & 19 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ trigger:
branches:
include: [dev, test-me-*]
tags:
include: ['*']
include: ["*"]

resources:
repositories:
Expand All @@ -16,21 +16,11 @@ variables:
CI: "true"

jobs:
- template: job--python-tox.yml@sloria
parameters:
toxenvs: [
lint,

py27-ipython5,

py36-ipython5,
py36-ipython6,

py310-ipython7,
py310-ipython8
]
os: linux
- template: job--pypi-release.yml@sloria
parameters:
dependsOn:
- tox_linux
- template: job--python-tox.yml@sloria
parameters:
toxenvs: [lint, py37-ipython6, py310-ipython7, py310-ipython8]
os: linux
- template: job--pypi-release.yml@sloria
parameters:
dependsOn:
- tox_linux
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys
import os
import datetime as dt
Expand All @@ -20,8 +19,8 @@
master_doc = "index"

# General information about the project.
project = u"doitlive"
copyright = u"2014-{0:%Y}".format(dt.datetime.utcnow())
project = "doitlive"
copyright = f"2014-{dt.datetime.utcnow():%Y}"

version = release = doitlive.__version__

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ With pip:
$ pip install doitlive


Requires Python >= 2.7 or >= 3.5 with pip.
Requires Python >= 3.7 with pip.

Quickstart
----------
Expand Down
1 change: 0 additions & 1 deletion doitlive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
doitlive
~~~~~~~~
Expand Down
35 changes: 14 additions & 21 deletions doitlive/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import functools
import os
import re
Expand All @@ -13,15 +12,14 @@
from click_didyoumean import DYMGroup

from doitlive.__version__ import __version__
from doitlive.compat import ensure_utf8
from doitlive.exceptions import SessionError
from doitlive.keyboard import (
RETURNS,
magicrun,
magictype,
regularrun,
run_command,
wait_for,
regularrun,
)
from doitlive.python_consoles import PythonRecorderConsole, start_python_player
from doitlive.styling import THEMES, echo, echo_prompt, format_prompt
Expand All @@ -43,15 +41,15 @@
def write_directives(fp, directive, args):
if args:
for arg in args:
line = "#doitlive {directive}: {arg}\n".format(directive=directive, arg=arg)
fp.write(ensure_utf8(line))
line = f"#doitlive {directive}: {arg}\n"
fp.write(line)
return None


class SessionState(dict):
"""Stores information about a fake terminal session."""

TRUTHY = set(["true", "yes", "1"])
TRUTHY = {"true", "yes", "1"}

def __init__(
self,
Expand Down Expand Up @@ -179,7 +177,7 @@ def run(
continue
is_comment = command.startswith("#")
if not is_comment:
command_as_list = shlex.split(ensure_utf8(command))
command_as_list = shlex.split(command)
else:
command_as_list = None
shell_match = SHELL_RE.match(command)
Expand Down Expand Up @@ -212,8 +210,7 @@ def run(
py_command = commands[i].rstrip()
except IndexError:
raise SessionError(
"Unmatched {0} code block in "
"session file.".format(shell_name)
"Unmatched {} code block in " "session file.".format(shell_name)
)
i += 1
if py_command.startswith("```"):
Expand Down Expand Up @@ -276,7 +273,7 @@ def preview_themes():
secho("Theme previews:", bold=True)
echo()
for name, template in THEMES.items():
echo('"{}" theme:'.format(name))
echo(f'"{name}" theme:')
echo(format_prompt(template), nl=False)
echo(" command arg1 arg2 ... argn")
echo()
Expand Down Expand Up @@ -480,9 +477,7 @@ def run_recorder(shell, prompt, aliases=None, envvars=None):
elif command == PREVIEW_COMMAND:
echo_rec_buffer(commands)
elif command == UNDO_COMMAND:
if commands and click.confirm(
'Remove command? "{}"'.format(commands[-1].strip())
):
if commands and click.confirm(f'Remove command? "{commands[-1].strip()}"'):
commands.pop()
secho("Removed command.", bold=True)
echo_rec_buffer(commands)
Expand Down Expand Up @@ -512,9 +507,7 @@ def print_recorder_instructions():
echo()
echo("INSTRUCTIONS:")
echo(
"Enter "
+ style("{}".format(STOP_COMMAND), bold=True)
+ " when you are done recording."
"Enter " + style(f"{STOP_COMMAND}", bold=True) + " when you are done recording."
)
echo(
"To preview the commands in the buffer, enter {}.".format(
Expand Down Expand Up @@ -547,14 +540,14 @@ def record(session_file, shell, prompt, alias, envvar):
"""
if os.path.exists(session_file):
click.confirm(
'File "{0}" already exists. Overwrite?'.format(session_file),
f'File "{session_file}" already exists. Overwrite?',
abort=True,
default=False,
)

secho("We'll do it live!", fg="red", bold=True)
filename = click.format_filename(session_file)
secho("RECORDING SESSION: {}".format(filename), fg="yellow", bold=True)
secho(f"RECORDING SESSION: {filename}", fg="yellow", bold=True)

print_recorder_instructions()

Expand All @@ -568,7 +561,7 @@ def record(session_file, shell, prompt, alias, envvar):
os.chdir(cwd) # Reset cwd

secho("FINISHED RECORDING SESSION", fg="yellow", bold=True)
secho("Writing to {0}...".format(filename), fg="cyan")
secho(f"Writing to {filename}...", fg="cyan")
with open(session_file, "w", encoding="utf-8") as fp:
fp.write(HEADER_TEMPLATE.format(shell=shell, prompt=prompt))
write_directives(fp, "alias", alias)
Expand All @@ -577,8 +570,8 @@ def record(session_file, shell, prompt, alias, envvar):
fp.write("".join(commands))
fp.write("\n")

play_cmd = style("doitlive play {}".format(filename), bold=True)
echo("Done. Run {} to play back your session.".format(play_cmd))
play_cmd = style(f"doitlive play {filename}", bold=True)
echo(f"Done. Run {play_cmd} to play back your session.")


if __name__ == "__main__":
Expand Down
7 changes: 0 additions & 7 deletions doitlive/compat.py

This file was deleted.

6 changes: 2 additions & 4 deletions doitlive/ipython/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
"""doitlive IPython support."""
from __future__ import absolute_import, print_function

import itertools as it

Expand Down Expand Up @@ -46,7 +44,7 @@ def __init__(self, commands, speed=1, *args, **kwargs):
# Index of current character in current command
self.current_command_pos = 0

super(DoitliveTerminalInteractiveShell, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def next_keys(self, key_presses):
return list(
Expand Down Expand Up @@ -123,7 +121,7 @@ def interact(self):

# Override TerminalInteractiveShell
def init_prompt_toolkit_cli(self):
super(DoitliveTerminalInteractiveShell, self).init_prompt_toolkit_cli()
super().init_prompt_toolkit_cli()
self.pt_app.app.key_processor = DoitliveKeyProcessor(
wrapped_processor=self.pt_app.app.key_processor, next_keys=self.next_keys
)
Expand Down
16 changes: 5 additions & 11 deletions doitlive/ipython/legacy_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
"""doitlive IPython support."""
from __future__ import absolute_import, print_function

from warnings import warn

Expand All @@ -20,25 +18,21 @@

class _PlayerInterfaceEventLoopCallbacks(_InterfaceEventLoopCallbacks):
def __init__(self, cli, on_feed_key):
super(_PlayerInterfaceEventLoopCallbacks, self).__init__(cli)
super().__init__(cli)
self.on_feed_key = on_feed_key

# Override _InterfaceEventLoopCallbacks
def feed_key(self, key_press, *args, **kwargs):
key_press = self.on_feed_key(key_press)
if key_press is not None:
return super(_PlayerInterfaceEventLoopCallbacks, self).feed_key(
key_press, *args, **kwargs
)
return super().feed_key(key_press, *args, **kwargs)


class _PlayerCommandLineInterface(CommandLineInterface):
def __init__(
self, application, eventloop=None, input=None, output=None, on_feed_key=None
):
super(_PlayerCommandLineInterface, self).__init__(
application, eventloop, input, output
)
super().__init__(application, eventloop, input, output)
self.on_feed_key = on_feed_key

# Override CommandLineInterface
Expand All @@ -56,7 +50,7 @@ def __init__(self, commands, speed=1, *args, **kwargs):
self.current_command_index = 0
# Index of current character in current command
self.current_command_pos = 0
super(PlayerTerminalInteractiveShell, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def on_feed_key(self, key_press):
"""Handles the magictyping when a key is pressed"""
Expand Down Expand Up @@ -132,7 +126,7 @@ def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):

# Override TerminalInteractiveShell
def init_prompt_toolkit_cli(self):
super(PlayerTerminalInteractiveShell, self).init_prompt_toolkit_cli()
super().init_prompt_toolkit_cli()
# override CommandLineInterface
self.pt_cli = _PlayerCommandLineInterface(
self._pt_app,
Expand Down
Loading