Skip to content

Commit 2ffec4b

Browse files
committed
Update project
Support newer Python versions Update packaging machanism to modern standards
1 parent 0102f0a commit 2ffec4b

File tree

10 files changed

+89
-99
lines changed

10 files changed

+89
-99
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v1
11-
- name: Set up Python 3.7
11+
- name: Set up Python 3.12
1212
uses: actions/setup-python@v1
1313
with:
14-
python-version: 3.7
14+
python-version: 3.12
1515
- name: Lint
1616
run: |
1717
pip install -U .[dev]
18-
flake8
19-
black --check --diff .
20-
isort --check-only --diff .
18+
black --check --diff riposte/
19+
isort --check-only --diff riposte/
20+
ruff check --diff riposte/
2121
2222
build:
2323
runs-on: ${{ matrix.os }}
2424
strategy:
2525
matrix:
26-
os: [macOS-10.15, ubuntu-18.04]
27-
python-version: [3.6, 3.7, 3.8]
26+
os: [macOS-13, ubuntu-22.04]
27+
python-version: [3.8, 3.9, "3.10", 3.11, 3.12]
2828
steps:
2929
- uses: actions/checkout@v1
3030
- name: Set up Python ${{ matrix.python-version }}
@@ -36,8 +36,8 @@ jobs:
3636
- name: Package
3737
run: |
3838
source venv/bin/activate
39-
pip install wheel
40-
python setup.py bdist_wheel
39+
pip install build
40+
python -m build --wheel .
4141
- name: Install
4242
run: |
4343
source venv/bin/activate
@@ -46,4 +46,4 @@ jobs:
4646
run: |
4747
source venv/bin/activate
4848
rm -rf riposte
49-
pytest tests/
49+
pytest tests/

Makefile

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
REFORMAT_DIRS:=riposte
2+
13
define colorecho
24
@tput setaf 6
35
@echo $1
@@ -9,14 +11,14 @@ endef
911
all: reformat tests lint
1012

1113

12-
.PHONY: build
13-
build: clean
14+
.PHONY: package
15+
package: clean
1416
$(call colorecho, "\n Building package distributions...")
15-
python setup.py sdist bdist_wheel
17+
python -m build .
1618

1719

