From f14bae0c3ee562b1113fa541a88de5f2a51a0f65 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 20:26:37 +0900 Subject: [PATCH 01/14] add: configure files (setup.py->setup.py+setup.cfg+pyproject.toml) --- pyproject.toml | 3 +++ setup.cfg | 67 ++++++++++++++++++++++++++++++++++++++++++++++++-- setup.py | 65 +----------------------------------------------- 3 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..10376dc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["wheel", "setuptools"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index 8980e9c..0bbe4a4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,69 @@ [metadata] -description-file = README.md -license_file = LICENSE +name = attr: waybackpy/__version__.__title__ +version = attr: waybackpy/__version__.__version__ +description = attr: waybackpy/__version__.__description__ +long_description = file: README.md +long_description_content_type = text/markdown +license = attr: waybackpy/__version__.__license__ +author = attr: waybackpy/__version__.__author__ +author_email = attr: waybackpy/__version__.__author_email__ +url = attr: waybackpy/__version__.__url__ +download_url = attr: waybackpy/__version__.__download_url__ +project_urls = + Documentation = https://github.com/akamhy/waybackpy/wiki + Source = https://github.com/akamhy/waybackpy + Tracker = https://github.com/akamhy/waybackpy/issues +keywords = + Archive Website + Wayback Machine + Internet Archive + Wayback Machine CLI + Wayback Machine Python + Internet Archiving + Availability API + CDX API + savepagenow +classifiers = + Development Status :: 4 - Beta + Intended Audience :: Developers + Natural Language :: English + License :: OSI Approved :: MIT License + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.4 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: Implementation :: CPython + +[options] +packages = + waybackpy +python_requires = >= 3.4 +install_requires = + requests + click + +[options.extras_require] +dev = + black + flake8 + isort + +[options.entry_points] +console_scripts = + waybackpy = waybackpy.cli:main + +[isort] +profile = black + +[flake8] +# E501: line too long +ignore = E501 +indent-size = 4 [flake8] max-line-length = 88 diff --git a/setup.py b/setup.py index b7fc3e4..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,66 +1,3 @@ -import os.path from setuptools import setup -readme_path = os.path.join(os.path.dirname(__file__), "README.md") -with open(readme_path, encoding="utf-8") as f: - long_description = f.read() - -about = {} -version_path = os.path.join(os.path.dirname(__file__), "waybackpy", "__version__.py") -with open(version_path, encoding="utf-8") as f: - exec(f.read(), about) - -version = str(about["__version__"]) - -download_url = "https://github.com/akamhy/waybackpy/archive/{version}.tar.gz".format( - version=version -) - -setup( - name=about["__title__"], - packages=["waybackpy"], - version=version, - description=about["__description__"], - long_description=long_description, - long_description_content_type="text/markdown", - license=about["__license__"], - author=about["__author__"], - author_email=about["__author_email__"], - url=about["__url__"], - download_url=download_url, - keywords=[ - "Archive Website", - "Wayback Machine", - "Internet Archive", - "Wayback Machine CLI", - "Wayback Machine Python", - "Internet Archiving", - "Availability API", - "CDX API", - "savepagenow", - ], - install_requires=["requests", "click"], - python_requires=">=3.4", - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Natural Language :: English", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: Implementation :: CPython", - ], - entry_points={"console_scripts": ["waybackpy = waybackpy.cli:main"]}, - project_urls={ - "Documentation": "https://github.com/akamhy/waybackpy/wiki", - "Source": "https://github.com/akamhy/waybackpy", - "Tracker": "https://github.com/akamhy/waybackpy/issues", - }, -) +setup() From bae383b282592f6b18d11a4b44a50c30bd5c8d5f Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 20:27:00 +0900 Subject: [PATCH 02/14] add: __download_url__ --- waybackpy/__init__.py | 19 ++++++++++--------- waybackpy/__version__.py | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/waybackpy/__init__.py b/waybackpy/__init__.py index c86b736..860a4a3 100644 --- a/waybackpy/__init__.py +++ b/waybackpy/__init__.py @@ -1,14 +1,15 @@ -from .wrapper import Url -from .cdx_api import WaybackMachineCDXServerAPI -from .save_api import WaybackMachineSaveAPI -from .availability_api import WaybackMachineAvailabilityAPI from .__version__ import ( - __title__, - __description__, - __url__, - __version__, __author__, __author_email__, - __license__, __copyright__, + __description__, + __license__, + __title__, + __url__, + __download_url__, + __version__, ) +from .availability_api import WaybackMachineAvailabilityAPI +from .cdx_api import WaybackMachineCDXServerAPI +from .save_api import WaybackMachineSaveAPI +from .wrapper import Url diff --git a/waybackpy/__version__.py b/waybackpy/__version__.py index e2c4906..a0e4d86 100644 --- a/waybackpy/__version__.py +++ b/waybackpy/__version__.py @@ -5,6 +5,11 @@ ) __url__ = "https://akamhy.github.io/waybackpy/" __version__ = "3.0.2" +__download_url__ = ( + "https://github.com/akamhy/waybackpy/archive/{version}.tar.gz".format( + version=__version__ + ) +) __author__ = "Akash Mahanty" __author_email__ = "akamhy@yahoo.com" __license__ = "MIT" From 7cc7d5a288ee2c6fc76c5b5f93834815c6fc5fae Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 20:27:17 +0900 Subject: [PATCH 03/14] format with black and isort --- tests/test_availability_api.py | 5 +++-- tests/test_cdx_snapshot.py | 3 ++- tests/test_cdx_utils.py | 11 ++++++----- tests/test_save_api.py | 7 ++++--- tests/test_utils.py | 6 +++--- waybackpy/availability_api.py | 8 +++++--- waybackpy/cdx_api.py | 9 ++++----- waybackpy/cdx_utils.py | 4 +++- waybackpy/cli.py | 14 ++++++++------ waybackpy/save_api.py | 8 ++++---- waybackpy/utils.py | 1 + waybackpy/wrapper.py | 5 +++-- 12 files changed, 46 insertions(+), 35 deletions(-) diff --git a/tests/test_availability_api.py b/tests/test_availability_api.py index 1260129..d76f9c5 100644 --- a/tests/test_availability_api.py +++ b/tests/test_availability_api.py @@ -1,12 +1,13 @@ -import pytest import random import string from datetime import datetime, timedelta +import pytest + from waybackpy.availability_api import WaybackMachineAvailabilityAPI from waybackpy.exceptions import ( - InvalidJSONInAvailabilityAPIResponse, ArchiveNotInAvailabilityAPIResponse, + InvalidJSONInAvailabilityAPIResponse, ) now = datetime.utcnow() diff --git a/tests/test_cdx_snapshot.py b/tests/test_cdx_snapshot.py index 0f9034f..cacdc0f 100644 --- a/tests/test_cdx_snapshot.py +++ b/tests/test_cdx_snapshot.py @@ -1,6 +1,7 @@ -import pytest from datetime import datetime +import pytest + from waybackpy.cdx_snapshot import CDXSnapshot diff --git a/tests/test_cdx_utils.py b/tests/test_cdx_utils.py index 27435f2..a0b5ff4 100644 --- a/tests/test_cdx_utils.py +++ b/tests/test_cdx_utils.py @@ -1,13 +1,14 @@ import pytest -from waybackpy.exceptions import WaybackError + from waybackpy.cdx_utils import ( - get_total_pages, - full_url, - get_response, - check_filters, check_collapses, + check_filters, check_match_type, + full_url, + get_response, + get_total_pages, ) +from waybackpy.exceptions import WaybackError def test_get_total_pages(): diff --git a/tests/test_save_api.py b/tests/test_save_api.py index be9b56c..92a1cde 100644 --- a/tests/test_save_api.py +++ b/tests/test_save_api.py @@ -1,11 +1,12 @@ -import pytest -import time import random import string +import time from datetime import datetime -from waybackpy.save_api import WaybackMachineSaveAPI +import pytest + from waybackpy.exceptions import MaximumSaveRetriesExceeded +from waybackpy.save_api import WaybackMachineSaveAPI rndstr = lambda n: "".join( random.choice(string.ascii_uppercase + string.digits) for _ in range(n) diff --git a/tests/test_utils.py b/tests/test_utils.py index 8a05ca8..88d2eda 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,9 +1,9 @@ +from waybackpy.__version__ import __version__ from waybackpy.utils import ( - latest_version_pypi, - latest_version_github, DEFAULT_USER_AGENT, + latest_version_github, + latest_version_pypi, ) -from waybackpy.__version__ import __version__ def test_default_user_agent(): diff --git a/waybackpy/availability_api.py b/waybackpy/availability_api.py index 72f247f..6e76bb8 100644 --- a/waybackpy/availability_api.py +++ b/waybackpy/availability_api.py @@ -1,12 +1,14 @@ -import time import json -import requests +import time from datetime import datetime -from .utils import DEFAULT_USER_AGENT + +import requests + from .exceptions import ( ArchiveNotInAvailabilityAPIResponse, InvalidJSONInAvailabilityAPIResponse, ) +from .utils import DEFAULT_USER_AGENT class WaybackMachineAvailabilityAPI: diff --git a/waybackpy/cdx_api.py b/waybackpy/cdx_api.py index 5d122f5..a04f8af 100644 --- a/waybackpy/cdx_api.py +++ b/waybackpy/cdx_api.py @@ -1,14 +1,13 @@ -from .exceptions import WaybackError from .cdx_snapshot import CDXSnapshot from .cdx_utils import ( - get_total_pages, - get_response, - check_filters, check_collapses, + check_filters, check_match_type, full_url, + get_response, + get_total_pages, ) - +from .exceptions import WaybackError from .utils import DEFAULT_USER_AGENT diff --git a/waybackpy/cdx_utils.py b/waybackpy/cdx_utils.py index ff31918..06f043c 100644 --- a/waybackpy/cdx_utils.py +++ b/waybackpy/cdx_utils.py @@ -1,7 +1,9 @@ import re + import requests -from urllib3.util.retry import Retry from requests.adapters import HTTPAdapter +from urllib3.util.retry import Retry + from .exceptions import WaybackError from .utils import DEFAULT_USER_AGENT diff --git a/waybackpy/cli.py b/waybackpy/cli.py index bf536e5..e2f6468 100644 --- a/waybackpy/cli.py +++ b/waybackpy/cli.py @@ -1,15 +1,17 @@ -import click -import re -import os import json as JSON +import os import random -import requests +import re import string + +import click +import requests + from .__version__ import __version__ -from .utils import DEFAULT_USER_AGENT +from .availability_api import WaybackMachineAvailabilityAPI from .cdx_api import WaybackMachineCDXServerAPI from .save_api import WaybackMachineSaveAPI -from .availability_api import WaybackMachineAvailabilityAPI +from .utils import DEFAULT_USER_AGENT from .wrapper import Url diff --git a/waybackpy/save_api.py b/waybackpy/save_api.py index cfdb595..10b1e51 100644 --- a/waybackpy/save_api.py +++ b/waybackpy/save_api.py @@ -1,13 +1,13 @@ import re import time -import requests - from datetime import datetime -from urllib3.util.retry import Retry + +import requests from requests.adapters import HTTPAdapter +from urllib3.util.retry import Retry -from .utils import DEFAULT_USER_AGENT from .exceptions import MaximumSaveRetriesExceeded +from .utils import DEFAULT_USER_AGENT class WaybackMachineSaveAPI: diff --git a/waybackpy/utils.py b/waybackpy/utils.py index 0c2be13..0123ea5 100644 --- a/waybackpy/utils.py +++ b/waybackpy/utils.py @@ -1,4 +1,5 @@ import requests + from .__version__ import __version__ DEFAULT_USER_AGENT = "waybackpy %s - https://github.com/akamhy/waybackpy" % __version__ diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index 7ca8d22..3121b77 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -1,8 +1,9 @@ -from .save_api import WaybackMachineSaveAPI +from datetime import datetime, timedelta + from .availability_api import WaybackMachineAvailabilityAPI from .cdx_api import WaybackMachineCDXServerAPI +from .save_api import WaybackMachineSaveAPI from .utils import DEFAULT_USER_AGENT -from datetime import datetime, timedelta """ The Url class is not recommended to be used anymore, instead use the From 5e491aaf5504bccb1ac2885f4b665dd87d7083ef Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 20:28:02 +0900 Subject: [PATCH 04/14] fix: flake8 section in setup.cfg --- setup.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 0bbe4a4..96bb5eb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,10 +61,6 @@ console_scripts = profile = black [flake8] -# E501: line too long -ignore = E501 indent-size = 4 - -[flake8] max-line-length = 88 extend-ignore = E203,W503 From 2685fefc889ca23d32d5a6354bb9f41b656aa622 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 20:29:12 +0900 Subject: [PATCH 05/14] add: E501 to flake ignore --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 96bb5eb..4d8868a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,4 +63,4 @@ profile = black [flake8] indent-size = 4 max-line-length = 88 -extend-ignore = E203,W503 +extend-ignore = E203,W503,E501 From a250e1d71e1b198f0ab3728f37ab053ef162230f Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 21:16:59 +0900 Subject: [PATCH 06/14] fix: metadata.name does not accept attr --- setup.cfg | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/setup.cfg b/setup.cfg index 4d8868a..9e27d98 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,14 @@ [metadata] -name = attr: waybackpy/__version__.__title__ -version = attr: waybackpy/__version__.__version__ -description = attr: waybackpy/__version__.__description__ +name = waybackpy +version = attr: waybackpy.__version__ +description = attr: waybackpy.__description__ long_description = file: README.md long_description_content_type = text/markdown -license = attr: waybackpy/__version__.__license__ -author = attr: waybackpy/__version__.__author__ -author_email = attr: waybackpy/__version__.__author_email__ -url = attr: waybackpy/__version__.__url__ -download_url = attr: waybackpy/__version__.__download_url__ +license = attr: waybackpy.__license__ +author = attr: waybackpy.__author__ +author_email = attr: waybackpy.__author_email__ +url = attr: waybackpy.__url__ +download_url = attr: waybackpy.__download_url__ project_urls = Documentation = https://github.com/akamhy/waybackpy/wiki Source = https://github.com/akamhy/waybackpy @@ -40,18 +40,21 @@ classifiers = Programming Language :: Python :: Implementation :: CPython [options] -packages = - waybackpy +packages = find: python_requires = >= 3.4 install_requires = - requests click + requests [options.extras_require] dev = black + codecov flake8 - isort + mypy + pytest + pytest-cov + [options.entry_points] console_scripts = From 01d8ff3ff5728aad6aeb655376dc121a4d65e84c Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 21:18:03 +0900 Subject: [PATCH 07/14] fix: merge __version__.py into __init__.py --- waybackpy/__init__.py | 42 ++++++++++++++++++++++++++++++---------- waybackpy/__version__.py | 16 --------------- waybackpy/cli.py | 10 +++++----- waybackpy/utils.py | 2 +- 4 files changed, 38 insertions(+), 32 deletions(-) delete mode 100644 waybackpy/__version__.py diff --git a/waybackpy/__init__.py b/waybackpy/__init__.py index 860a4a3..602ca00 100644 --- a/waybackpy/__init__.py +++ b/waybackpy/__init__.py @@ -1,15 +1,37 @@ -from .__version__ import ( - __author__, - __author_email__, - __copyright__, - __description__, - __license__, - __title__, - __url__, - __download_url__, - __version__, +__title__ = "waybackpy" +__description__ = ( + "Python package that interfaces with the Internet Archive's Wayback Machine APIs. " + "Archive pages and retrieve archived pages easily." ) +__url__ = "https://akamhy.github.io/waybackpy/" +__version__ = "3.0.2" +__download_url__ = ( + "https://github.com/akamhy/waybackpy/archive/{version}.tar.gz".format( + version=__version__ + ) +) +__author__ = "Akash Mahanty" +__author_email__ = "akamhy@yahoo.com" +__license__ = "MIT" +__copyright__ = "Copyright 2020-2022 Akash Mahanty et al." + from .availability_api import WaybackMachineAvailabilityAPI from .cdx_api import WaybackMachineCDXServerAPI from .save_api import WaybackMachineSaveAPI from .wrapper import Url + +__all__ = [ + "__author__", + "__author_email__", + "__copyright__", + "__description__", + "__license__", + "__title__", + "__url__", + "__download_url__", + "__version__", + "WaybackMachineAvailabilityAPI", + "WaybackMachineCDXServerAPI", + "WaybackMachineSaveAPI", + "Url", +] diff --git a/waybackpy/__version__.py b/waybackpy/__version__.py deleted file mode 100644 index a0e4d86..0000000 --- a/waybackpy/__version__.py +++ /dev/null @@ -1,16 +0,0 @@ -__title__ = "waybackpy" -__description__ = ( - "Python package that interfaces with the Internet Archive's Wayback Machine APIs. " - "Archive pages and retrieve archived pages easily." -) -__url__ = "https://akamhy.github.io/waybackpy/" -__version__ = "3.0.2" -__download_url__ = ( - "https://github.com/akamhy/waybackpy/archive/{version}.tar.gz".format( - version=__version__ - ) -) -__author__ = "Akash Mahanty" -__author_email__ = "akamhy@yahoo.com" -__license__ = "MIT" -__copyright__ = "Copyright 2020-2022 Akash Mahanty et al." diff --git a/waybackpy/cli.py b/waybackpy/cli.py index e2f6468..406d7ac 100644 --- a/waybackpy/cli.py +++ b/waybackpy/cli.py @@ -7,7 +7,7 @@ import click import requests -from .__version__ import __version__ +from . import __version__ from .availability_api import WaybackMachineAvailabilityAPI from .cdx_api import WaybackMachineCDXServerAPI from .save_api import WaybackMachineSaveAPI @@ -191,13 +191,13 @@ def main( limit, cdx_print, ): - """\b + """\ _ _ | | | | __ ____ _ _ _| |__ __ _ ___| | ___ __ _ _ - \ \ /\ / / _` | | | | '_ \ / _` |/ __| |/ / '_ \| | | | - \ V V / (_| | |_| | |_) | (_| | (__| <| |_) | |_| | - \_/\_/ \__,_|\__, |_.__/ \__,_|\___|_|\_\ .__/ \__, | + \\ \\ /\\ / / _` | | | | '_ \\ / _` |/ __| |/ / '_ \\| | | | + \\ V V / (_| | |_| | |_) | (_| | (__| <| |_) | |_| | + \\_/\\_/ \\__,_|\\__, |_.__/ \\__,_|\\___|_|\\_\\ .__/ \\__, | __/ | | | __/ | |___/ |_| |___/ diff --git a/waybackpy/utils.py b/waybackpy/utils.py index 0123ea5..7201403 100644 --- a/waybackpy/utils.py +++ b/waybackpy/utils.py @@ -1,6 +1,6 @@ import requests -from .__version__ import __version__ +from . import __version__ DEFAULT_USER_AGENT = "waybackpy %s - https://github.com/akamhy/waybackpy" % __version__ From 79259b40263cb8c7d11ed76ebd2a4bd3f94426d0 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 21:33:25 +0900 Subject: [PATCH 08/14] fix: flake8 errors in tests/ --- tests/test_availability_api.py | 12 +++++++----- tests/test_cdx_snapshot.py | 2 -- tests/test_cdx_utils.py | 4 ++-- tests/test_save_api.py | 11 +++++++---- tests/test_utils.py | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/test_availability_api.py b/tests/test_availability_api.py index d76f9c5..3b2b812 100644 --- a/tests/test_availability_api.py +++ b/tests/test_availability_api.py @@ -14,9 +14,11 @@ url = "https://example.com/" user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" -rndstr = lambda n: "".join( - random.choice(string.ascii_uppercase + string.digits) for _ in range(n) -) + +def rndstr(n): + return "".join( + random.choice(string.ascii_uppercase + string.digits) for _ in range(n) + ) def test_oldest(): @@ -58,7 +60,7 @@ def test_invalid_json(): """ with pytest.raises(InvalidJSONInAvailabilityAPIResponse): availability_api = WaybackMachineAvailabilityAPI(url="", user_agent=user_agent) - archive_url = availability_api.archive_url + _ = availability_api.archive_url def test_no_archive(): @@ -74,7 +76,7 @@ def test_no_archive(): availability_api = WaybackMachineAvailabilityAPI( url="https://%s.cn" % rndstr(30), user_agent=user_agent ) - archive_url = availability_api.archive_url + _ = availability_api.archive_url def test_no_api_call_str_repr(): diff --git a/tests/test_cdx_snapshot.py b/tests/test_cdx_snapshot.py index cacdc0f..baea40e 100644 --- a/tests/test_cdx_snapshot.py +++ b/tests/test_cdx_snapshot.py @@ -1,7 +1,5 @@ from datetime import datetime -import pytest - from waybackpy.cdx_snapshot import CDXSnapshot diff --git a/tests/test_cdx_utils.py b/tests/test_cdx_utils.py index a0b5ff4..406e7e6 100644 --- a/tests/test_cdx_utils.py +++ b/tests/test_cdx_utils.py @@ -87,10 +87,10 @@ def test_check_collapses(): def test_check_match_type(): - assert None == check_match_type(None, "url") + assert check_match_type(None, "url") is None match_type = "exact" url = "test_url" - assert None == check_match_type(match_type, url) + assert check_match_type(match_type, url) is None url = "has * in it" with pytest.raises(WaybackError): diff --git a/tests/test_save_api.py b/tests/test_save_api.py index 92a1cde..afd3863 100644 --- a/tests/test_save_api.py +++ b/tests/test_save_api.py @@ -8,9 +8,11 @@ from waybackpy.exceptions import MaximumSaveRetriesExceeded from waybackpy.save_api import WaybackMachineSaveAPI -rndstr = lambda n: "".join( - random.choice(string.ascii_uppercase + string.digits) for _ in range(n) -) + +def rndstr(n): + return "".join( + random.choice(string.ascii_uppercase + string.digits) for _ in range(n) + ) def test_save(): @@ -24,8 +26,9 @@ def test_save(): cached_save = save_api.cached_save assert cached_save in [True, False] assert archive_url.find("github.com/akamhy/waybackpy") != -1 + assert timestamp is not None assert str(headers).find("github.com/akamhy/waybackpy") != -1 - assert type(save_api.timestamp()) == type(datetime(year=2020, month=10, day=2)) + assert isinstance(save_api.timestamp(), datetime.datetime) def test_max_redirect_exceeded(): diff --git a/tests/test_utils.py b/tests/test_utils.py index 88d2eda..6f6d509 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,4 @@ -from waybackpy.__version__ import __version__ +from waybackpy import __version__ from waybackpy.utils import ( DEFAULT_USER_AGENT, latest_version_github, From 0d9cb63971f28f32b71d2da1c1ac5f2cb422e599 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 21:37:26 +0900 Subject: [PATCH 09/14] fix: datetime.datetime -> datetime --- tests/test_save_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_save_api.py b/tests/test_save_api.py index afd3863..7cd725d 100644 --- a/tests/test_save_api.py +++ b/tests/test_save_api.py @@ -28,7 +28,7 @@ def test_save(): assert archive_url.find("github.com/akamhy/waybackpy") != -1 assert timestamp is not None assert str(headers).find("github.com/akamhy/waybackpy") != -1 - assert isinstance(save_api.timestamp(), datetime.datetime) + assert isinstance(save_api.timestamp(), datetime) def test_max_redirect_exceeded(): From 09fc4baaec2d80e487c45f8fa9b401babb382228 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 21:47:23 +0900 Subject: [PATCH 10/14] fix: banner --- waybackpy/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/waybackpy/cli.py b/waybackpy/cli.py index 406d7ac..f62ecaf 100644 --- a/waybackpy/cli.py +++ b/waybackpy/cli.py @@ -191,13 +191,13 @@ def main( limit, cdx_print, ): - """\ + """ _ _ | | | | __ ____ _ _ _| |__ __ _ ___| | ___ __ _ _ - \\ \\ /\\ / / _` | | | | '_ \\ / _` |/ __| |/ / '_ \\| | | | - \\ V V / (_| | |_| | |_) | (_| | (__| <| |_) | |_| | - \\_/\\_/ \\__,_|\\__, |_.__/ \\__,_|\\___|_|\\_\\ .__/ \\__, | + \ \ /\ / / _` | | | | '_ \ / _` |/ __| |/ / '_ \| | | | + \ V V / (_| | |_| | |_) | (_| | (__| <| |_) | |_| | + \_/\_/ \__,_|\__, |_.__/ \__,_|\___|_|\_\ .__/ \__, | __/ | | | __/ | |___/ |_| |___/ From c96d8c8fc2bba8495532b6807a576222d4ef3828 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 21:51:34 +0900 Subject: [PATCH 11/14] fix: ignore W605 for banner --- setup.cfg | 2 +- waybackpy/cli.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 9e27d98..acf9512 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,4 +66,4 @@ profile = black [flake8] indent-size = 4 max-line-length = 88 -extend-ignore = E203,W503,E501 +extend-ignore = E203,W503,E501,W605 diff --git a/waybackpy/cli.py b/waybackpy/cli.py index f62ecaf..f1117c2 100644 --- a/waybackpy/cli.py +++ b/waybackpy/cli.py @@ -191,7 +191,7 @@ def main( limit, cdx_print, ): - """ + """\b _ _ | | | | __ ____ _ _ _| |__ __ _ ___| | ___ __ _ _ From f0776152b79a6a9c76bd507c896d09dbd2ce1848 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 22:04:37 +0900 Subject: [PATCH 12/14] fix: way to install deps in CI --- .github/workflows/build_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index ef61a4a..d5364e6 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel + pip install -U setuptools wheel - name: Build test the package run: | python setup.py sdist bdist_wheel From 193ac3d7d414a22a1ae13003d94699270dc70db4 Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 22:08:44 +0900 Subject: [PATCH 13/14] add: versem to setuptools --- requirements-dev.txt | 9 +++++---- setup.cfg | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 24b2b39..288ffd3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,8 +1,9 @@ +black click -requests -pytest -pytest-cov codecov flake8 mypy -black +setuptools>=46.4.0 +pytest +pytest-cov +requests diff --git a/setup.cfg b/setup.cfg index acf9512..a4279c4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,6 +54,7 @@ dev = mypy pytest pytest-cov + setuptools>=46.4.0 [options.entry_points] From 7bbe9bdf6ad25ea6879f815c6faf3550e44b17cf Mon Sep 17 00:00:00 2001 From: eggplants Date: Thu, 3 Feb 2022 22:23:04 +0900 Subject: [PATCH 14/14] fix: drop python<=3.6 (#126) from package and CI --- .github/workflows/build_test.yml | 2 +- .github/workflows/unit_test.yml | 12 ++++++------ setup.cfg | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index d5364e6..aac0944 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.6', '3.10'] + python-version: ['3.7', '3.10'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index a076b00..8fd5b95 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9'] + python-version: ['3.10'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -25,14 +25,14 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + pip install '.[dev]' - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 waybackpy/ --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - # flake8 waybackpy/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --per-file-ignores="waybackpy/__init__.py:F401" + flake8 . --count --show-source --statistics + - name: Lint with black + run: | + black . --check --diff # - name: Static type test with mypy # run: | # mypy diff --git a/setup.cfg b/setup.cfg index a4279c4..197b071 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,9 +30,6 @@ classifiers = License :: OSI Approved :: MIT License Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 @@ -41,7 +38,7 @@ classifiers = [options] packages = find: -python_requires = >= 3.4 +python_requires = >= 3.7 install_requires = click requests