Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
Support newer Python versions
Update packaging machanism to modern standards
  • Loading branch information
fwkz committed Jan 17, 2024
1 parent 0102f0a commit 2ffec4b
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 99 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.12
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.12
- name: Lint
run: |
pip install -U .[dev]
flake8
black --check --diff .
isort --check-only --diff .
black --check --diff riposte/
isort --check-only --diff riposte/
ruff check --diff riposte/
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-10.15, ubuntu-18.04]
python-version: [3.6, 3.7, 3.8]
os: [macOS-13, ubuntu-22.04]
python-version: [3.8, 3.9, "3.10", 3.11, 3.12]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -36,8 +36,8 @@ jobs:
- name: Package
run: |
source venv/bin/activate
pip install wheel
python setup.py bdist_wheel
pip install build
python -m build --wheel .
- name: Install
run: |
source venv/bin/activate
Expand All @@ -46,4 +46,4 @@ jobs:
run: |
source venv/bin/activate
rm -rf riposte
pytest tests/
pytest tests/
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REFORMAT_DIRS:=riposte

define colorecho
@tput setaf 6
@echo $1
Expand All @@ -9,14 +11,14 @@ endef
all: reformat tests lint


.PHONY: build
build: clean
.PHONY: package
package: clean
$(call colorecho, "\n Building package distributions...")
python setup.py sdist bdist_wheel
python -m build .


