mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-23 09:49:30 +00:00
refactor: use itertools instead of sum for combining iterables
This commit is contained in:
1 parent
b28c156e78
commit
239149f2b4
7 files changed
+19
-9
No files matched your search
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse
|
||||
import itertools
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
@@ -56,9 +57,9 @@ class Status(Handler):
|
||||
service_status = client.status_get()
|
||||
StatusPrinter(service_status.status)(verbose=args.info)
|
||||
if args.package:
|
||||
packages: list[tuple[Package, BuildStatus]] = sum(
|
||||
(client.package_get(base) for base in args.package),
|
||||
start=[])
|
||||
packages: list[tuple[Package, BuildStatus]] = list(
|
||||
itertools.chain.from_iterable(client.package_get(base) for base in args.package)
|
||||
)
|
||||
else:
|
||||
packages = client.package_get(None)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#
|
||||
import argparse
|
||||
import copy
|
||||
import itertools
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -97,7 +98,7 @@ class Validate(Handler):
|
||||
|
||||
# create trigger loader instance
|
||||
loader = TriggerLoader()
|
||||
triggers = loader.selected_triggers(configuration) + loader.known_triggers(configuration)
|
||||
triggers = itertools.chain(loader.selected_triggers(configuration), loader.known_triggers(configuration))
|
||||
|
||||
for trigger in set(triggers):
|
||||
try:
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse
|
||||
import itertools
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -99,7 +100,7 @@ class Versions(Handler):
|
||||
keys.extend(portion)
|
||||
portion = {
|
||||
key
|
||||
for key in sum((list(dependencies_by_key(key)) for key in portion), start=[])
|
||||
for key in itertools.chain.from_iterable(dependencies_by_key(key) for key in portion)
|
||||
if key not in keys
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import itertools
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from ahriman.core.build_tools.package_version import PackageVersion
|
||||
@@ -126,7 +128,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
if not dependencies.paths:
|
||||
continue # skip check if no package dependencies found
|
||||
|
||||
required_packages = {dep for dep_packages in dependencies.paths.values() for dep in dep_packages}
|
||||
required_packages = set(itertools.chain.from_iterable(dependencies.paths.values()))
|
||||
filesystem = extract_files(required_packages)
|
||||
|
||||
for path, packages in dependencies.paths.items():
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse
|
||||
import itertools
|
||||
import uuid
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
@@ -117,7 +118,7 @@ class Spawn(Thread, LazyLogging):
|
||||
continue # skip null values
|
||||
flag = f"--{argument}"
|
||||
if isinstance(value, list):
|
||||
arguments.extend(list(sum(((flag, v) for v in value), ())))
|
||||
arguments.extend(itertools.chain.from_iterable((flag, v) for v in value))
|
||||
elif value:
|
||||
arguments.extend([flag, value])
|
||||
else:
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import itertools
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import Any, ClassVar, Self
|
||||
|
||||
@@ -100,7 +102,7 @@ class Result:
|
||||
Returns:
|
||||
list[Package]: list of packages with success result
|
||||
"""
|
||||
return list(self._added.values()) + list(self._updated.values())
|
||||
return list(itertools.chain(self._added.values(), self._updated.values()))
|
||||
|
||||
def add_added(self, package: Package) -> None:
|
||||
"""
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import itertools
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
@@ -117,7 +119,7 @@ class KeyringGenerator(PkgbuildGenerator):
|
||||
source_path(Path): destination of the file content
|
||||
"""
|
||||
with source_path.open("w", encoding="utf8") as source_file:
|
||||
for key in sorted(set(self.trusted + self.packagers + self.revoked)):
|
||||
for key in sorted(set(itertools.chain(self.trusted, self.packagers, self.revoked))):
|
||||
public_key = self.sign.key_export(key)
|
||||
source_file.write(public_key)
|
||||
source_file.write("\n")
|
||||
|
||||
Reference in new issue
Block a user