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

add support for python 3.13 #599

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
sudo apt remove python3-pip
python -m pip install --upgrade pip
python -m pip install . ruff mypy pytest readme_renderer
python -m pip install .[dev]
pip list
- name: Type Checker
run: |
Expand All @@ -31,7 +31,7 @@ jobs:
ruff format --check .
- name: Run Tests
run: |
./tests/run_tests.py
pytest
- name: Validate README.md
# Ensure that the README renders correctly (required for uploading to PyPI).
run: |
Expand Down
2 changes: 1 addition & 1 deletion examples/asyncio-python-embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def print_counter() -> None:
Coroutine that prints counters and saves it in a global variable.
"""
while True:
print("Counter: %i" % counter[0])
print(f"Counter: {counter[0]}")
counter[0] += 1
await asyncio.sleep(3)

Expand Down
4 changes: 2 additions & 2 deletions examples/asyncio-ssh-python-embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ async def main(port: int = 8222) -> None:
def create_server() -> MySSHServer:
return MySSHServer(lambda: environ)

print("Listening on :%i" % port)
print('To connect, do "ssh localhost -p %i"' % port)
print(f"Listening on :{port}")
print(f'To connect, do "ssh localhost -p {port}"')

await asyncssh.create_server(
create_server, "", port, server_host_keys=["/etc/ssh/ssh_host_dsa_key"]
Expand Down
6 changes: 0 additions & 6 deletions mypy.ini

This file was deleted.

19 changes: 7 additions & 12 deletions ptpython/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def append_category(category: OptionCategory[Any]) -> None:
tokens.extend(
[
("class:sidebar", " "),
("class:sidebar.title", " %-36s" % category.title),
("class:sidebar.title", f" {category.title:36}"),
("class:sidebar", "\n"),
]
)
Expand All @@ -130,7 +130,7 @@ def goto_next(mouse_event: MouseEvent) -> None:
sel = ",selected" if selected else ""

tokens.append(("class:sidebar" + sel, " >" if selected else " "))
tokens.append(("class:sidebar.label" + sel, "%-24s" % label, select_item))
tokens.append(("class:sidebar.label" + sel, f"{label:24}", select_item))
tokens.append(("class:sidebar.status" + sel, " ", select_item))
tokens.append(("class:sidebar.status" + sel, f"{status}", goto_next))

Expand Down Expand Up @@ -332,7 +332,7 @@ def get_continuation(
width: int, line_number: int, is_soft_wrap: bool
) -> StyleAndTextTuples:
if python_input.show_line_numbers and not is_soft_wrap:
text = ("%i " % (line_number + 1)).rjust(width)
text = f"{line_number + 1} ".rjust(width)
return [("class:line-number", text)]
else:
return to_formatted_text(get_prompt_style().in2_prompt(width))
Expand Down Expand Up @@ -365,13 +365,9 @@ def get_text_fragments() -> StyleAndTextTuples:
append((TB, " "))

# Position in history.
append(
(
TB,
"%i/%i "
% (python_buffer.working_index + 1, len(python_buffer._working_lines)),
)
)
index = python_buffer.working_index + 1
lines = len(python_buffer._working_lines)
append((TB, f"{index}/{lines} "))

# Shortcuts.
app = get_app()
Expand Down Expand Up @@ -492,8 +488,7 @@ def toggle_sidebar(mouse_event: MouseEvent) -> None:
("class:status-toolbar", " - "),
(
"class:status-toolbar.python-version",
"%s %i.%i.%i"
% (platform.python_implementation(), version[0], version[1], version[2]),
f"{platform.python_implementation()} {version[0]}.{version[1]}.{version[2]}",
),
("class:status-toolbar", " "),
]
Expand Down
2 changes: 1 addition & 1 deletion ptpython/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ async def eval_async(self, line: str) -> object:

def _store_eval_result(self, result: object) -> None:
locals: dict[str, Any] = self.get_locals()
locals["_"] = locals["_%i" % self.current_statement_index] = result
locals["_"] = locals[f"_{self.current_statement_index}"] = result

def get_compiler_flags(self) -> int:
return super().get_compiler_flags() | PyCF_ALLOW_TOP_LEVEL_AWAIT
Expand Down
54 changes: 53 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
[project]
name = "ptpython"
version = "3.0.29"
description = "Python REPL build on top of prompt_toolkit"
readme = "README.rst"
authors = [{ name = "Jonathan Slenders" }]
classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python",
]
requires-python = ">=3.7"
dependencies = [
"appdirs",
"importlib_metadata;python_version<'3.8'",
"jedi>=0.16.0",
# Use prompt_toolkit 3.0.43, because of `OneStyleAndTextTuple` import.
"prompt_toolkit>=3.0.43,<3.1.0",
"pygments",
]
dynamic = ["scripts"]

[project.urls]
Homepage = "https://github.com/prompt-toolkit/ptpython"
Changelog = "https://github.com/prompt-toolkit/ptpython/blob/master/CHANGELOG"
"Bug Tracker" = "https://github.com/prompt-toolkit/ptpython/issues"
"Source Code" = "https://github.com/prompt-toolkit/ptpython"

[project.optional-dependencies]
ptipython = ["ipython"] # For ptipython, we need to have IPython
all = ["black"] # Black not always possible on PyPy
dev = ["mypy", "readme_renderer", "ruff", "pytest"]

[tool.mypy]
ignore_missing_imports = true
no_implicit_optional = true
platform = "win32"
strict_equality = true
strict_optional = true

[tool.ruff]
target-version = "py37"
lint.select = [
Expand Down Expand Up @@ -27,9 +75,13 @@ lint.ignore = [
"ptpython/ipython.py" = ["T100"] # Import usage.
"ptpython/repl.py" = ["T201"] # Print usage.
"ptpython/printer.py" = ["T201"] # Print usage.
"tests/run_tests.py" = ["F401"] # Unused imports.
"tests/test_todo.py" = ["F401"] # Unused imports.


[tool.ruff.lint.isort]
known-first-party = ["ptpython"]
known-third-party = ["prompt_toolkit", "pygments", "asyncssh"]

[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
41 changes: 0 additions & 41 deletions setup.cfg

This file was deleted.

51 changes: 2 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,8 @@
#!/usr/bin/env python
import os
import sys

from setuptools import find_packages, setup

with open(os.path.join(os.path.dirname(__file__), "README.rst")) as f:
long_description = f.read()

from setuptools import setup

setup(
name="ptpython",
author="Jonathan Slenders",
version="3.0.29",
url="https://github.com/prompt-toolkit/ptpython",
description="Python REPL build on top of prompt_toolkit",
long_description=long_description,
package_urls={
"Changelog": "https://github.com/prompt-toolkit/ptpython/blob/master/CHANGELOG",
},
project_urls={
"Bug Tracker": "https://github.com/prompt-toolkit/ptpython/issues",
"Source Code": "https://github.com/prompt-toolkit/ptpython",
"Changelog": "https://github.com/prompt-toolkit/ptpython/blob/master/CHANGELOG",
},
packages=find_packages("."),
package_data={"ptpython": ["py.typed"]},
install_requires=[
"appdirs",
"importlib_metadata;python_version<'3.8'",
"jedi>=0.16.0",
# Use prompt_toolkit 3.0.43, because of `OneStyleAndTextTuple` import.
"prompt_toolkit>=3.0.43,<3.1.0",
"pygments",
],
python_requires=">=3.7",
classifiers=[
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python",
],
entry_points={
"console_scripts": [
"ptpython = ptpython.entry_points.run_ptpython:run",
Expand All @@ -59,9 +16,5 @@
*sys.version_info[:2]
),
]
},
extras_require={
"ptipython": ["ipython"], # For ptipython, we need to have IPython
"all": ["black"], # Black not always possible on PyPy
},
}
)
9 changes: 3 additions & 6 deletions tests/run_tests.py → tests/test_todo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env python
from __future__ import annotations

import unittest

import ptpython.completer
import ptpython.eventloop
import ptpython.filters
Expand All @@ -16,9 +13,9 @@
import ptpython.validator

# For now there are no tests here.
# However this is sufficient for Travis to do at least a syntax check.
# However this is sufficient to do at least a syntax check.
# That way we are at least sure to restrict to the Python 2.6 syntax.


if __name__ == "__main__":
unittest.main()
def test_todo():
pass