Skip to content

Commit 5cbfffc

Browse files
authored
Limit line length in src/briefcase comments (ruff E501) (#2526)
1 parent 8ea4a0e commit 5cbfffc

24 files changed

Lines changed: 134 additions & 104 deletions

File tree

changes/2526.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Comments in ``src/briefcase`` now have a maximum line length of 88 characters (ruff rule ``E501``).

src/briefcase/commands/base.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,20 +1090,21 @@ def update_cookiecutter_cache(self, template: str, branch="master"):
10901090
self.tools.shutil.rmtree(cached_template)
10911091
raise
10921092
except self.tools.git.exc.GitError as e:
1093-
# The clone failed; to make sure the repo is in a clean state, clean up
1094-
# any partial remnants of this initial clone.
1093+
# The clone failed; to make sure the repo is in a clean state,
1094+
# clean up any partial remnants of this initial clone.
10951095
# If we're getting a GitError, we know the directory must exist.
10961096
self.tools.shutil.rmtree(cached_template)
10971097
git_fatal_message = re.findall(
10981098
r"(?<=fatal: ).*?$", e.stderr, flags=re.DOTALL
10991099
)
11001100
if git_fatal_message:
1101-
# GitError captures stderr with single quotes. Because the regex above
1102-
# takes everything after git's "fatal" message, we need to strip that final single quote.
1101+
# GitError captures stderr with single quotes. Because the regex
1102+
# above takes everything after git's "fatal" message, we need to
1103+
# strip that final single quote.
11031104
hint = git_fatal_message[0].rstrip("'").strip()
11041105

1105-
# git is inconsistent with capitalisation of the first word of the message
1106-
# and about periods at the end of the message.
1106+
# git is inconsistent with capitalization of the first word of
1107+
# the message and about periods at the end of the message.
11071108
hint = f"{hint[0].upper()}{hint[1:]}{'' if hint[-1] == '.' else '.'}"
11081109
else:
11091110
hint = (
@@ -1197,9 +1198,11 @@ def _generate_template(self, template, branch, output_path, extra_context):
11971198
no_input=True,
11981199
output_dir=str(output_path),
11991200
checkout=branch,
1200-
# Use a copy to prevent changes propagating among tests while test suite is running
1201+
# Use a copy to prevent changes propagating among tests
1202+
# while the test suite is running
12011203
extra_context=extra_context.copy(),
1202-
# Store replay data in the Briefcase template cache instead of ~/.cookiecutter_replay
1204+
# Store replay data in the Briefcase template cache
1205+
# instead of ~/.cookiecutter_replay
12031206
default_config={"replay_dir": str(self.template_cache_path(".replay"))},
12041207
)
12051208
except subprocess.CalledProcessError as e:
@@ -1233,7 +1236,8 @@ def generate_template(
12331236

12341237
extra_context = extra_context.copy()
12351238
# Additional context that can be used for the Briefcase template pyproject.toml
1236-
# header to include the version of Briefcase as well as the source of the template.
1239+
# header to include the version of Briefcase as well as the source of the
1240+
# template.
12371241
extra_context.update(
12381242
{
12391243
"template_source": template,

src/briefcase/commands/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def __call__(
110110
**options,
111111
) -> dict | None:
112112
# Has the user requested an invalid set of options?
113-
# This can't be done with argparse, because it isn't a simple mutually exclusive group.
113+
# This can't be done with argparse because it isn't
114+
# a simple mutually exclusive group.
114115
if no_update:
115116
if update:
116117
raise BriefcaseCommandError(

src/briefcase/commands/convert.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ def get_license_hint(self) -> tuple[str | None, str]:
522522
intro = "What license do you want to use for this project's code? "
523523
default = None
524524

525-
# If there is license information in the pyproject.toml file, use that, otherwise check the license file
525+
# If there is license information in the pyproject.toml file, use that,
526+
# otherwise check the license file
526527
if "text" in self.pep621_data.get("license", {}):
527528
default = self.get_license_from_text(self.pep621_data["license"]["text"])
528529
default_source = "the PEP621 formatted pyproject.toml"
@@ -638,9 +639,10 @@ def merge_or_copy_pyproject(self, briefcase_config_file: Path) -> None:
638639
if pyproject_file.exists():
639640
pep621_pyproject = pyproject_file.read_text(encoding="utf-8")
640641

641-
# The pyproject.toml file in the target directory has no briefcase keys, so it's
642-
# safe to copy-paste the text, and that way also keep formatting and comments.
643-
# We merge it this way to preserve comments in the original pyproject.toml file
642+
# The pyproject.toml file in the target directory has no briefcase keys, so
643+
# it's safe to copy-paste the text, and that way also keep formatting and
644+
# comments. We merge it this way to preserve comments in the original
645+
# pyproject.toml file
644646
briefcase_comment = "# content below this line added by briefcase convert"
645647
merged_pyproject = (
646648
f"{pep621_pyproject}\n\n\n{briefcase_comment}\n{briefcase_pyproject}"

src/briefcase/commands/create.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def generate_app_template(self, app: AppConfig):
240240
# Ensure the output format is in the case we expect
241241
"format": self.output_format.lower(),
242242
# Properties of the generating environment
243-
# The full Python version string, including minor and dev/a/b/c suffixes (e.g., 3.11.0rc2)
243+
# The full Python version string, including minor and dev/a/b/c suffixes
244+
# (e.g., 3.11.0rc2)
244245
"python_version": platform.python_version(),
245246
# The host architecture
246247
"host_arch": self.tools.host_arch,
@@ -938,8 +939,9 @@ def create_app(self, app: AppConfig, **options):
938939
self.console.info("Generating application template...", prefix=app.app_name)
939940
self.generate_app_template(app=app)
940941

941-
# External apps (apps that define 'external_package_path') need the packaging metadata
942-
# from the template, but not the app content, dependencies, support package etc.
942+
# External apps (apps that define 'external_package_path') need the packaging
943+
# metadata from the template, but not the app content, dependencies, support
944+
# package, etc.
943945
if app.external_package_path:
944946
self.console.info("Removing generated app content...", prefix=app.app_name)
945947
self.tools.shutil.rmtree(self.bundle_package_path(app))

src/briefcase/commands/dev.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class DevCommand(RunAppMixin, BaseCommand):
2121
output_format = ""
2222
description = "Run a Briefcase project in the dev environment."
2323

24-
# On macOS CoreFoundation/NSApplication will do its own independent parsing of argc/argv.
25-
# This means that whatever we pass to the Python interpreter on start-up will also be
26-
# visible to NSApplication which will interpret things like `-u` (used to make I/O
27-
# unbuffered in CPython) as `-u [URL]` (a request to open a document by URL). This is,
28-
# rather patently, Not Good.
29-
# To avoid this causing unwanted hilarity, we use environment variables to configure the
30-
# Python interpreter rather than command-line options.
24+
# On macOS CoreFoundation/NSApplication will do its own independent parsing of
25+
# argc/argv. This means that whatever we pass to the Python interpreter on start-up
26+
# will also be visible to NSApplication which will interpret things like `-u` (used
27+
# to make I/O unbuffered in CPython) as `-u [URL]` (a request to open a document by
28+
# URL). This is, rather patently, Not Good.
29+
# To avoid this causing unwanted hilarity, we use environment variables to configure
30+
# the Python interpreter rather than command-line options.
3131
DEV_ENVIRONMENT: Mapping[str, str] = {
3232
# Equivalent of passing "-u"
3333
"PYTHONUNBUFFERED": "1",

src/briefcase/commands/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ def __call__(self, line):
5555
if filtered is None:
5656
return
5757

58-
# If there's a cleaned line, we can determine if it should be included in analysis
58+
# If there's a cleaned line, we can determine if it should be
59+
# included in analysis
5960
clean_line, included = filtered
6061
else:
6162
# If we don't perform cleaning, we assume all content is potentially
62-
# Python, and should be included in analysis
63+
# Python and should be included in analysis
6364
clean_line = line
6465
included = True
6566

src/briefcase/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def validate_document_type_config(document_type_id, document_type):
174174
else:
175175
uti = None
176176

177-
# If an UTI is provided in LSItemContentTypes, that takes precedence over a MIME type
177+
# If an UTI is provided in LSItemContentTypes,
178+
# that takes precedence over a MIME type
178179
if is_uti_core_type(uti) or ((uti := mime_type_to_uti(mime_type)) is not None):
179180
macOS.setdefault("is_core_type", True)
180181
macOS.setdefault("LSItemContentTypes", [uti])

src/briefcase/console.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ def __init__(
186186
self.save_log = False
187187
# flag set by exceptions to skip writing the log; save_log takes precedence.
188188
self.skip_log = False
189-
# Rich stacktraces of exceptions for logging to file.
190-
# A list of tuples containing a label for the thread context, and the Trace object
189+
# Rich stacktraces of exceptions for logging to a file.
190+
# A list of tuples containing a label for the thread context,
191+
# and the Trace object
191192
self.stacktraces: list[tuple[str, Trace]] = []
192193
# functions to run for additional logging if creating a logfile
193194
self.log_file_extras: list[Callable[[], object]] = []
@@ -511,13 +512,17 @@ def _build_log(self, command) -> str:
511512
f"Platform: {platform.platform(aliased=True)}\n"
512513
"\n"
513514
f"Python exe: {sys.executable}\n"
514-
# replace line breaks with spaces (use chr(10) since '\n' isn't allowed in f-strings...)
515+
# replace line breaks with spaces
516+
# (use chr(10) since '\n' isn't allowed in f-strings...)
515517
f"Python version: {sys.version.replace(chr(10), ' ')}\n"
516518
# sys.real_prefix was used in older versions of virtualenv.
517-
# sys.base_prefix is always the python exe's original site-specific directory (e.g. /usr/local).
518-
# sys.prefix is updated (from base_prefix's value) to the virtual env's site-specific directory.
519+
# sys.base_prefix is always the python exe's original site-specific
520+
# directory (e.g. /usr/local).
521+
# sys.prefix is updated (from base_prefix's value) to the virtual env's
522+
# site-specific directory.
519523
f"Virtual env: {hasattr(sys, 'real_prefix') or sys.base_prefix != sys.prefix}\n"
520-
# for conda, prefix and base_prefix are likely the same but contain a conda-meta dir.
524+
# for conda, prefix and base_prefix are likely the same
525+
# but contain a conda-meta dir.
521526
f"Conda env: {(Path(sys.prefix) / 'conda-meta').exists()}\n"
522527
"\n"
523528
f"Briefcase: {__version__}\n"
@@ -561,7 +566,7 @@ def is_color_enabled(self):
561566
the NO_COLOR environment variable; alternatively, the derived color system for
562567
the terminal is influenced by attributes of the platform as well as FORCE_COLOR.
563568
"""
564-
# no_color has precedence since color_system can be set even if color is disabled
569+
# no_color has precedence: color_system can be set even if color is disabled
565570
if self._console_impl.no_color:
566571
return False
567572
else:
@@ -632,7 +637,8 @@ def wait_bar(
632637
self._wait_bar.start()
633638
yield NotDeadYet(console=self)
634639
except BaseException as e:
635-
# capture BaseException so message is left on the screen even if user sends CTRL+C
640+
# capture BaseException so the message is left on the screen
641+
# even if the user sends CTRL+C
636642
error_message = "aborted" if isinstance(e, KeyboardInterrupt) else "errored"
637643
self.print(
638644
f"{message} {error_message}", markup=markup, show=show_outcome_message

src/briefcase/integrations/android_sdk.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ def verify_install(
292292
"""
293293
)
294294
elif sdk.cmdline_tools_path.parent.exists():
295-
# a cmdline-tools directory exists but the required version isn't installed.
296-
# try to install the required version using the 'latest' version.
295+
# a cmdline-tools directory exists,
296+
# but the required version isn't installed.
297+
# Try to install the required version using the 'latest' version.
297298
if not sdk.install_cmdline_tools():
298299
sdk = None
299300
tools.console.warning(
@@ -412,8 +413,10 @@ def install(self):
412413
# So, the unpacking process is:
413414
#
414415
# 1. Make a <sdk_path>/cmdline-tools folder
415-
# 2. Unpack the zip file into that folder, creating <sdk_path>/cmdline-tools/cmdline-tools
416-
# 3. Move <sdk_path>/cmdline-tools/cmdline-tools to <sdk_path>/cmdline-tools/<cmdline-tools version>
416+
# 2. Unpack the zip file into that folder, creating
417+
# <sdk_path>/cmdline-tools/cmdline-tools
418+
# 3. Move <sdk_path>/cmdline-tools/cmdline-tools to
419+
# <sdk_path>/cmdline-tools/<cmdline-tools version>
417420

418421
with self.tools.console.wait_bar(
419422
f"Installing Android SDK Command-Line Tools {self.SDK_MANAGER_VER}..."
@@ -1474,9 +1477,10 @@ def run(self, *arguments: SubprocessArgT, quiet: int = 0) -> str:
14741477
[self.tools.android_sdk.adb_path, "-s", self.device, *arguments],
14751478
quiet=quiet,
14761479
)
1477-
# add returns status code 0 in the case of failure. The only tangible evidence
1478-
# of failure is the message "Failure [INSTALL_FAILED_OLDER_SDK]" in the,
1479-
# console output; so if that message exists in the output, raise an exception.
1480+
# add returns status code 0 in the case of failure.
1481+
# The only tangible evidence of failure is the message
1482+
# "Failure [INSTALL_FAILED_OLDER_SDK]" in the console output;
1483+
# so if that message exists in the output, raise an exception.
14801484
if "Failure [INSTALL_FAILED_OLDER_SDK]" in output:
14811485
raise BriefcaseCommandError(
14821486
"Your device doesn't meet the minimum SDK requirements of this app."
@@ -1529,9 +1533,9 @@ def start_app(self, package: str, activity: str, passthrough: list[str]):
15291533
:returns: `None` on success; raises an exception on failure.
15301534
"""
15311535
try:
1532-
# `am start` also accepts string array extras, but we pass the arguments as a
1533-
# single JSON string, because JSON deals with edge cases like whitespace and
1534-
# escaping in a reliable and well-documented way.
1536+
# `am start` also accepts string array extras, but we pass the arguments as
1537+
# a single JSON string, because JSON deals with edge cases like whitespace
1538+
# and escaping in a reliable and well-documented way.
15351539
output = self.run(
15361540
"shell",
15371541
"am",
@@ -1718,11 +1722,11 @@ def pidof(self, package: str, **kwargs) -> str | None:
17181722
:returns: The PID of the given app as a string, or None if it isn't
17191723
running.
17201724
"""
1721-
# The pidof command is available since API level 24. The level 23 emulator image also
1722-
# includes it, but it doesn't work correctly (it returns all processes).
1725+
# The pidof command is available since API level 24. The level 23 emulator image
1726+
# also includes it, but it doesn't work correctly (it returns all processes).
17231727
try:
1724-
# Exit status is unreliable: some devices (e.g. Nexus 4) return 0 even when no
1725-
# process was found.
1728+
# Exit status is unreliable: some devices (e.g. Nexus 4) return 0
1729+
# even when no process was found.
17261730
return self.run("shell", "pidof", "-s", package, **kwargs).strip() or None
17271731
except subprocess.CalledProcessError:
17281732
return None

0 commit comments

Comments
 (0)