Skip to content

Commit 5fb9709

Browse files
authored
Merge pull request #20 from nezhar/httpx
Use httpx and asyncio instead of requests
2 parents c7c8e5d + 8a35f3e commit 5fb9709

15 files changed

+205
-260
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ jobs:
2727
run: |
2828
python -m pip install --upgrade pip
2929
pip install .
30-
pip install codecov black
30+
pip install codecov black isort respx
3131
3232
- name: Lint with black
3333
run: black ./updatable ./test --check
3434

35+
- name: Lint package sorting
36+
run: isort ./updatable ./test --check
37+
3538
- name: Setup environment
3639
run: python setup.py install
3740

3841
- name: Code Coverage
3942
run: |
4043
coverage run --source='./updatable' --omit='./updatable/__main__.py' run_tests.py
44+
coverage report
4145
coverage xml
4246
4347
- name: Upload coverage to Codecov
44-
uses: codecov/codecov-action@v1
48+
uses: codecov/codecov-action@v3

.pre-commit-config.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v4.3.0
66
hooks:
7-
- id: check-docstring-first
8-
- id: trailing-whitespace
9-
- id: end-of-file-fixer
10-
- id: check-yaml
11-
- id: check-added-large-files
12-
- repo: https://github.com/psf/black
7+
- id: check-docstring-first
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: check-yaml
11+
- id: check-added-large-files
12+
- repo: https://github.com/psf/black
1313
rev: 22.6.0
1414
hooks:
15-
- id: black
15+
- id: black
16+
- repo: https://github.com/pycqa/isort
17+
rev: 5.10.1
18+
hooks:
19+
- id: isort
20+
args: [ "--profile", "black", "--filter-files" ]

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [0.7.0 - Unreleased]
88

99
### Added
10+
- support for python 3.10
1011
- black in pre-commit
12+
- isort in pre-commit
13+
- dependency `httpx`
14+
- display required time in console
1115

1216
### Changed
13-
- add support for python 3.10
14-
- drop support for python 3.6 and pypy3 <= 3.6
17+
- moved from synchronous to asynchronous http calls for the PyPiJSON API
1518

1619
### Removed
17-
- pylama form pre-commit
20+
- support for python 3.6 and pypy3 <= 3.6
21+
- pylama from pre-commit
22+
- dependency `requests`
23+
- dependency `pyopenssl`
1824

1925
## [0.6.0]
2026

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tool.isort]
2+
known_first_party = ["updatable"]
3+
profile = "black"
4+
multi_line_output = 3
5+
line_length = 120
6+
7+
[tool.black]
8+
line_length = 120

run_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import unittest
21
import doctest
2+
import sys
3+
import unittest
34

45

56
def test_suite():
@@ -9,4 +10,5 @@ def test_suite():
910

1011

1112
if __name__ == "__main__":
12-
unittest.TextTestRunner(verbosity=2).run(test_suite())
13+
result = unittest.TextTestRunner(verbosity=2).run(test_suite())
14+
sys.exit(not result.wasSuccessful())

setup.cfg

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

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import os
21
import io
2+
import os
33

44
from setuptools import find_packages, setup
55

@@ -12,9 +12,8 @@
1212

1313
# What packages are required for this module to be executed?
1414
REQUIRED = [
15-
"requests",
15+
"httpx",
1616
"semantic_version",
17-
"pyopenssl",
1817
"packaging",
1918
]
2019

@@ -37,7 +36,7 @@
3736
packages=find_packages(exclude=("test",)),
3837
entry_points={
3938
"console_scripts": [
40-
"updatable = updatable.console:_updatable",
39+
"updatable = updatable.console:main",
4140
]
4241
},
4342
install_requires=REQUIRED,

