mirror of
https://github.com/BioArchLinux/bioarchlinux-tools.git
synced 2025-03-09 22:53:31 +00:00
fix: _pkgname match error and optdepends
This commit is contained in:
parent
381e415090
commit
b980752240
1 changed files with 32 additions and 8 deletions
|
@ -136,8 +136,9 @@ class PkgInfo:
|
||||||
if r_cran.status_code == requests.codes.ok:
|
if r_cran.status_code == requests.codes.ok:
|
||||||
self.cran_descs = r_cran.text.split('\n\n')
|
self.cran_descs = r_cran.text.split('\n\n')
|
||||||
for desc in self.cran_descs:
|
for desc in self.cran_descs:
|
||||||
if desc.startswith(f'Package: {pkgname}'):
|
# do not remove '\n' here, or tofsims with match tofsimsData
|
||||||
logging.info(f"Found {pkgname} in CRAN")
|
if desc.startswith(f'Package: {pkgname}\n'):
|
||||||
|
logging.debug(f"Found {pkgname} in CRAN")
|
||||||
return desc
|
return desc
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
@ -153,8 +154,9 @@ class PkgInfo:
|
||||||
if bioconductor_descs.status_code == requests.codes.ok:
|
if bioconductor_descs.status_code == requests.codes.ok:
|
||||||
bioconductor_descs = bioconductor_descs.text.split('\n\n')
|
bioconductor_descs = bioconductor_descs.text.split('\n\n')
|
||||||
for desc in bioconductor_descs:
|
for desc in bioconductor_descs:
|
||||||
if desc.startswith(f'Package: {pkgname}'):
|
# do not remove '\n' here, or tofsims with match tofsimsData
|
||||||
logging.info(
|
if desc.startswith(f'Package: {pkgname}\n'):
|
||||||
|
logging.debug(
|
||||||
f"Found {pkgname} in Bioconductor {ver}: {p}")
|
f"Found {pkgname} in Bioconductor {ver}: {p}")
|
||||||
return desc
|
return desc
|
||||||
else:
|
else:
|
||||||
|
@ -166,12 +168,12 @@ class PkgInfo:
|
||||||
'''
|
'''
|
||||||
obtain new depends and optdepends from `desc`, and write them to `self`
|
obtain new depends and optdepends from `desc`, and write them to `self`
|
||||||
'''
|
'''
|
||||||
|
logging.debug(f"Updating {self.pkgname} using \n {desc}")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read_string('[pkg]\n'+desc)
|
config.read_string('[pkg]\n'+desc)
|
||||||
self.pkgver = config['pkg'].get('version')
|
self.pkgver = config['pkg'].get('version')
|
||||||
r_deps = []
|
r_deps = []
|
||||||
r_optdeps = []
|
r_optdeps = []
|
||||||
|
|
||||||
# depends
|
# depends
|
||||||
dep_depends = config['pkg'].get('depends')
|
dep_depends = config['pkg'].get('depends')
|
||||||
if dep_depends:
|
if dep_depends:
|
||||||
|
@ -220,6 +222,14 @@ class PkgInfo:
|
||||||
if sorted(self.new_depends) != sorted(self.depends):
|
if sorted(self.new_depends) != sorted(self.depends):
|
||||||
self.depends_changed = True
|
self.depends_changed = True
|
||||||
|
|
||||||
|
# no optdepends
|
||||||
|
if not self.optdepends:
|
||||||
|
self.optdepends_changed = bool(self.new_optdepends)
|
||||||
|
return
|
||||||
|
if not self.new_optdepends:
|
||||||
|
self.optdepends_changed = bool(self.optdepends)
|
||||||
|
return
|
||||||
|
|
||||||
# keep explanation of optdepends
|
# keep explanation of optdepends
|
||||||
if any(map(lambda x: ':' in x, self.optdepends)):
|
if any(map(lambda x: ':' in x, self.optdepends)):
|
||||||
self.new_optdepends = [
|
self.new_optdepends = [
|
||||||
|
@ -243,7 +253,6 @@ class PkgInfo:
|
||||||
'''
|
'''
|
||||||
if not self.depends_changed and not self.optdepends_changed:
|
if not self.depends_changed and not self.optdepends_changed:
|
||||||
return
|
return
|
||||||
|
|
||||||
with open("PKGBUILD", "r") as f:
|
with open("PKGBUILD", "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
|
@ -273,12 +282,25 @@ class PkgInfo:
|
||||||
lines[i] = ''
|
lines[i] = ''
|
||||||
lines[depends_interval[1]] = '\n'.join(
|
lines[depends_interval[1]] = '\n'.join(
|
||||||
['depends=(', '\n'.join([' ' + _ for _ in self.new_depends]), ')\n'])
|
['depends=(', '\n'.join([' ' + _ for _ in self.new_depends]), ')\n'])
|
||||||
|
|
||||||
|
# new lines for new optdepends
|
||||||
|
if self.new_optdepends:
|
||||||
|
new_optdepends_line = '\n'.join(
|
||||||
|
['optdepends=(', '\n'.join(
|
||||||
|
[' ' + _ for _ in self.new_optdepends]), ')\n'])
|
||||||
if self.optdepends_changed:
|
if self.optdepends_changed:
|
||||||
|
# no old, but has new
|
||||||
|
if optdepends_interval[0] == -1:
|
||||||
|
# add optdepends
|
||||||
|
lines.insert(depends_interval[1]+1, new_optdepends_line)
|
||||||
|
optdepends_interval[0] = depends_interval[1]+1
|
||||||
|
optdepends_interval[1] = depends_interval[1]+1
|
||||||
|
|
||||||
|
# has old,
|
||||||
for i in range(optdepends_interval[0], optdepends_interval[1]):
|
for i in range(optdepends_interval[0], optdepends_interval[1]):
|
||||||
lines[i] = ''
|
lines[i] = ''
|
||||||
if self.new_optdepends:
|
if self.new_optdepends:
|
||||||
lines[optdepends_interval[1]] = '\n'.join(
|
lines[optdepends_interval[1]] = new_optdepends_line
|
||||||
['optdepends=(', '\n'.join([' ' + _ for _ in self.new_optdepends]), ')\n'])
|
|
||||||
|
|
||||||
logging.info(f"Writing new PKGBUILD for {self.pkgname}")
|
logging.info(f"Writing new PKGBUILD for {self.pkgname}")
|
||||||
with open("PKGBUILD", "w") as f:
|
with open("PKGBUILD", "w") as f:
|
||||||
|
@ -325,6 +347,7 @@ def update_depends_by_file(file, bioarch_path="BioArchLinux", bioc_min_ver="3.0"
|
||||||
break
|
break
|
||||||
with open(file, "r") as f:
|
with open(file, "r") as f:
|
||||||
for pkgname in f:
|
for pkgname in f:
|
||||||
|
logging.info(f"Updating {pkgname}")
|
||||||
pkgname = pkgname.strip()
|
pkgname = pkgname.strip()
|
||||||
if case == '_pkgname':
|
if case == '_pkgname':
|
||||||
pkgname = 'r-'+pkgname.lower()
|
pkgname = 'r-'+pkgname.lower()
|
||||||
|
@ -337,6 +360,7 @@ def update_depends_by_file(file, bioarch_path="BioArchLinux", bioc_min_ver="3.0"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='update the depends of R packages from CRAN and Bioconductor automatically',
|
description='update the depends of R packages from CRAN and Bioconductor automatically',
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
||||||
|
|
Loading…
Add table
Reference in a new issue