From bb0bf8f0c79c31114a615cb201505de3fae15044 Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Tue, 7 Dec 2021 15:30:56 -0800 Subject: Standardize on double quotes --- setup.py | 74 ++++++++++++++++++++++++------------------------ test/test_validations.py | 32 ++++++++++----------- wikiget/__init__.py | 10 +++---- wikiget/dl.py | 13 +++++---- wikiget/validations.py | 6 ++-- wikiget/version.py | 2 +- wikiget/wikiget.py | 64 ++++++++++++++++++++--------------------- 7 files changed, 101 insertions(+), 100 deletions(-) diff --git a/setup.py b/setup.py index ab809e2..a10c111 100644 --- a/setup.py +++ b/setup.py @@ -23,56 +23,56 @@ from os import path from setuptools import setup, find_packages here = path.abspath(path.dirname(__file__)) -with open(path.join(here, 'README.md'), 'r') as fr: +with open(path.join(here, "README.md"), "r") as fr: long_description = fr.read() version_file = {} -with open(path.join(here, 'wikiget', 'version.py'), 'r') as fv: +with open(path.join(here, "wikiget", "version.py"), "r") as fv: exec(fv.read(), version_file) setup( - name='wikiget', - version=version_file['__version__'], - author='Cody Logan', - author_email='clpo13@gmail.com', - description='CLI tool for downloading files from MediaWiki sites', + name="wikiget", + version=version_file["__version__"], + author="Cody Logan", + author_email="clpo13@gmail.com", + description="CLI tool for downloading files from MediaWiki sites", long_description=long_description, - long_description_content_type='text/markdown', - url='https://github.com/clpo13/wikiget', - keywords='commons download mediawiki wikimedia wikipedia', + long_description_content_type="text/markdown", + url="https://github.com/clpo13/wikiget", + keywords="commons download mediawiki wikimedia wikipedia", packages=find_packages(), classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Intended Audience :: End Users/Desktop', - 'License :: OSI Approved :: GNU General Public License v3 or later ' - '(GPLv3+)', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Topic :: Internet', - 'Topic :: Internet :: WWW/HTTP', - 'Topic :: Multimedia', - 'Topic :: Multimedia :: Graphics', - 'Topic :: Multimedia :: Sound/Audio', - 'Topic :: Multimedia :: Video', - 'Topic :: Utilities', + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: End Users/Desktop", + "License :: OSI Approved :: GNU General Public License v3 or later " + "(GPLv3+)", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Topic :: Internet", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Multimedia", + "Topic :: Multimedia :: Graphics", + "Topic :: Multimedia :: Sound/Audio", + "Topic :: Multimedia :: Video", + "Topic :: Utilities", ], - python_requires='>=3.6', - install_requires=['mwclient>=0.10.0', 'requests', 'tqdm'], - setup_requires=['pytest-runner'], - tests_require=['pytest', 'pytest-cov'], + python_requires=">=3.6", + install_requires=["mwclient>=0.10.0", "requests", "tqdm"], + setup_requires=["pytest-runner"], + tests_require=["pytest", "pytest-cov"], project_urls={ - 'Bug Reports': 'https://github.com/clpo13/wikiget/issues', + "Bug Reports": "https://github.com/clpo13/wikiget/issues", }, entry_points={ - 'console_scripts': [ - 'wikiget=wikiget.wikiget:main', + "console_scripts": [ + "wikiget=wikiget.wikiget:main", ], }, ) diff --git a/test/test_validations.py b/test/test_validations.py index 5b7d4fc..8dd4d6d 100644 --- a/test/test_validations.py +++ b/test/test_validations.py @@ -23,8 +23,8 @@ def test_invalid_site_input(): """ Invalid site strings should not return regex match objects. """ - invalid_input = ['example.com', 'vim.wikia.com', - 'en.wikipedia.com', 'en.wikimpedia.org'] + invalid_input = ["example.com", "vim.wikia.com", + "en.wikipedia.com", "en.wikimpedia.org"] for i in invalid_input: site_match = valid_site(i) assert site_match is None @@ -34,8 +34,8 @@ def test_valid_site_input(): """ Valid site strings should return regex match objects. """ - valid_input = ['en.wikipedia.org', 'commons.wikimedia.org', - 'de.wikipedia.org', 'meta.wikimedia.org'] + valid_input = ["en.wikipedia.org", "commons.wikimedia.org", + "de.wikipedia.org", "meta.wikimedia.org"] for i in valid_input: site_match = valid_site(i) assert site_match is not None @@ -46,20 +46,20 @@ def test_file_regex(): File regex should return a match object with match groups corresponding to the file prefix and name. """ - i = 'File:Example.jpg' + i = "File:Example.jpg" file_match = valid_file(i) assert file_match is not None - assert file_match.group(0) == 'File:Example.jpg' # entire match - assert file_match.group(1) == 'File:' # first group - assert file_match.group(2) == 'Example.jpg' # second group + assert file_match.group(0) == "File:Example.jpg" # entire match + assert file_match.group(1) == "File:" # first group + assert file_match.group(2) == "Example.jpg" # second group def test_invalid_file_input(): """ Invalid file strings should not return regex match objects. """ - invalid_input = ['file:example', 'example.jpg', 'Foo Bar.gif', - 'Fil:Example.jpg'] + invalid_input = ["file:example", "example.jpg", "Foo Bar.gif", + "Fil:Example.jpg"] for i in invalid_input: file_match = valid_file(i) assert file_match is None @@ -69,9 +69,9 @@ def test_valid_file_input(): """ Valid file strings should return regex match objects. """ - valid_input = ['Image:example.jpg', 'file:example.jpg', - 'File:example.file-01.jpg', 'FILE:FOO.BMP', - 'File:ß handwritten sample.gif', 'File:A (1).jpeg'] + valid_input = ["Image:example.jpg", "file:example.jpg", + "File:example.file-01.jpg", "FILE:FOO.BMP", + "File:ß handwritten sample.gif", "File:A (1).jpeg"] for i in valid_input: file_match = valid_file(i) assert file_match is not None @@ -81,9 +81,9 @@ def test_verify_hash(tmp_path): """ Confirm that verify_hash returns the proper SHA1 hash. """ - file_name = 'testfile' - file_contents = 'foobar' - file_sha1 = '8843d7f92416211de9ebb963ff4ce28125932878' + file_name = "testfile" + file_contents = "foobar" + file_sha1 = "8843d7f92416211de9ebb963ff4ce28125932878" tmp_file = tmp_path / file_name tmp_file.write_text(file_contents) diff --git a/wikiget/__init__.py b/wikiget/__init__.py index 8437ebf..4adcae3 100644 --- a/wikiget/__init__.py +++ b/wikiget/__init__.py @@ -1,5 +1,5 @@ # wikiget - CLI tool for downloading files from Wikimedia sites -# Copyright (C) 2018, 2019, 2020 Cody Logan and contributors +# Copyright (C) 2018-2021 Cody Logan and contributors # SPDX-License-Identifier: GPL-3.0-or-later # # Wikiget is free software: you can redistribute it and/or modify @@ -22,7 +22,7 @@ from .version import __version__ as wikiget_version # set some global constants BLOCKSIZE = 65536 CHUNKSIZE = 1024 -DEFAULT_SITE = 'commons.wikimedia.org' -DEFAULT_PATH = '/w/' -USER_AGENT = ('wikiget/{} (https://github.com/clpo13/wikiget) ' - 'mwclient/{}'.format(wikiget_version, mwclient_version)) +DEFAULT_SITE = "commons.wikimedia.org" +DEFAULT_PATH = "/w/" +USER_AGENT = (f"wikiget/{wikiget_version} (https://github.com/clpo13/wikiget) " + f"mwclient/{mwclient_version}") diff --git a/wikiget/dl.py b/wikiget/dl.py index 856d8ca..8f32218 100644 --- a/wikiget/dl.py +++ b/wikiget/dl.py @@ -102,11 +102,12 @@ def download(dl, args): if file.imageinfo != {}: # file exists either locally or at a common repository, # like Wikimedia Commons - file_url = file.imageinfo['url'] - file_size = file.imageinfo['size'] - file_sha1 = file.imageinfo['sha1'] + file_url = file.imageinfo["url"] + file_size = file.imageinfo["size"] + file_sha1 = file.imageinfo["sha1"] - filename_log = f"Downloading '{filename}' ({file_size} bytes) from {site.host}" + filename_log = (f"Downloading '{filename}' ({file_size} bytes) " + f"from {site.host}") if args.output: filename_log += f" to '{dest}'" logging.info(filename_log) @@ -117,7 +118,7 @@ def download(dl, args): "(use -f to ignore)") else: try: - fd = open(dest, 'wb') + fd = open(dest, "wb") except IOError as e: logging.error("File could not be written. " "The following error was encountered:") @@ -130,7 +131,7 @@ def download(dl, args): else: leave_bars = False with tqdm(leave=leave_bars, total=file_size, - unit='B', unit_scale=True, + unit="B", unit_scale=True, unit_divisor=CHUNKSIZE) as progress_bar: with fd: res = site.connection.get(file_url, stream=True) diff --git a/wikiget/validations.py b/wikiget/validations.py index 20ef74f..bd99570 100644 --- a/wikiget/validations.py +++ b/wikiget/validations.py @@ -31,7 +31,7 @@ def valid_file(search_string): """ # second group could also restrict to file extensions with three or more # letters with ([^/\r\n\t\f\v]+\.\w{3,}) - file_regex = re.compile(r'(File:|Image:)([^/\r\n\t\f\v]+\.\w+)$', re.I) + file_regex = re.compile(r"(File:|Image:)([^/\r\n\t\f\v]+\.\w+)$", re.I) return file_regex.search(search_string) @@ -44,7 +44,7 @@ def valid_site(search_string): :param search_string: string to validate :returns: a regex Match object if there's a match or None otherwise """ - site_regex = re.compile(r'wiki[mp]edia\.org$', re.I) + site_regex = re.compile(r"wiki[mp]edia\.org$", re.I) return site_regex.search(search_string) @@ -56,7 +56,7 @@ def verify_hash(filename): :return: hash digest """ hasher = hashlib.sha1() - with open(filename, 'rb') as dl: + with open(filename, "rb") as dl: buf = dl.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) diff --git a/wikiget/version.py b/wikiget/version.py index 93b60a1..dd9b22c 100644 --- a/wikiget/version.py +++ b/wikiget/version.py @@ -1 +1 @@ -__version__ = '0.5.1' +__version__ = "0.5.1" diff --git a/wikiget/wikiget.py b/wikiget/wikiget.py index 6a537ba..a8679c9 100644 --- a/wikiget/wikiget.py +++ b/wikiget/wikiget.py @@ -44,42 +44,42 @@ def main(): conditions. There is NO WARRANTY, to the extent permitted by law. """) - parser.add_argument('FILE', help=""" + parser.add_argument("FILE", help=""" name of the file to download with the File: prefix, or the URL of its file description page """) - parser.add_argument('-V', '--version', action='version', - version=f'%(prog)s {wikiget_version}') + parser.add_argument("-V", "--version", action="version", + version=f"%(prog)s {wikiget_version}") message_options = parser.add_mutually_exclusive_group() - message_options.add_argument('-q', '--quiet', - help='suppress warning messages', - action='store_true') - message_options.add_argument('-v', '--verbose', - help='print detailed information; ' - 'use -vv for even more detail', - action='count', default=0) - parser.add_argument('-f', '--force', - help='force overwriting existing files', - action='store_true') - parser.add_argument('-s', '--site', default=DEFAULT_SITE, - help='MediaWiki site to download from ' - '(default: %(default)s)') - parser.add_argument('-p', '--path', default=DEFAULT_PATH, - help='MediaWiki site path, where api.php is located ' - '(default: %(default)s)') - parser.add_argument('--username', default='', - help='MediaWiki site username, for private wikis') - parser.add_argument('--password', default='', - help='MediaWiki site password, for private wikis') + message_options.add_argument("-q", "--quiet", + help="suppress warning messages", + action="store_true") + message_options.add_argument("-v", "--verbose", + help="print detailed information; " + "use -vv for even more detail", + action="count", default=0) + parser.add_argument("-f", "--force", + help="force overwriting existing files", + action="store_true") + parser.add_argument("-s", "--site", default=DEFAULT_SITE, + help="MediaWiki site to download from " + "(default: %(default)s)") + parser.add_argument("-p", "--path", default=DEFAULT_PATH, + help="MediaWiki site path, where api.php is located " + "(default: %(default)s)") + parser.add_argument("--username", default="", + help="MediaWiki site username, for private wikis") + parser.add_argument("--password", default="", + help="MediaWiki site password, for private wikis") output_options = parser.add_mutually_exclusive_group() - output_options.add_argument('-o', '--output', - help='write download to OUTPUT') - output_options.add_argument('-a', '--batch', - help='treat FILE as a textfile containing ' - 'multiple files to download, one URL or ' - 'filename per line', action='store_true') - parser.add_argument('-l', '--logfile', default='', - help='save log output to LOGFILE') + output_options.add_argument("-o", "--output", + help="write download to OUTPUT") + output_options.add_argument("-a", "--batch", + help="treat FILE as a textfile containing " + "multiple files to download, one URL or " + "filename per line", action="store_true") + parser.add_argument("-l", "--logfile", default="", + help="save log output to LOGFILE") args = parser.parse_args() @@ -131,7 +131,7 @@ def main(): logging.info(f"Using batch file '{input_file}'.") try: - fd = open(input_file, 'r') + fd = open(input_file, "r") except IOError as e: logging.error("File could not be read. " "The following error was encountered:") -- cgit v1.2.3