Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions b2/_internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import argparse
import contextlib
import functools
import io
import locale
import re
import sys
import textwrap
import unittest.mock

from rst2ansi import rst2ansi
from rich.console import Console
from rich_rst import RestructuredText

try:
getencoding = locale.getencoding
Expand Down Expand Up @@ -127,15 +129,14 @@ def _encode_description(self, value: str):
return textwrap.dedent(value)
else:
encoding = self._get_encoding()
try:
return rst2ansi(value.encode(encoding), output_encoding=encoding)
except SystemError:
# FALLBACK(PARSER): rst2ansi can raise SystemError on Python 3.14+ due to
# buffer overflow bug in get_terminal_size ioctl call.
# See: https://github.com/Backblaze/B2_Command_Line_Tool/issues/1119
# TODO-REMOVE-BY: When rst2ansi is updated or replaced
if encoding == 'ascii':
return textwrap.dedent(value)

buf = io.StringIO()
console = Console(file=buf, color_system='standard')
console.print(RestructuredText(textwrap.dedent(value)))
return buf.getvalue().rstrip()

def _get_short_description(self) -> str:
if not self._raw_description:
return ''
Expand Down
12 changes: 3 additions & 9 deletions b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

import b2sdk
import requests
import rst2ansi
from b2sdk.v3 import (
ALL_CAPABILITIES,
B2_ACCOUNT_INFO_DEFAULT_FILE,
Expand Down Expand Up @@ -421,7 +420,7 @@ class DestinationSseMixin(Described):
Using SSE-C requires providing ``{B2_DESTINATION_SSE_C_KEY_B64_ENV_VAR}`` environment variable,
containing the base64 encoded encryption key.
If ``{B2_DESTINATION_SSE_C_KEY_ID_ENV_VAR}`` environment variable is provided,
it's value will be saved as ``{SSE_C_KEY_ID_FILE_INFO_KEY_NAME}`` in the
its value will be saved as ``{SSE_C_KEY_ID_FILE_INFO_KEY_NAME}`` in the
uploaded file's fileInfo.
"""

Expand Down Expand Up @@ -4292,7 +4291,7 @@ class License(Command): # pragma: no cover
# overrides to the license text extracted by piplicenses.
# Thanks to this set, we make sure the module is still used
# PTable is used on versions below Python 3.11
MODULES_TO_OVERRIDE_LICENSE_TEXT = {'rst2ansi', 'b2sdk'}
MODULES_TO_OVERRIDE_LICENSE_TEXT = {'b2sdk'}

LICENSES = {
'argcomplete': 'https://raw.githubusercontent.com/kislyuk/argcomplete/develop/LICENSE.rst',
Expand Down Expand Up @@ -4445,12 +4444,7 @@ def _fetch_license_from_url(self, url: str) -> str:
def _get_single_license(self, module_dict: dict):
license_ = module_dict['LicenseText']
module_name = module_dict['Name']
if module_name == 'rst2ansi':
# this one module is problematic, we need to extract the license text from its docstring
assert license_ == piplicenses.LICENSE_UNKNOWN # let's make sure they didn't fix it
license_ = rst2ansi.__doc__
assert 'MIT License' in license_ # let's make sure the license is still there
elif module_name == 'b2sdk':
if module_name == 'b2sdk':
license_ = (pathlib.Path(b2sdk.__file__).parent / 'LICENSE').read_text()
else:
license_url = self.LICENSES.get(module_name) or self.LICENSES.get(
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+migrate-from-rst2ansi-to-rich.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace rst2ansi man-page rendering with Rich, fixing Python 3.14+ compatibility issues.
2 changes: 0 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ def run_integration_test(session, pytest_posargs):
'2' if CI else 'auto',
'--log-level',
'INFO',
'-W',
'ignore::DeprecationWarning:rst2ansi.visitor:',
*PYTEST_GLOBAL_ARGS,
*pytest_posargs,
]
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies = [
"tabulate==0.9.0",
"tqdm>=4.65.0,<5",
"platformdirs>=3.11.0,<5",
"rich>=15.0.0",
"rich-rst>=2.0.1",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -116,6 +118,7 @@ authorized_licenses = [
"bsd license",
"new bsd license",
"simplified bsd",
"bsd-2-clause",
"bsd-3-clause",
"apache",
"apache 2.0",
Expand Down
51 changes: 51 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.