Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbarrett314 committed Apr 21, 2023
2 parents eccd784 + 2ef19bf commit c4c63a2
Show file tree
Hide file tree
Showing 22 changed files with 598 additions and 582 deletions.
12 changes: 0 additions & 12 deletions .flake8

This file was deleted.

44 changes: 19 additions & 25 deletions .github/workflows/lint-test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
on: [ push, pull_request, repository_dispatch ]
on:
push:
branches: [master, develop]
tags:
- '*'
pull_request:
workflow_dispatch:

name: Tests

Expand All @@ -17,23 +23,14 @@ jobs:
python-version: "3.11"
- uses: pre-commit/action@v3.0.0
env:
SKIP: "mypy,flake8,ruff,black"
SKIP: "mypy,ruff,black,poetry-lock"

black-format:
name: Check format with black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
flake8-lint:
runs-on: ubuntu-latest
name: Lint with flake8
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- uses: py-actions/flake8@v2
ruff-lint:
name: Lint with ruff
runs-on: ubuntu-latest
Expand Down Expand Up @@ -63,15 +60,20 @@ jobs:

test:
name: Pytest via poetry
needs:
- pre-commit
- black-format
- ruff-lint
- mypy

strategy:
matrix:
python-version: [ "3.10", "3.9","3.8", "3.7", "3.11", "pypy3.9" ]
python-version: ["3.11", "3.10", "3.9","3.8", "3.7", "pypy3.8", "pypy3.9", "3.12.0-alpha7" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
exclude:
- os: windows-latest
python-version: pypy3
continue-on-error: ${{ matrix.python-version == 'pypy3.9' && matrix.os == 'windows-latest' }}
continue-on-error: ${{ (matrix.python-version == 'pypy3.11' && matrix.os == 'windows-latest') || matrix.python-version == 'pypy3.8' || (matrix.python-version == 'pypy3.9' && matrix.os == 'windows-latest') || matrix.python-version=='3.12.0-alpha.4' }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -124,24 +126,16 @@ jobs:
name: Build and publish Python distributions to PyPI and TestPyPI
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
permissions:
id-token: write
needs:
- pre-commit
- black-format
- flake8-lint
- ruff-lint
- mypy
- test

steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'poetry'
- run: poetry --version
- run: poetry install
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.15
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
24 changes: 9 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.10
python: python3.11
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -22,7 +22,7 @@ repos:
- id: check-merge-conflict

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black

Expand All @@ -40,7 +40,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/pycqa/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort

Expand All @@ -56,19 +56,13 @@ repos:
# - id: pyupgrade
# args: [--py37-plus]

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.223
rev: v0.0.262
hooks:
- id: ruff
args: ["--force-exclude"]

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.2.3
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies:
Expand All @@ -81,19 +75,19 @@ repos:
- id: add-trailing-comma

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [ black==22.6.0 ]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.2.0
hooks:
- id: mypy
additional_dependencies: [ types-Deprecated ]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.289
rev: v1.1.304
hooks:
- id: pyright
additional_dependencies:
Expand All @@ -104,7 +98,7 @@ repos:
- importlib-metadata
- deprecated
- repo: https://github.com/python-poetry/poetry
rev: 1.3.0
rev: 1.4.0
hooks:
- id: poetry-check
- id: poetry-lock
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ formats:
build:
os: "ubuntu-22.04"
tools:
python: "3.10"
python: "3.11"
jobs:
post_create_environment:
# Install poetry
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 0.6.12
-------------
* Updating deployment workflow
* Various dependency and testing updates

Version 0.6.11
-------------
* Fix issue with calling stty
Expand Down
48 changes: 24 additions & 24 deletions cursesmenu/curses_menu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Top level class and functions for a curses-based menu."""

from __future__ import annotations

import atexit
import curses
import os
Expand All @@ -8,7 +10,7 @@
import threading
import time
from collections import defaultdict
from typing import TYPE_CHECKING, Any, Callable, DefaultDict, List, Optional, cast
from typing import TYPE_CHECKING, Any, cast

from deprecated import deprecated

Expand All @@ -17,6 +19,8 @@

if TYPE_CHECKING:
# noinspection PyCompatibility,PyProtectedMember
from typing import Callable, DefaultDict

from _curses import window

Window = window
Expand All @@ -28,6 +32,7 @@
MIN_SIZE = 6 # Top bar, space, title, space, subtitle, space, bottom bar

PROJECT_ROOT = pathlib.Path(__file__).parent.parent.absolute()
_SCREENDUMP_DIR = PROJECT_ROOT.joinpath("screendumps")


class CursesMenu:
Expand Down Expand Up @@ -63,8 +68,8 @@ class CursesMenu:
is currently active (E.G. when switching between menus)
"""

currently_active_menu: Optional["CursesMenu"] = None
stdscr: Optional[Window] = None
currently_active_menu: CursesMenu | None = None
stdscr: Window | None = None

def __init__(
self,
Expand All @@ -80,7 +85,7 @@ def __init__(
self.subtitle = subtitle
self.zero_pad = zero_pad

self.screen: Optional[Window] = None
self.screen: Window | None = None

# highlight should be initialized to black-on-white, but bold is a fine
# fallback that doesn't need the screen initialized first
Expand All @@ -106,7 +111,7 @@ def __init__(
# TODO: Should this be a property
self.returned_value = None

self.parent: Optional[CursesMenu] = None
self.parent: CursesMenu | None = None

self.user_input_handlers: DefaultDict[int, Callable[[int], None]] = defaultdict(
cursesmenu.utils.null_input_factory,
Expand Down Expand Up @@ -139,12 +144,12 @@ def __init__(
@classmethod
def make_selection_menu(
cls,
selections: List[str],
selections: list[str],
title: str = "",
subtitle: str = "",
*,
show_exit_item: bool = False,
) -> "CursesMenu":
) -> CursesMenu:
"""
Create a menu from a list of strings.
Expand All @@ -169,7 +174,7 @@ def make_selection_menu(
@classmethod
def get_selection(
cls,
selections: List[str],
selections: list[str],
title: str = "",
subtitle: str = "",
) -> int:
Expand All @@ -196,15 +201,15 @@ def all_items(self) -> ItemGroup:
return self.items + self.end_items

@property
def current_item(self) -> Optional[MenuItem]:
def current_item(self) -> MenuItem | None:
"""Get the currently selected MenuItem."""
if not self.all_items:
return None
else:
return self.all_items[self.current_option]

@property
def selected_item(self) -> Optional[MenuItem]:
def selected_item(self) -> MenuItem | None:
"""Get the most recently selected MenuItem."""
if self.selected_option == -1:
return None
Expand Down Expand Up @@ -262,7 +267,7 @@ def _wrap_start(self) -> None:
# noinspection PyBroadException
try: # noqa: SIM105
curses.start_color()
except: # noqa: E722 # pragma: no cover all
except: # noqa: E722,S110 # pragma: no cover all
pass
self._main_loop()
finally:
Expand Down Expand Up @@ -316,25 +321,20 @@ def draw(self) -> None:

self.refresh_screen()
if self._debug_screens: # pragma: no cover all
with open(
PROJECT_ROOT.joinpath("screendumps", f"{self.title}-{time.time()}"),
with _SCREENDUMP_DIR.joinpath(f"{self.title}-{time.time()}").open(
"wb",
) as f:
self.screen.putwin(f)
with open(
PROJECT_ROOT.joinpath(
"screendumps",
f"stdscr-{self.title}-{time.time()}",
),
"wb",
) as f:
with _SCREENDUMP_DIR.joinpath(
f"stdscr-{self.title}-{time.time()}",
).open("wb") as f:
self.screen.putwin(f)

def draw_item(
self,
index: int,
item: MenuItem,
index_text: Optional[str] = None,
index_text: str | None = None,
) -> None:
"""
Draw an individual item.
Expand Down Expand Up @@ -487,7 +487,7 @@ def clear_screen(self) -> None:
self.screen.clear()
self.refresh_screen()

def join(self, timeout: Optional[int] = None) -> Any: # noqa: ANN401
def join(self, timeout: int | None = None) -> Any: # noqa: ANN401
"""
Block until the menu exits.
Expand All @@ -505,7 +505,7 @@ def is_running(self) -> bool:
"""
return self._running.is_set()

def wait_for_start(self, timeout: Optional[int] = None) -> bool:
def wait_for_start(self, timeout: int | None = None) -> bool:
"""
Block until the menu starts.
Expand All @@ -530,7 +530,7 @@ def is_alive(self) -> bool:
"""
return self._main_thread.is_alive()

def exit(self, timeout: Optional[int] = None) -> Any: # noqa: A003, ANN401
def exit(self, timeout: int | None = None) -> Any: # noqa: A003, ANN401
"""
Signal the menu to exit and block until it does.
Expand Down

0 comments on commit c4c63a2

Please sign in to comment.