Skip to content

Commit

Permalink
Merge branch 'release/0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbarrett314 committed Aug 1, 2022
2 parents 574d2b3 + 95fbf4d commit 9ec072a
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 69 deletions.
21 changes: 21 additions & 0 deletions .coveragerc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[coverage:report]
exclude_lines =
pragma: no cover {platform}
if __name__ == .__main__.:
if TYPE_CHECKING:
pragma: no cover
if sys.version_info >= \\(3, [5-9]\\):
@overload
{extra_exclude}
omit =
cursesmenu/old_curses_menu.py
{extra_omit}

[coverage:run]
branch = true
source =
test
cursesmenu
omit =
cursesmenu/old_curses_menu.py
{extra_omit}
10 changes: 10 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Black

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
17 changes: 17 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: flake8 Lint

on: [push, pull_request]

jobs:
flake8-lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@v2
- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: flake8 Lint
uses: py-actions/flake8@v2
6 changes: 3 additions & 3 deletions .github/workflows/github-action-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

strategy:
matrix:
#os: [macos-latest, ubuntu-latest, windows-latest]
os: [ubuntu-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
#os: [ubuntu-latest]
#python-version: [3.6, 3.7, 3.8, 3.9, pypy3]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]
exclude:
- os: windows-latest
python-version: pypy3
Expand Down
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -19,14 +19,14 @@ repos:
- id: trailing-whitespace
- id: check-merge-conflict
- repo: https://github.com/psf/black
rev: 21.11b1
rev: 22.6.0
hooks:
- id: black
exclude: ^docs/source/conf.py
language_version: python3

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910-1
rev: v0.971
hooks:
- id: mypy
exclude: ^docs
Expand Down Expand Up @@ -54,7 +54,7 @@ repos:
name: isort (python)

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

Expand All @@ -68,18 +68,18 @@ repos:
- pydocstyle[toml]

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

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.2.1
rev: v2.2.3
hooks:
- id: add-trailing-comma

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.0
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==21.5b1]
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.6.1
-------------

* Mostly just fixed bugs in tests
* Improved cross-platform functionality of CommandITem

Version 0.6.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion cursesmenu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__all__ = ["CursesMenu", "ItemGroup", "items"]

__version__ = "0.6.0"
__version__ = "0.6.1"
4 changes: 2 additions & 2 deletions cursesmenu/curses_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

if TYPE_CHECKING:
# noinspection PyCompatibility,PyProtectedMember
from _curses import _CursesWindow
from _curses import window

Window = _CursesWindow
Window = window
from cursesmenu.items.menu_item import MenuItem
else:
Window = Any
Expand Down
12 changes: 11 additions & 1 deletion cursesmenu/items/command_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import subprocess
import sys
from typing import TYPE_CHECKING, Any, List, Optional