test/test_console.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
#!/usr/bin/env python
2+
import asyncio
23
import sys
34
import unittest
5+
from argparse import ArgumentTypeError
46
from io import StringIO
7+
from test.utils import TEST_REQUIREMENTS_PATH, get_environment_requirements_list_monkey
58
from unittest.mock import patch
6-
from argparse import ArgumentTypeError
7-
from updatable.console import (
8-
_str_to_bool,
9-
_list_updates,
10-
_list_package_updates,
11-
_updatable,
12-
_argument_parser,
13-
)
14-
from test.utils import get_environment_requirements_list_monkey, TEST_REQUIREMENTS_PATH
9+
10+
from updatable.console import _argument_parser, _list_package_updates, _list_updates, _str_to_bool, _updatable
1511

1612

1713
class Capture(list):
@@ -83,7 +79,7 @@ def test_with_updates_in_list(self):
8379

8480

8581
class TestListPackageUpdates(unittest.TestCase):
86-
def _mock_get_package_update_list(*args, **kwargs):
82+
async def _mock_get_package_update_list(*args, **kwargs):
8783

8884
# No updates, no prereeases, no non semantic version
8985
if args[1] == "package1":
@@ -219,11 +215,11 @@ def test_with_no_available_updates(self):
219215
side_effect=self._mock_get_package_update_list,
220216
):
221217
with Capture() as output:
222-
_list_package_updates("package1", "1.0.0", False)
218+
asyncio.run(_list_package_updates("package1", "1.0.0", False))
223219
self.assertListEqual(output, [])
224220

225221
with Capture() as output:
226-
_list_package_updates("package1", "1.0.0", True)
222+
asyncio.run(_list_package_updates("package1", "1.0.0", True))
227223
self.assertListEqual(output, [])
228224

