Skip to content

Commit

Permalink
Merge pull request #20 from nezhar/httpx
Browse files Browse the repository at this point in the history
Use httpx and asyncio instead of requests
  • Loading branch information
nezhar authored Jul 8, 2022
2 parents c7c8e5d + 8a35f3e commit 5fb9709
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 260 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install .
pip install codecov black
pip install codecov black isort respx
- name: Lint with black
run: black ./updatable ./test --check

- name: Lint package sorting
run: isort ./updatable ./test --check

- name: Setup environment
run: python setup.py install

- name: Code Coverage
run: |
coverage run --source='./updatable' --omit='./updatable/__main__.py' run_tests.py
coverage report
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
21 changes: 13 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-docstring-first
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
- id: check-docstring-first
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [ "--profile", "black", "--filter-files" ]
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.7.0 - Unreleased]

### Added
- support for python 3.10
- black in pre-commit
- isort in pre-commit
- dependency `httpx`
- display required time in console

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

### Removed
- pylama form pre-commit
- support for python 3.6 and pypy3 <= 3.6
- pylama from pre-commit
- dependency `requests`
- dependency `pyopenssl`

## [0.6.0]

Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.isort]
known_first_party = ["updatable"]
profile = "black"
multi_line_output = 3
line_length = 120

[tool.black]
line_length = 120
6 changes: 4 additions & 2 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import doctest
import sys
import unittest


def test_suite():
Expand All @@ -9,4 +10,5 @@ def test_suite():


if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(test_suite())
result = unittest.TextTestRunner(verbosity=2).run(test_suite())
sys.exit(not result.wasSuccessful())
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import io
import os

from setuptools import find_packages, setup

Expand All @@ -12,9 +12,8 @@

# What packages are required for this module to be executed?
REQUIRED = [
"requests",
"httpx",
"semantic_version",
"pyopenssl",
"packaging",
]

Expand All @@ -37,7 +36,7 @@
packages=find_packages(exclude=("test",)),
entry_points={
"console_scripts": [
"updatable = updatable.console:_updatable",
"updatable = updatable.console:main",
]
},
install_requires=REQUIRED,
Expand Down
54 changes: 24 additions & 30 deletions test/test_console.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/usr/bin/env python
import asyncio
import sys
import unittest
from argparse import ArgumentTypeError
from io import StringIO
from test.utils import TEST_REQUIREMENTS_PATH, get_environment_requirements_list_monkey
from unittest.mock import patch
from argparse import ArgumentTypeError
from updatable.console import (
_str_to_bool,
_list_updates,
_list_package_updates,
_updatable,
_argument_parser,
)
from test.utils import get_environment_requirements_list_monkey, TEST_REQUIREMENTS_PATH

from updatable.console import _argument_parser, _list_package_updates, _list_updates, _str_to_bool, _updatable


class Capture(list):
Expand Down Expand Up @@ -83,7 +79,7 @@ def test_with_updates_in_list(self):


class TestListPackageUpdates(unittest.TestCase):
def _mock_get_package_update_list(*args, **kwargs):
async def _mock_get_package_update_list(*args, **kwargs):