from cursesmenu.items.external_item import ExternalItem
Expand Down Expand Up @@ -57,9 +58,18 @@ def __init__(
self.stdout_filepath = stdout_filepath
self.exit_status: Optional[int] = None

def _get_args_list(self) -> List[str]:
args = [self.command] + self.arguments
if not sys.platform.startswith(
"win",
): # pragma: no cover macos # pragma: no cover linux
args = [" ".join(args)]
return args

def action(self) -> None:
"""Run the command using subprocess.run."""
args = [self.command] + self.arguments
args = self._get_args_list()

if self.stdout_filepath:
with open(self.stdout_filepath, "w") as stdout:
completed_process = subprocess.run(
Expand Down
60 changes: 30 additions & 30 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
alabaster==0.7.12
appdirs==1.4.4
attrs==21.2.0
Babel==2.9.1
certifi==2021.10.8
chardet==4.0.0
charset-normalizer==2.0.8
coverage[toml]==6.1.2
attrs==22.1.0
Babel==2.10.3
certifi==2022.6.15
chardet==5.0.0
charset-normalizer==2.1.0
coverage[toml]==6.4.2
Deprecated==1.2.13
distlib==0.3.3
docutils==0.18.1
filelock==3.4.0
flake8==4.0.1
distlib==0.3.5
docutils==0.19
filelock==3.7.1
flake8==5.0.1
idna==3.3
imagesize==1.3.0
imagesize==1.4.1
iniconfig==1.1.1
Jinja2==3.0.3
MarkupSafe==2.0.1
mccabe==0.6.1
Jinja2==3.1.2
MarkupSafe==2.1.1
mccabe==0.7.0
packaging==21.3
pexpect==4.8.0
platformdirs==2.4.0
platformdirs==2.5.2
pluggy==1.0.0
ptyprocess==0.7.0
py==1.11.0
pycodestyle==2.8.0
pyflakes==2.4.0
Pygments==2.10.0
pyparsing==3.0.6
pyte==0.8.0
pytest==6.2.5
pyflakes==2.5.0
Pygments==2.12.0
pyparsing==3.0.9
pyte==0.8.1
pytest==7.1.2
pytest-cov==3.0.0
pytz==2021.3
requests==2.26.0
pytz==2022.1
requests==2.28.1
six==1.16.0
snowballstemmer==2.2.0
Sphinx==4.3.0
sphinx-autodoc-typehints==1.12.0
Sphinx==5.1.1
sphinx-autodoc-typehints==1.19.1
sphinx-rtd-theme==1.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
Expand All @@ -44,10 +44,10 @@ sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml==0.10.2
tox==3.24.4
types-Deprecated==1.2.3
urllib3==1.26.7
virtualenv==20.10.0
tox==3.25.1
types-Deprecated==1.2.9
urllib3==1.26.11
virtualenv==20.16.2
wcwidth==0.2.5
windows-curses==2.2.0;sys_platform=='win32'
wrapt==1.13.3
windows-curses==2.3.0;sys_platform=='win32'
wrapt==1.14.1
33 changes: 33 additions & 0 deletions scripts/make_coverage_rc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""A script to make a coveragerc file for testing based on the platform."""

import os
import sys
from pathlib import Path


def main() -> None:
"""Make the file."""
rcfile_path = os.environ["COVERAGE_RCFILE"]

if sys.platform.startswith("win"):
platform = "windows"
elif sys.platform.startswith("darwin"):
platform = "macos"
elif sys.platform.startswith("linux"):
platform = "linux"
else:
raise Exception("Unidentified platform")

extra_omit = "test/test_graphics.py" if platform == "windows" else ""
extra_exclude = (
'if sys.platform.startswith\\("win"\\):' if platform != "windows" else ""
)
Path(rcfile_path).write_text(
Path(".coveragerc.in")
.read_text()
.format(platform=platform, extra_omit=extra_omit, extra_exclude=extra_exclude),
)


if __name__ == "__main__":
main()
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -31,7 +30,7 @@ classifiers =
packages = find:
install_requires =
windows-curses;sys_platform=='win32'
python_requires = >=3.6
python_requires = >=3.7

[options.extras_require]
all =
Expand Down
2 changes: 2 additions & 0 deletions test/test_clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


def test_clear():
tmp_platform = sys.platform
sys.platform = "win32"
with mock.patch("cursesmenu.utils.os.system") as mock_system:
cursesmenu.utils.clear_terminal()
Expand All @@ -14,3 +15,4 @@ def test_clear():
with mock.patch("cursesmenu.utils.os.system") as mock_system:
cursesmenu.utils.clear_terminal()
mock_system.assert_called_once_with("reset")
sys.platform = tmp_platform
42 changes: 24 additions & 18 deletions test/test_command_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,43 @@

@pytest.fixture
def create_item():
if sys.platform.startswith("win"): # pragma: no cover
yield CommandItem(
"create_item",
"echo",
arguments=["hello"],
stdout_filepath=test_file_path,
)
else:
yield CommandItem("create_item", "echo hello", stdout_filepath=test_file_path)
return CommandItem(
"create_item",
"echo",
arguments=["hello"],
stdout_filepath=test_file_path,
)


@pytest.fixture
def delete_item():
if sys.platform.startswith("win"): # pragma: no cover
return CommandItem("delete_item", "del", arguments=[f"{str(test_file_path)}"])
else:
return CommandItem("delete_item", f"rm {str(test_file_path)}", ["-f"])
if sys.platform.startswith(
"win",
): # pragma: no cover macos # pragma: no cover linux
return CommandItem("delete_item", "del", arguments=[str(test_file_path)])
else: # pragma: no cover windows
return CommandItem("delete_item", "rm", arguments=["-f", str(test_file_path)])


@pytest.fixture
def exit_item():
if sys.platform.startswith("win"): # pragma: no cover
return CommandItem("return_command_item", "exit 1")
else:
return CommandItem("return_command_item", "exit 1")
return CommandItem("return_command_item", "exit", arguments=["42"])


def test_init():
item1 = CommandItem("return_command_item", "exit")
item2 = CommandItem("return_command_item", "echo", arguments=["hello"])
assert item1._get_args_list() == ["exit"]
if sys.platform.startswith("win"):
assert item2._get_args_list() == ["echo", "hello"]
else: # pragma: no cover windows
assert item2._get_args_list() == ["echo hello"]


def test_return(exit_item: CommandItem):
exit_item.action()

assert exit_item.get_return() == 1
assert exit_item.get_return() == 42


def test_create(create_item: CommandItem, delete_item: CommandItem):
Expand Down
Loading

0 comments on commit 9ec072a

Please sign in to comment.