Skip to content

Commit

Permalink
style: paragraph -> stanza, repositories -> repos
Browse files Browse the repository at this point in the history
  • Loading branch information
james-garner-canonical committed Dec 4, 2024
1 parent 865aad8 commit b993c54
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/charms/operator_libs_linux/v0/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ def load_deb822(self, filename: str) -> None:
"""Load a deb822 format repository source file into the cache.
In contrast to one-line-style, the deb822 format specifies a repository
using a multi-line paragraph. Paragraphs are separated by whitespace,
using a multi-line stanza. Stanzas are separated by whitespace,
and each definition consists of lines that are either key: value pairs,
or continuations of the previous value.
Expand Down Expand Up @@ -1327,16 +1327,16 @@ def _parse_deb822_lines(
`_parse_deb822_lines` strips out comments entirely when parsing a file into stanzas,
instead only reading the 'Enabled' key to determine if an entry is enabled
"""
repositories: List[DebianRepository] = []
repos: List[DebianRepository] = []
errors: List[InvalidSourceError] = []
for numbered_lines in _iter_deb822_stanzas(lines):
try:
stanza = _Deb822Stanza(numbered_lines=numbered_lines, filename=filename)
except InvalidSourceError as e:
errors.append(e)
else:
repositories.extend(stanza.repositories)
return repositories, errors
repos.extend(stanza.repos)
return repos, errors

def load(self, filename: str):
"""Load a one-line-style format repository source file into the cache.
Expand Down Expand Up @@ -1506,7 +1506,7 @@ def __init__(self, numbered_lines: List[Tuple[int, str]], filename: str = ""):
self._filename = filename
self._numbered_lines = numbered_lines
if not numbered_lines:
self._repositories = ()
self._repos = ()
self._gpg_key_filename = ""
self._gpg_key_from_stanza = None
return
Expand All @@ -1516,13 +1516,13 @@ def __init__(self, numbered_lines: List[Tuple[int, str]], filename: str = ""):
)
for repo in repos:
repo._deb822_stanza = self # pyright: ignore[reportPrivateUsage]
self._repositories = repos
self._repos = repos
self._gpg_key_filename, self._gpg_key_from_stanza = gpg_key_info

@property
def repositories(self) -> Tuple[DebianRepository, ...]:
def repos(self) -> Tuple[DebianRepository, ...]:
"""The repositories defined by this deb822 stanza."""
return self._repositories
return self._repos

def get_gpg_key_filename(self) -> str:
"""Return the path to the GPG key for this stanza.
Expand Down Expand Up @@ -1579,18 +1579,18 @@ def _iter_deb822_stanzas(lines: Iterable[str]) -> Iterator[List[Tuple[int, str]]
lists of numbered lines (a tuple of line number and line) that make up
a deb822 stanza, with comments stripped out (but accounted for in line numbering)
"""
current_paragraph: List[Tuple[int, str]] = []
current_stanza: List[Tuple[int, str]] = []
for n, line in enumerate(lines, start=1): # 1 indexed line numbers
if not line.strip(): # blank lines separate paragraphs
if current_paragraph:
yield current_paragraph
current_paragraph = []
if not line.strip(): # blank lines separate stanzas
if current_stanza:
yield current_stanza
current_stanza = []
continue
content, _delim, _comment = line.partition("#")
if content.strip(): # skip (potentially indented) comment line
current_paragraph.append((n, content.rstrip())) # preserve indent
if current_paragraph:
yield current_paragraph
current_stanza.append((n, content.rstrip())) # preserve indent
if current_stanza:
yield current_stanza


def _deb822_stanza_to_options(
Expand Down Expand Up @@ -1700,7 +1700,7 @@ def _deb822_options_to_repos(
msg = (
"Since 'Suites' (line {suites_line}) does not specify"
" a path relative to 'URIs' (line {uris_line}),"
" 'Components' must be present in this paragraph."
" 'Components' must be present in this stanza."
).format(
suites_line=line_numbers.get("Suites"),
uris_line=line_numbers.get("URIs"),
Expand Down

0 comments on commit b993c54

Please sign in to comment.