1820
.PHONY: publish
19-
publish: build
21+
publish: package
2022
twine upload dist/*
2123

2224

@@ -29,17 +31,16 @@ tests: clean
2931
.PHONY: lint
3032
lint:
3133
$(call colorecho, "\nLinting...")
32-
flake8
33-
black --check --diff .
34-
isort --check-only --diff .
35-
34+
black --check --diff $(REFORMAT_DIRS)
35+
isort --check-only --diff $(REFORMAT_DIRS)
36+
ruff check --diff $(REFORMAT_DIRS)
3637

3738
.PHONY: reformat
3839
reformat:
3940
$(call colorecho, "\nReformatting...")
40-
black .
41-
isort .
42-
41+
black $(REFORMAT_DIRS)
42+
isort $(REFORMAT_DIRS)
43+
ruff check --fix $(REFORMAT_DIRS)
4344

4445
.PHONY: clean
4546
clean:

pyproject.toml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,57 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "setuptools_scm"]
2+
requires = ["setuptools>=64", "setuptools_scm>=8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "riposte"
7+
description="Package for wrapping applications inside a tailored interactive shell."
8+
authors = [
9+
{name = "Mariusz Kupidura"},
10+
]
11+
dynamic = ["version"]
12+
requires-python = ">= 3.8"
13+
readme = "README.md"
14+
license = {file = "LICENSE"}
15+
classifiers=[
16+
"Development Status :: 4 - Beta",
17+
"Environment :: Console",
18+
"Operating System :: POSIX",
19+
"Intended Audience :: Developers",
20+
"License :: OSI Approved :: MIT License",
21+
"Programming Language :: Python",
22+
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Programming Language :: Python :: 3 :: Only",
28+
"Topic :: Software Development :: Libraries :: Python Modules",
29+
"Topic :: System :: Shells",
30+
]
31+
32+
[project.urls]
33+
Homepage = "https://github.com/fwkz/riposte"
34+
35+
[project.optional-dependencies]
36+
dev = [
37+
"black",
38+
"isort",
39+
"pytest",
40+
"ruff",
41+
"setuptools_scm",
42+
"twine",
43+
"wheel",
44+
]
45+
46+
[tool.setuptools_scm]
47+
write_to = "riposte/_version.py"
48+
write_to_template = "version = \"{version}\"\n"
49+
50+
[tool.ruff]
51+
line-length = 80
352

453
[tool.black]
5-
line-length = 79
54+
line-length = 80
655
py36 = true
756
include = '\.pyi?$'
857
exclude = '''
@@ -25,6 +74,6 @@ force_grid_wrap = false
2574
force_sort_within_sections = true
2675
include_trailing_comma = true
2776
known_first_party = "riposte"
28-
line_length = 79
77+
line_length = 80
2978
multi_line_output = 3
3079
use_parentheses = true

riposte/command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _apply_guides(self, bound_arguments: inspect.BoundArguments) -> List:
8989
return processed
9090

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

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

111111
if not self._completer_function:
112112
return ()

riposte/guides.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def encode(value: str) -> Any:
1919

2020

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

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

3131

3232
def extract_guides(func: Callable) -> Dict[str, Tuple[Callable]]:
33-
""" Extract guides out of type-annotations. """
33+
"""Extract guides out of type-annotations."""
3434
return {
3535
arg: get_guides(annotation)
3636
for arg, annotation in func.__annotations__.items()

riposte/input_streams.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77

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

1212

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

1717

1818
def file_input(path: Path) -> Generator[Callable, None, None]:
19-
""" Read file and translate it into input stream """
19+
"""Read file and translate it into input stream"""
2020
try:
2121
with open(path, "r") as file_handler:
2222
for line in file_handler:

riposte/riposte.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def contextual_complete(self) -> List[str]:
100100
def _raw_command_completer(
101101
self, text, line, start_index, end_index
102102
) -> List[str]:
103-
""" Complete command w/o any argument """
103+
"""Complete command w/o any argument"""
104104
results = [
105105
command
106106
for command in self.contextual_complete()
@@ -112,7 +112,7 @@ def _raw_command_completer(
112112

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

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

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

148148
def _get_command(self, command_name: str) -> Command:
149-
""" Resolve command name into registered `Command` object. """
149+
"""Resolve command name into registered `Command` object."""
150150
try:
151151
return self._commands[command_name]
152152
except KeyError:
@@ -195,7 +195,7 @@ def command(
195195
description: str = "",
196196
guides: Dict[str, Iterable[Callable]] = None,
197197
) -> Callable:
198-
""" Decorator for bounding command with handling function. """
198+
"""Decorator for bounding command with handling function."""
199199

200200
def wrapper(func: Callable):
201201
if name not in self._commands:
@@ -207,7 +207,7 @@ def wrapper(func: Callable):
207207
return wrapper
208208

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

212212
def wrapper(func: Callable):
213213
cmd = self._get_command(command)

setup.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/test_command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ def test_attach_completer_already_attached(command):
4848

4949
@mock.patch("riposte.command.extract_guides")
5050
def test_command_setup_guides_validate(mocked_extract_guides):
51-
5251
with mock.patch.object(
5352
Command, "_validate_guides"
5453
) as mocked_validate_guides:
55-
5654
Command("foo", mock.Mock(), "description")
5755

5856
mocked_validate_guides.assert_called_once_with()
@@ -106,7 +104,7 @@ def test_validate_guides(command, guides):
106104
command._validate_guides()
107105

108106

109-
@mock.patch("riposte.command.inspect")
107+
@mock.patch("riposte.command.inspect", new_callable=mock.MagicMock)
110108
def test_bind_arguments(inspect_mock, command):
111109
args = (1, 2)
112110
command._bind_arguments(*args)
@@ -115,7 +113,7 @@ def test_bind_arguments(inspect_mock, command):
115113
inspect_mock.signature.return_value.bind.assert_called_once_with(*args)
116114

117115

118-
@mock.patch("riposte.command.inspect")
116+
@mock.patch("riposte.command.inspect", new_callable=mock.MagicMock)
119117
def test_bind_arguments_exception(inspect_mock, command):
120118
args = (1, 2)
121119
inspect_mock.signature.return_value.bind.side_effect = TypeError

0 commit comments

Comments
 (0)