229225
def test_with_updates_and_no_prereleases(self):
@@ -232,7 +228,7 @@ def test_with_updates_and_no_prereleases(self):
232228
side_effect=self._mock_get_package_update_list,
233229
):
234230
with Capture() as output:
235-
_list_package_updates("package2", "1.0.0", False)
231+
asyncio.run(_list_package_updates("package2", "1.0.0", False))
236232
self.assertListEqual(
237233
output,
238234
[
@@ -250,7 +246,7 @@ def test_with_updates_and_no_prereleases(self):
250246
)
251247

252248
with Capture() as output:
253-
_list_package_updates("package2", "1.0.0", True)
249+
asyncio.run(_list_package_updates("package2", "1.0.0", True))
254250
self.assertListEqual(
255251
output,
256252
[
@@ -273,7 +269,7 @@ def test_with_updates_and_no_prereleases_and_non_semantic_versions(self):
273269
side_effect=self._mock_get_package_update_list,
274270
):
275271
with Capture() as output:
276-
_list_package_updates("package3", "1.0.0", False)
272+
asyncio.run(_list_package_updates("package3", "1.0.0", False))
277273
self.assertListEqual(
278274
output,
279275
[
@@ -287,7 +283,7 @@ def test_with_updates_and_no_prereleases_and_non_semantic_versions(self):
287283
)
288284

289285
with Capture() as output:
290-
_list_package_updates("package3", "1.0.0", True)
286+
asyncio.run(_list_package_updates("package3", "1.0.0", True))
291287
self.assertListEqual(
292288
output,
293289
[
@@ -306,7 +302,7 @@ def test_with_updates_and_prereleases_and_non_semantic_versions(self):
306302
side_effect=self._mock_get_package_update_list,
307303
):
308304
with Capture() as output:
309-
_list_package_updates("package4", "1.0.0", False)
305+
asyncio.run(_list_package_updates("package4", "1.0.0", False))
310306
self.assertListEqual(
311307
output,
312308
[
@@ -320,7 +316,7 @@ def test_with_updates_and_prereleases_and_non_semantic_versions(self):
320316
)
321317

322318
with Capture() as output:
323-
_list_package_updates("package4", "1.0.0", True)
319+
asyncio.run(_list_package_updates("package4", "1.0.0", True))
324320
self.assertListEqual(
325321
output,
326322
[
@@ -341,11 +337,11 @@ def test_with_prereleases_and_non_semantic_versions(self):
341337
side_effect=self._mock_get_package_update_list,
342338
):
343339
with Capture() as output:
344-
_list_package_updates("package5", "1.0.0", False)
340+
asyncio.run(_list_package_updates("package5", "1.0.0", False))
345341
self.assertListEqual(output, [])
346342

347343
with Capture() as output:
348-
_list_package_updates("package5", "1.0.0", True)
344+
asyncio.run(_list_package_updates("package5", "1.0.0", True))
349345
self.assertListEqual(
350346
output,
351347
[
@@ -362,11 +358,11 @@ def test_with_prereleases(self):
362358
side_effect=self._mock_get_package_update_list,
363359
):
364360
with Capture() as output:
365-
_list_package_updates("package6", "1.0.0", False)
361+
asyncio.run(_list_package_updates("package6", "1.0.0", False))
366362
self.assertListEqual(output, [])
367363

368364
with Capture() as output:
369-
_list_package_updates("package6", "1.0.0", True)
365+
asyncio.run(_list_package_updates("package6", "1.0.0", True))
370366
self.assertListEqual(
371367
output,
372368
[
@@ -383,23 +379,21 @@ def test_with_non_semantic_versions(self):
383379
side_effect=self._mock_get_package_update_list,
384380
):
385381
with Capture() as output:
386-
_list_package_updates("package7", "1.0.0", False)
382+
asyncio.run(_list_package_updates("package7", "1.0.0", False))
387383
self.assertListEqual(output, [])
388384

389385
with Capture() as output:
390-
_list_package_updates("package7", "1.0.0", True)
386+
asyncio.run(_list_package_updates("package7", "1.0.0", True))
391387
self.assertListEqual(output, [])
392388

393389
def test_updatable_call(self):
394-
with patch(
395-
"updatable.console._argument_parser", side_effect=self._mock_argument_parser
396-
):
390+
with patch("updatable.console._argument_parser", side_effect=self._mock_argument_parser):
397391
with patch(
398392
"updatable.utils.get_package_update_list",
399393
side_effect=self._mock_get_package_update_list,
400394
):
401395
with Capture() as output:
402-
_updatable()
396+
asyncio.run(_updatable())
403397

404398
self.assertListEqual(
405399
output,
@@ -518,7 +512,7 @@ def test_argument_parser_pre_file(self):
518512
"package2==1.0\n",
519513
"package3==2\n",
520514
"package4==2.4\n",
521-
"package5==3.0.0",
515+
"package5==3.0.0\n",
522516
],
523517
)
524518

@@ -535,7 +529,7 @@ def test_argument_parser_pre_file(self):
535529
"package2==1.0\n",
536530
"package3==2\n",
537531
"package4==2.4\n",
538-
"package5==3.0.0",
532+
"package5==3.0.0\n",
539533
],
540534
)
541535

test/test_parse.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
#!/usr/bin/env python
22
import unittest
3+
from test.utils import get_environment_requirements_list_monkey
34

45
from updatable import utils as updatable_utils
5-
from test.utils import get_environment_requirements_list_monkey
66

77

88
class TestParse(unittest.TestCase):
99
def setUp(self):
10-
self.get_environment_requirements_list_orig = (
11-
updatable_utils.get_environment_requirements_list
12-
)
13-
updatable_utils.get_environment_requirements_list = (
14-
get_environment_requirements_list_monkey
15-
)
10+
self.get_environment_requirements_list_orig = updatable_utils.get_environment_requirements_list
11+
updatable_utils.get_environment_requirements_list = get_environment_requirements_list_monkey
1612

1713
def tearDown(self):
18-
updatable_utils.get_environment_requirements_list = (
19-
self.get_environment_requirements_list_orig
20-
)
14+
updatable_utils.get_environment_requirements_list = self.get_environment_requirements_list_orig
2115

2216
def assert_package_list(self, packages):
2317
"""

0 commit comments

Comments
 (0)