diff --git a/docs/contributors/fetch.py b/docs/contributors/fetch.py index ba94c28183..8c3f700d7f 100644 --- a/docs/contributors/fetch.py +++ b/docs/contributors/fetch.py @@ -193,7 +193,7 @@ def load_awesome_people() -> People: def fetch(url: str, params: Optional[Dict[str, str]] = None) -> UserInfo: headers = { 'Accept': 'application/vnd.github.v3+json', - 'Authentication': f'token {GITHUB_TOKEN}' + 'Authentication': f'token {GITHUB_TOKEN}', } for retry in range(1, 6): debug(f'[{retry}/5]', f'{url = }', f'{params = }') diff --git a/docs/contributors/generate.py b/docs/contributors/generate.py index 27470d5672..2dd10e2d9d 100644 --- a/docs/contributors/generate.py +++ b/docs/contributors/generate.py @@ -3,9 +3,8 @@ """ import sys -from jinja2 import Template - from fetch import HERE, load_awesome_people +from jinja2 import Template TPL_FILE = HERE / 'snippet.jinja2' @@ -13,11 +12,11 @@ 'claudiatd', 'jakubroztocil', 'jkbr', - 'isidentical' + 'isidentical', } BOT_ACCOUNTS = { - 'dependabot-sr' + 'dependabot-sr', } IGNORE_ACCOUNTS = HTTPIE_TEAM | BOT_ACCOUNTS diff --git a/extras/packaging/linux/build.py b/extras/packaging/linux/build.py index 9f02136923..35c813f0e5 100644 --- a/extras/packaging/linux/build.py +++ b/extras/packaging/linux/build.py @@ -7,7 +7,7 @@ HTTPIE_DIR = BUILD_DIR.parent.parent.parent EXTRAS_DIR = HTTPIE_DIR / 'extras' -MAN_PAGES_DIR = EXTRAS_DIR / 'man' +MAN_PAGES_DIR = EXTRAS_DIR / 'man' SCRIPT_DIR = BUILD_DIR / Path('scripts') HOOKS_DIR = SCRIPT_DIR / 'hooks' @@ -33,7 +33,7 @@ def build_binaries() -> Iterator[Tuple[str, Path]]: HOOKS_DIR, *extra_args, target_script, - ] + ], ) for executable_path in DIST_DIR.iterdir(): @@ -61,7 +61,7 @@ def build_packages(http_binary: Path, httpie_binary: Path) -> None: # A list of additional dependencies deps = [ 'python3 >= 3.7', - 'python3-pip' + 'python3-pip', ] processed_deps = [ @@ -104,6 +104,5 @@ def main(): binaries['httpie_cli'].rename(DIST_DIR / 'httpie') - if __name__ == '__main__': main() diff --git a/extras/packaging/linux/scripts/hooks/hook-pip.py b/extras/packaging/linux/scripts/hooks/hook-pip.py index 1dac8fb17f..c8c3fb3540 100644 --- a/extras/packaging/linux/scripts/hooks/hook-pip.py +++ b/extras/packaging/linux/scripts/hooks/hook-pip.py @@ -1,12 +1,12 @@ -from pathlib import Path from PyInstaller.utils.hooks import collect_all + def hook(hook_api): for pkg in [ 'pip', 'setuptools', 'distutils', - 'pkg_resources' + 'pkg_resources', ]: datas, binaries, hiddenimports = collect_all(pkg) hook_api.add_datas(datas) diff --git a/extras/profiling/benchmarks.py b/extras/profiling/benchmarks.py index 9d409debbe..bd7e7f023f 100644 --- a/extras/profiling/benchmarks.py +++ b/extras/profiling/benchmarks.py @@ -60,7 +60,8 @@ def log_message(self, *args, **kwargs): @contextmanager def start_server(): """Create a server to serve local files. It will create the - PREDEFINED_FILES through dd.""" + PREDEFINED_FILES through dd. + """ with TemporaryDirectory() as directory: for file_name, (block_size, count) in PREDEFINED_FILES.items(): subprocess.check_call( @@ -179,8 +180,8 @@ def run(self, context: Context) -> pyperf.Benchmark: [ '--print=HBhb', f'--pretty={pretty}', - 'httpbin.org/stream/1000' - ] + 'httpbin.org/stream/1000', + ], ) DownloadRunner('download', '`http --download :/big_file.txt` (3GB)', '3G') @@ -191,7 +192,7 @@ def main() -> None: # benchmarks 3 times to warm up (e.g especially for download benchmark, this # is important). And then 5 actual runs where we record. sys.argv.extend( - ['--worker', '--loops=1', '--warmup=3', '--values=5', '--processes=2'] + ['--worker', '--loops=1', '--warmup=3', '--values=5', '--processes=2'], ) with Context() as context: diff --git a/extras/profiling/run.py b/extras/profiling/run.py index d03827b0b0..560689edb2 100644 --- a/extras/profiling/run.py +++ b/extras/profiling/run.py @@ -44,8 +44,7 @@ from contextlib import contextmanager from dataclasses import dataclass from pathlib import Path -from typing import (IO, Dict, Generator, Iterable, List, Optional, - Tuple) +from typing import IO, Dict, Generator, Iterable, List, Optional, Tuple BENCHMARK_SCRIPT = Path(__file__).parent / 'benchmarks.py' CURRENT_REPO = Path(__file__).parent.parent.parent @@ -119,7 +118,7 @@ def on_repo(self) -> Generator[Path, None, None]: 'wheel', 'pyperf==2.3.0', *self.dependencies, - ] + ], ) # Create a wheel distribution of HTTPie @@ -148,7 +147,7 @@ def on_repo(self) -> Generator[Path, None, None]: def dump_results( results: List[str], file: IO[str], - min_speed: Optional[str] = None + min_speed: Optional[str] = None, ) -> None: for result in results: lines = result.strip().splitlines() @@ -213,7 +212,7 @@ def iterate(env_name, status): results.append(compare( *config.keys(), directory=result_directory, - min_speed=min_speed + min_speed=min_speed, )) dump_results(results, file=file, min_speed=min_speed) @@ -252,7 +251,7 @@ def main() -> None: parser.add_argument( '--min-speed', help='Minimum of speed in percent to consider that a ' - 'benchmark is significant' + 'benchmark is significant', ) parser.add_argument( '--debug', diff --git a/extras/scripts/generate_man_pages.py b/extras/scripts/generate_man_pages.py index 71e0100f39..fb8f66a7a1 100644 --- a/extras/scripts/generate_man_pages.py +++ b/extras/scripts/generate_man_pages.py @@ -1,7 +1,7 @@ import re from contextlib import contextmanager from pathlib import Path -from typing import Optional, Iterator, Iterable +from typing import Iterable, Iterator, Optional import httpie from httpie.cli.definition import options as core_options @@ -9,18 +9,16 @@ from httpie.manager.cli import options as manager_options from httpie.output.ui.rich_help import OptionsHighlighter, to_usage from httpie.output.ui.rich_utils import render_as_string -from httpie.utils import split_iterable - # Escape certain characters so they are rendered properly on # all terminals. # https://man7.org/linux/man-pages/man7/groff_char.7.html ESCAPE_MAP = { - '"': '\[dq]', - "'": '\[aq]', - '~': '\(ti', - '’': "\(ga", - '\\': '\e', + '"': r'\[dq]', + "'": r'\[aq]', + '~': r'\(ti', + '’': r"\(ga", + '\\': r'\e', } ESCAPE_MAP = {ord(key): value for key, value in ESCAPE_MAP.items()} @@ -29,9 +27,10 @@ PROJECT_ROOT = EXTRAS_DIR.parent OPTION_HIGHLIGHT_RE = re.compile( - OptionsHighlighter.highlights[0] + OptionsHighlighter.highlights[0], ) + class ManPageBuilder: def __init__(self): self.source = [] @@ -45,7 +44,7 @@ def title_line( ) -> None: self.source.append( f'.TH {program_name} 1 "{last_edit_date}" ' - f'"{full_name} {program_version}" "{full_name} Manual"' + f'"{full_name} {program_version}" "{full_name} Manual"', ) def set_name(self, program_name: str) -> None: @@ -65,7 +64,7 @@ def format_desc(self, desc: str) -> str: description = OPTION_HIGHLIGHT_RE.sub( # Boldify the option part, but don't remove the prefix (start of the match). lambda match: match[1] + self.boldify(match['option']), - description + description, ) return description @@ -110,9 +109,9 @@ def _escape_and_dedent(text: str) -> str: def to_man_page(program_name: str, spec: ParserSpec, *, is_top_level_cmd: bool = False) -> str: builder = ManPageBuilder() builder.add_comment( - f"This file is auto-generated from the parser declaration " + "This file is auto-generated from the parser declaration " + (f"in {Path(spec.source_file).relative_to(PROJECT_ROOT)} " if spec.source_file else "") - + f"by {Path(__file__).relative_to(PROJECT_ROOT)}." + + f"by {Path(__file__).relative_to(PROJECT_ROOT)}.", ) builder.title_line( @@ -138,7 +137,7 @@ def to_man_page(program_name: str, spec: ParserSpec, *, is_top_level_cmd: bool = if spec.man_page_hint: builder.write(spec.man_page_hint) - for index, group in enumerate(spec.groups, 1): + for _, group in enumerate(spec.groups, 1): with builder.section(group.name): if group.description: builder.write(group.description) @@ -153,7 +152,7 @@ def to_man_page(program_name: str, spec: ParserSpec, *, is_top_level_cmd: bool = if raw_arg.get('is_positional'): # In case of positional arguments, metavar is always equal # to the list of options (e.g `METHOD`). - metavar = None + metavar = None builder.add_options(raw_arg['options'], metavar=metavar) desc = builder.format_desc(raw_arg.get('description', '')) @@ -178,6 +177,5 @@ def main() -> None: stream.write(to_man_page(program_name, spec, **config)) - if __name__ == '__main__': main() diff --git a/httpie/adapters.py b/httpie/adapters.py index 8e2dd7397f..22adae4096 100644 --- a/httpie/adapters.py +++ b/httpie/adapters.py @@ -1,13 +1,14 @@ -from httpie.cli.dicts import HTTPHeadersDict from requests.adapters import HTTPAdapter +from httpie.cli.dicts import HTTPHeadersDict + class HTTPieHTTPAdapter(HTTPAdapter): def build_response(self, req, resp): """Wrap the original headers with the `HTTPHeadersDict` - to preserve multiple headers that have the same name""" - + to preserve multiple headers that have the same name + """ response = super().build_response(req, resp) response.headers = HTTPHeadersDict(getattr(resp, 'headers', {})) return response diff --git a/httpie/cli/argparser.py b/httpie/cli/argparser.py index 9bf09b3b73..625c7caaa0 100644 --- a/httpie/cli/argparser.py +++ b/httpie/cli/argparser.py @@ -9,24 +9,21 @@ from requests.utils import get_netrc_auth -from .argtypes import ( - AuthCredentials, SSLCredentials, KeyValueArgType, - PARSED_DEFAULT_FORMAT_OPTIONS, - parse_auth, - parse_format_options, -) -from .constants import ( - HTTP_GET, HTTP_POST, BASE_OUTPUT_OPTIONS, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT, - OUTPUT_OPTIONS_DEFAULT_OFFLINE, OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED, - OUT_RESP_BODY, PRETTY_MAP, PRETTY_STDOUT_TTY_ONLY, RequestType, - SEPARATOR_CREDENTIALS, - SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_GROUP_DATA_ITEMS, URL_SCHEME_RE, -) -from .exceptions import ParseError -from .requestitems import RequestItems from ..context import Environment from ..plugins.registry import plugin_manager from ..utils import ExplicitNullAuth, get_content_type +from .argtypes import (PARSED_DEFAULT_FORMAT_OPTIONS, AuthCredentials, + KeyValueArgType, SSLCredentials, parse_auth, + parse_format_options) +from .constants import (BASE_OUTPUT_OPTIONS, HTTP_GET, HTTP_POST, + OUT_RESP_BODY, OUTPUT_OPTIONS, OUTPUT_OPTIONS_DEFAULT, + OUTPUT_OPTIONS_DEFAULT_OFFLINE, + OUTPUT_OPTIONS_DEFAULT_STDOUT_REDIRECTED, PRETTY_MAP, + PRETTY_STDOUT_TTY_ONLY, SEPARATOR_CREDENTIALS, + SEPARATOR_GROUP_ALL_ITEMS, SEPARATOR_GROUP_DATA_ITEMS, + URL_SCHEME_RE, RequestType) +from .exceptions import ParseError +from .requestitems import RequestItems class HTTPieHelpFormatter(RawDescriptionHelpFormatter): @@ -72,7 +69,7 @@ def add_usage(self, usage, actions, groups, prefix=None): usage, displayed_actions, groups, - prefix="usage:\n " + prefix="usage:\n ", ) @@ -91,10 +88,10 @@ def parse_args( self, env: Environment, args=None, - namespace=None + namespace=None, ) -> argparse.Namespace: self.env = env - self.args, no_options = self.parse_known_args(args, namespace) + self.args, _ = self.parse_known_args(args, namespace) if self.args.debug: self.args.traceback = True self.has_stdin_data = ( @@ -117,7 +114,7 @@ def _print_message(self, message, file=None): file = { sys.stdout: env.stdout, sys.stderr: env.stderr, - None: env.stderr + None: env.stderr, }.get(file, file) if not hasattr(file, 'buffer') and isinstance(message, str): @@ -152,7 +149,7 @@ def parse_args( self, env: Environment, args=None, - namespace=None + namespace=None, ) -> argparse.Namespace: self.env = env self.env.args = namespace = namespace or argparse.Namespace() @@ -229,7 +226,6 @@ def _setup_standard_streams(self): Modify `env.stdout` and `env.stdout_isatty` based on args, if needed. """ - self.args.output_file_specified = bool(self.args.output_file) if self.args.download: # FIXME: Come up with a cleaner solution. @@ -295,7 +291,7 @@ def _process_auth(self): key=username, value=password, sep=SEPARATOR_CREDENTIALS, - orig=SEPARATOR_CREDENTIALS.join([username, password]) + orig=SEPARATOR_CREDENTIALS.join([username, password]), ) if self.args.auth is not None or auth_type_set: @@ -313,7 +309,7 @@ def _process_auth(self): key=netrc_credentials[0], value=netrc_credentials[1], sep=SEPARATOR_CREDENTIALS, - orig=SEPARATOR_CREDENTIALS.join(netrc_credentials) + orig=SEPARATOR_CREDENTIALS.join(netrc_credentials), ) if plugin.auth_require and self.args.auth is None: @@ -338,7 +334,7 @@ def _process_auth(self): # Non-tty stdin read by now self.error( 'Unable to prompt for passwords because' - ' --ignore-stdin is set.' + ' --ignore-stdin is set.', ) credentials.prompt_password(url.netloc) @@ -479,7 +475,7 @@ def _parse_items(self): self.error("Can't read request from multiple files") request_file = file - fn, fd, ct = request_file + fn, fd, _ = request_file self.args.files = {} self._body_from_file(fd) @@ -569,11 +565,12 @@ def print_manual(self): with self.env.rich_console.pager(): self.env.rich_console.print( text, - highlight=False + highlight=False, ) def print_usage(self, file): from rich.text import Text + from httpie.output.ui import rich_help whitelist = set() @@ -597,7 +594,8 @@ def print_usage(self, file): def error(self, message): """Prints a usage message incorporating the message to stderr and - exits.""" + exits. + """ self.print_usage(sys.stderr) self.env.rich_error_console.print( dedent( @@ -607,7 +605,7 @@ def error(self, message): [bold]for more information[/bold]: run '{self.prog} --help' or visit https://httpie.io/docs/cli - '''.rstrip() - ) + '''.rstrip(), + ), ) self.exit(2) diff --git a/httpie/cli/argtypes.py b/httpie/cli/argtypes.py index 8f19c3c51e..083271e789 100644 --- a/httpie/cli/argtypes.py +++ b/httpie/cli/argtypes.py @@ -5,8 +5,8 @@ from copy import deepcopy from typing import List, Optional, Union -from .constants import DEFAULT_FORMAT_OPTIONS, SEPARATOR_CREDENTIALS from ..sessions import VALID_SESSION_NAME_PATTERN +from .constants import DEFAULT_FORMAT_OPTIONS, SEPARATOR_CREDENTIALS class KeyValueArg: @@ -184,7 +184,7 @@ def __call__(self, s): key=s, value=None, sep=SEPARATOR_CREDENTIALS, - orig=s + orig=s, ) @@ -245,7 +245,7 @@ def parse_format_options(s: str, defaults: Optional[dict]) -> dict: 'invalid value' f' {value!r} in {option!r}' f' (expected {default_type.__name__}' - f' got {parsed_type.__name__})' + f' got {parsed_type.__name__})', ) options[section][key] = parsed_value diff --git a/httpie/cli/constants.py b/httpie/cli/constants.py index 09ca19e4af..573d5173ad 100644 --- a/httpie/cli/constants.py +++ b/httpie/cli/constants.py @@ -4,7 +4,6 @@ import enum import re - URL_SCHEME_RE = re.compile(r'^[a-z][a-z0-9.+-]*://', re.IGNORECASE) HTTP_POST = 'POST' @@ -32,7 +31,7 @@ SEPARATOR_DATA_RAW_JSON, SEPARATOR_FILE_UPLOAD, SEPARATOR_DATA_EMBED_FILE_CONTENTS, - SEPARATOR_DATA_EMBED_RAW_JSON_FILE + SEPARATOR_DATA_EMBED_RAW_JSON_FILE, }) SEPARATORS_GROUP_MULTIPART = frozenset({ @@ -101,7 +100,7 @@ class PrettyOptions(enum.Enum): 'all': ['format', 'colors'], 'colors': ['colors'], 'format': ['format'], - 'none': [] + 'none': [], } PRETTY_STDOUT_TTY_ONLY = PrettyOptions.STDOUT_TTY_ONLY diff --git a/httpie/cli/definition.py b/httpie/cli/definition.py index 0e5f91edf7..7d4e6dcbcd 100644 --- a/httpie/cli/definition.py +++ b/httpie/cli/definition.py @@ -16,7 +16,8 @@ SORTED_FORMAT_OPTIONS_STRING, UNSORTED_FORMAT_OPTIONS_STRING, RequestType) from httpie.cli.options import ParserSpec, Qualifiers, to_argparse -from httpie.output.formatters.colors import (AUTO_STYLE, DEFAULT_STYLE, BUNDLED_STYLES, +from httpie.output.formatters.colors import (AUTO_STYLE, BUNDLED_STYLES, + DEFAULT_STYLE, get_available_styles) from httpie.plugins.builtin import BuiltinAuthPlugin from httpie.plugins.registry import plugin_manager @@ -32,7 +33,7 @@ Suggestions and bug reports are greatly appreciated: https://github.com/httpie/httpie/issues """, - source_file=__file__ + source_file=__file__, ) @@ -182,14 +183,14 @@ short_help=( 'Similar to --form, but always sends a multipart/form-data ' 'request (i.e., even without files).' - ) + ), ) content_types.add_argument( '--boundary', short_help=( 'Specify a custom boundary string for multipart/form-data requests. ' 'Only has effect only together with --form.' - ) + ), ) content_types.add_argument( '--raw', @@ -311,10 +312,10 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): # The closest approx. of the documented resetting to default via --no-