# No updates, no prereeases, no non semantic version
if args[1] == "package1":
Expand Down Expand Up @@ -219,11 +215,11 @@ def test_with_no_available_updates(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package1", "1.0.0", False)
asyncio.run(_list_package_updates("package1", "1.0.0", False))
self.assertListEqual(output, [])

with Capture() as output:
_list_package_updates("package1", "1.0.0", True)
asyncio.run(_list_package_updates("package1", "1.0.0", True))
self.assertListEqual(output, [])

def test_with_updates_and_no_prereleases(self):
Expand All @@ -232,7 +228,7 @@ def test_with_updates_and_no_prereleases(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package2", "1.0.0", False)
asyncio.run(_list_package_updates("package2", "1.0.0", False))
self.assertListEqual(
output,
[
Expand All @@ -250,7 +246,7 @@ def test_with_updates_and_no_prereleases(self):
)

with Capture() as output:
_list_package_updates("package2", "1.0.0", True)
asyncio.run(_list_package_updates("package2", "1.0.0", True))
self.assertListEqual(
output,
[
Expand All @@ -273,7 +269,7 @@ def test_with_updates_and_no_prereleases_and_non_semantic_versions(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package3", "1.0.0", False)
asyncio.run(_list_package_updates("package3", "1.0.0", False))
self.assertListEqual(
output,
[
Expand All @@ -287,7 +283,7 @@ def test_with_updates_and_no_prereleases_and_non_semantic_versions(self):
)

with Capture() as output:
_list_package_updates("package3", "1.0.0", True)
asyncio.run(_list_package_updates("package3", "1.0.0", True))
self.assertListEqual(
output,
[
Expand All @@ -306,7 +302,7 @@ def test_with_updates_and_prereleases_and_non_semantic_versions(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package4", "1.0.0", False)
asyncio.run(_list_package_updates("package4", "1.0.0", False))
self.assertListEqual(
output,
[
Expand All @@ -320,7 +316,7 @@ def test_with_updates_and_prereleases_and_non_semantic_versions(self):
)

with Capture() as output:
_list_package_updates("package4", "1.0.0", True)
asyncio.run(_list_package_updates("package4", "1.0.0", True))
self.assertListEqual(
output,
[
Expand All @@ -341,11 +337,11 @@ def test_with_prereleases_and_non_semantic_versions(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package5", "1.0.0", False)
asyncio.run(_list_package_updates("package5", "1.0.0", False))
self.assertListEqual(output, [])

with Capture() as output:
_list_package_updates("package5", "1.0.0", True)
asyncio.run(_list_package_updates("package5", "1.0.0", True))
self.assertListEqual(
output,
[
Expand All @@ -362,11 +358,11 @@ def test_with_prereleases(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package6", "1.0.0", False)
asyncio.run(_list_package_updates("package6", "1.0.0", False))
self.assertListEqual(output, [])

with Capture() as output:
_list_package_updates("package6", "1.0.0", True)
asyncio.run(_list_package_updates("package6", "1.0.0", True))
self.assertListEqual(
output,
[
Expand All @@ -383,23 +379,21 @@ def test_with_non_semantic_versions(self):
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_list_package_updates("package7", "1.0.0", False)
asyncio.run(_list_package_updates("package7", "1.0.0", False))
self.assertListEqual(output, [])

with Capture() as output:
_list_package_updates("package7", "1.0.0", True)
asyncio.run(_list_package_updates("package7", "1.0.0", True))
self.assertListEqual(output, [])

def test_updatable_call(self):
with patch(
"updatable.console._argument_parser", side_effect=self._mock_argument_parser
):
with patch("updatable.console._argument_parser", side_effect=self._mock_argument_parser):
with patch(
"updatable.utils.get_package_update_list",
side_effect=self._mock_get_package_update_list,
):
with Capture() as output:
_updatable()
asyncio.run(_updatable())

self.assertListEqual(
output,
Expand Down Expand Up @@ -518,7 +512,7 @@ def test_argument_parser_pre_file(self):
"package2==1.0\n",
"package3==2\n",
"package4==2.4\n",
"package5==3.0.0",
"package5==3.0.0\n",
],
)

Expand All @@ -535,7 +529,7 @@ def test_argument_parser_pre_file(self):
"package2==1.0\n",
"package3==2\n",
"package4==2.4\n",
"package5==3.0.0",
"package5==3.0.0\n",
],
)

Expand Down
14 changes: 4 additions & 10 deletions test/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#!/usr/bin/env python
import unittest
from test.utils import get_environment_requirements_list_monkey

from updatable import utils as updatable_utils
from test.utils import get_environment_requirements_list_monkey


class TestParse(unittest.TestCase):
def setUp(self):
self.get_environment_requirements_list_orig = (
updatable_utils.get_environment_requirements_list
)
updatable_utils.get_environment_requirements_list = (
get_environment_requirements_list_monkey
)
self.get_environment_requirements_list_orig = updatable_utils.get_environment_requirements_list
updatable_utils.get_environment_requirements_list = get_environment_requirements_list_monkey

def tearDown(self):
updatable_utils.get_environment_requirements_list = (
self.get_environment_requirements_list_orig
)
updatable_utils.get_environment_requirements_list = self.get_environment_requirements_list_orig

def assert_package_list(self, packages):
"""
Expand Down
Loading

0 comments on commit 5fb9709

Please sign in to comment.