.PHONY: publish
publish: build
publish: package
twine upload dist/*


Expand All @@ -29,17 +31,16 @@ tests: clean
.PHONY: lint
lint:
$(call colorecho, "\nLinting...")
flake8
black --check --diff .
isort --check-only --diff .

black --check --diff $(REFORMAT_DIRS)
isort --check-only --diff $(REFORMAT_DIRS)
ruff check --diff $(REFORMAT_DIRS)

.PHONY: reformat
reformat:
$(call colorecho, "\nReformatting...")
black .
isort .

black $(REFORMAT_DIRS)
isort $(REFORMAT_DIRS)
ruff check --fix $(REFORMAT_DIRS)

.PHONY: clean
clean:
Expand Down
55 changes: 52 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools_scm"]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "riposte"
description="Package for wrapping applications inside a tailored interactive shell."
authors = [
{name = "Mariusz Kupidura"},
]
dynamic = ["version"]
requires-python = ">= 3.8"
readme = "README.md"
license = {file = "LICENSE"}
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Operating System :: POSIX",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"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",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Shells",
]

[project.urls]
Homepage = "https://github.com/fwkz/riposte"

[project.optional-dependencies]
dev = [
"black",
"isort",
"pytest",
"ruff",
"setuptools_scm",
"twine",
"wheel",
]

[tool.setuptools_scm]
write_to = "riposte/_version.py"
write_to_template = "version = \"{version}\"\n"

[tool.ruff]
line-length = 80

[tool.black]
line-length = 79
line-length = 80
py36 = true
include = '\.pyi?$'
exclude = '''
Expand All @@ -25,6 +74,6 @@ force_grid_wrap = false
force_sort_within_sections = true
include_trailing_comma = true
known_first_party = "riposte"
line_length = 79
line_length = 80
multi_line_output = 3
use_parentheses = true
4 changes: 2 additions & 2 deletions riposte/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _apply_guides(self, bound_arguments: inspect.BoundArguments) -> List:
return processed

def _bind_arguments(self, *args) -> inspect.BoundArguments:
""" Check whether given `args` match `_func` signature. """
"""Check whether given `args` match `_func` signature."""
try:
return inspect.signature(self._func).bind(*args)
except TypeError as e:
Expand All @@ -106,7 +106,7 @@ def execute(self, *args: str) -> None:
return self._func(*self._apply_guides(self._bind_arguments(*args)))

def complete(self, *args, **kwargs) -> Sequence:
""" Execute completer function bound to this command. """
"""Execute completer function bound to this command."""

if not self._completer_function:
return ()
Expand Down
4 changes: 2 additions & 2 deletions riposte/guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def encode(value: str) -> Any:


def get_guides(annotation) -> Tuple[Callable]:
""" Based on given annotation get chain of guides. """
"""Based on given annotation get chain of guides."""

if annotation in (str, AnyStr, Text):
return ()
Expand All @@ -30,7 +30,7 @@ def get_guides(annotation) -> Tuple[Callable]:


def extract_guides(func: Callable) -> Dict[str, Tuple[Callable]]:
""" Extract guides out of type-annotations. """
"""Extract guides out of type-annotations."""
return {
arg: get_guides(annotation)
for arg, annotation in func.__annotations__.items()
Expand Down
6 changes: 3 additions & 3 deletions riposte/input_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@


def prompt_input(prompt: Callable) -> Generator[Callable, None, None]:
""" Unexhaustible generator yielding `input` function forever. """
"""Unexhaustible generator yielding `input` function forever."""
yield from itertools.repeat(lambda: input(prompt()))


def cli_input(inline_commands: str) -> Generator[Callable, None, None]:
""" Translate inline command provided via '-c' into input stream. """
"""Translate inline command provided via '-c' into input stream."""
yield lambda: inline_commands


def file_input(path: Path) -> Generator[Callable, None, None]:
""" Read file and translate it into input stream """
"""Read file and translate it into input stream"""
try:
with open(path, "r") as file_handler:
for line in file_handler:
Expand Down
12 changes: 6 additions & 6 deletions riposte/riposte.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def contextual_complete(self) -> List[str]:
def _raw_command_completer(
self, text, line, start_index, end_index
) -> List[str]:
""" Complete command w/o any argument """
"""Complete command w/o any argument"""
results = [
command
for command in self.contextual_complete()
Expand All @@ -112,7 +112,7 @@ def _raw_command_completer(

@staticmethod
def _split_inline_commands(line: str) -> List[str]:
""" Split multiple inline commands. """
"""Split multiple inline commands."""
parsed = shlex.split(line, posix=False)

commands = []
Expand All @@ -139,14 +139,14 @@ def _split_inline_commands(line: str) -> List[str]:

@staticmethod
def _parse_line(line: str) -> List[str]:
""" Split input line into command's name and its arguments. """
"""Split input line into command's name and its arguments."""
try:
return shlex.split(line)
except ValueError as err:
raise RiposteException(err)

def _get_command(self, command_name: str) -> Command:
""" Resolve command name into registered `Command` object. """
"""Resolve command name into registered `Command` object."""
try:
return self._commands[command_name]
except KeyError:
Expand Down Expand Up @@ -195,7 +195,7 @@ def command(
description: str = "",
guides: Dict[str, Iterable[Callable]] = None,
) -> Callable:
""" Decorator for bounding command with handling function. """
"""Decorator for bounding command with handling function."""

def wrapper(func: Callable):
if name not in self._commands:
Expand All @@ -207,7 +207,7 @@ def wrapper(func: Callable):
return wrapper

def complete(self, command: str) -> Callable:
""" Decorator for bounding complete function with `Command`. """
"""Decorator for bounding complete function with `Command`."""

def wrapper(func: Callable):
cmd = self._get_command(command)
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

53 changes: 0 additions & 53 deletions setup.py

This file was deleted.

6 changes: 2 additions & 4 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ def test_attach_completer_already_attached(command):

@mock.patch("riposte.command.extract_guides")
def test_command_setup_guides_validate(mocked_extract_guides):

with mock.patch.object(
Command, "_validate_guides"
) as mocked_validate_guides:

Command("foo", mock.Mock(), "description")

mocked_validate_guides.assert_called_once_with()
Expand Down Expand Up @@ -106,7 +104,7 @@ def test_validate_guides(command, guides):
command._validate_guides()


@mock.patch("riposte.command.inspect")
@mock.patch("riposte.command.inspect", new_callable=mock.MagicMock)
def test_bind_arguments(inspect_mock, command):
args = (1, 2)
command._bind_arguments(*args)
Expand All @@ -115,7 +113,7 @@ def test_bind_arguments(inspect_mock, command):
inspect_mock.signature.return_value.bind.assert_called_once_with(*args)


@mock.patch("riposte.command.inspect")
@mock.patch("riposte.command.inspect", new_callable=mock.MagicMock)
def test_bind_arguments_exception(inspect_mock, command):
args = (1, 2)
inspect_mock.signature.return_value.bind.side_effect = TypeError
Expand Down

0 comments on commit 2ffec4b

Please sign in to comment.