Skip to content

Commit

Permalink
Added pyalpm as a dependency and fixed flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Torxed committed Nov 8, 2024
1 parent 878ccf8 commit 7853ff5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
1 change: 1 addition & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ depends=(
'pciutils'
'procps-ng'
'python'
'pyalpm'
'python-pydantic'
'python-pyparted'
'python-simple-term-menu'
Expand Down
68 changes: 32 additions & 36 deletions archinstall/lib/pacman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@


class PacmanServer(pydantic.BaseModel):
address :urllib.parse.ParseResult
address: urllib.parse.ParseResult

def geturl(self):
return self.address.geturl()


class PacmanTransaction:
def __init__(self,
session :pyalpm.Handle,
def __init__(
self,
session: pyalpm.Handle,
cascade=False,
nodeps=False,
force=True,
Expand Down Expand Up @@ -78,7 +79,7 @@ def __enter__(self):
message, code, _ = error.args

if code == 10:
raise PermissionError(f"Could not lock database {db.name}.db in {self.dbpath}")
raise PermissionError(f"Could not lock database {self._session.dbpath}")

raise error
return self
Expand Down Expand Up @@ -112,24 +113,25 @@ def __getattr__(self, key):


class Pacman:
def __init__(self,
config :pathlib.Path = pathlib.Path('/etc/pacman.conf'),
servers :typing.List[str] | typing.Dict[str, PacmanServer] | None = None,
dbpath :pathlib.Path | None = None, # pathlib.Path('/var/lib/pacman/')
cachedir :pathlib.Path | None = None, # pathlib.Path('/var/cache/pacman/pkg')
hooks :typing.List[pathlib.Path] | None = None,
repos :typing.List[str] | None = None,
def __init__(
self,
config: pathlib.Path = pathlib.Path('/etc/pacman.conf'),
servers: typing.List[str] | typing.Dict[str, PacmanServer] | None = None,
dbpath: pathlib.Path | None = None, # pathlib.Path('/var/lib/pacman/')
cachedir: pathlib.Path | None = None, # pathlib.Path('/var/cache/pacman/pkg')
hooks: typing.List[pathlib.Path] | None = None,
repos: typing.List[str] | None = None,
# hooks = [
# pathlib.Path('/usr/share/libalpm/hooks/'),
# pathlib.Path('/etc/pacman.d/hooks/')
# ],
logfile :pathlib.Path | None = None, # pathlib.Path('/var/log/pacman.log'),
gpgdir :pathlib.Path | None = None, # pathlib.Path('/etc/pacman.d/gnupg/'),
lock :pathlib.Path | None = None,
include_config_mirrors :bool = False,
temporary :bool = False,
silent :bool = False,
synced :float | None = None,
logfile: pathlib.Path | None = None, # pathlib.Path('/var/log/pacman.log'),
gpgdir: pathlib.Path | None = None, # pathlib.Path('/etc/pacman.d/gnupg/'),
lock: pathlib.Path | None = None,
include_config_mirrors: bool = False,
temporary: bool = False,
silent: bool = False,
synced: float | None = None,
**kwargs
):
self.config = config
Expand Down Expand Up @@ -194,7 +196,7 @@ def load_config(self):
continue

config_item = line.strip()

if _section not in config:
config[_section] = {}

Expand Down Expand Up @@ -306,7 +308,7 @@ def update(self):
# we ensure we rely on the latest information
for db in self._session.get_syncdbs():
# Set up a transaction with some sane defaults
with PacmanTransaction(session=self._session) as _transaction:
with PacmanTransaction(session=self._session) as _transaction: # noqa: F841
# Populate the database with the servers
# listed in the configuration (we could manually override a list here)
db.servers = [
Expand All @@ -326,7 +328,7 @@ def install(self, *packages):
continue

pyalpm_package_list += results

if missing_packages:
raise ValueError(f"Could not find package(s): {' '.join(missing_packages)}")

Expand All @@ -352,13 +354,10 @@ def search(self, *patterns, exact=True):
# print(f"Searching {db.name} for: {' '.join(patterns)}")
results += db.search(*queries)

# !! Workaround for https://gitlab.archlinux.org/pacman/pacman/-/issues/204
#
# Since the regex ^<package>$ should make absolute matches
# but doesn't. This could be because I assume (incorrectly) that
# `pacman -Ss <name>` should match on `pkgname` and `pkgdescr` in PKGBUILD
# or because it's a bug.
# But we can remove the following workaround once that is sorted out:
# Because `pacman -Ss <name>` doesn't perform exact matches,
# as discussed in https://gitlab.archlinux.org/pacman/pacman/-/issues/204
# we need to filter out any inexact results until we figure out if libalpm
# can be used to implement `pacman --sync --nodeps --nodeps --print --print-format '%n' nano`
if exact:
results = [
package
Expand All @@ -385,13 +384,10 @@ def query(self, *patterns, exact=True):
db = self._session.get_localdb()
results += db.search(*queries)

# !! Workaround for https://gitlab.archlinux.org/pacman/pacman/-/issues/204
#
# Since the regex ^<package>$ should make absolute matches
# but doesn't. This could be because I assume (incorrectly) that
# `pacman -Ss <name>` should match on `pkgname` and `pkgdescr` in PKGBUILD
# or because it's a bug.
# But we can remove the following workaround once that is sorted out:
# Because `pacman -Ss <name>` doesn't perform exact matches,
# as discussed in https://gitlab.archlinux.org/pacman/pacman/-/issues/204
# we need to filter out any inexact results until we figure out if libalpm
# can be used to implement `pacman --sync --nodeps --nodeps --print --print-format '%n' nano`
if exact:
results = [
package
Expand Down Expand Up @@ -460,4 +456,4 @@ def strap(self, target, packages: Union[str, list[str]]) -> None:
SysCommand,
f'/usr/bin/pacstrap -C /etc/pacman.conf -K {target} {" ".join(packages)} --noconfirm',
peek_output=True
)
)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ classifiers = [
dependencies = [
"simple-term-menu==1.6.4",
"pyparted @ https://github.com//dcantrell/pyparted/archive/v3.13.0.tar.gz#sha512=26819e28d73420937874f52fda03eb50ab1b136574ea9867a69d46ae4976d38c4f26a2697fa70597eed90dd78a5ea209bafcc3227a17a7a5d63cff6d107c2b11",
"pydantic==2.9.2"
"pydantic==2.9.2",
"pyalpm==0.10.6",
]

[project.urls]
Expand Down

0 comments on commit 7853ff5

Please sign in to comment.