public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2015-10-22 16:13 Paul Varner
  0 siblings, 0 replies; 23+ messages in thread
From: Paul Varner @ 2015-10-22 16:13 UTC (permalink / raw
  To: gentoo-commits

commit:     1537ab55fffda2348753ce26d6d7c11de49d9032
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 22 16:09:30 2015 +0000
Commit:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
CommitDate: Thu Oct 22 16:09:30 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=1537ab55

gentoolkit: Fix to allow package names of all digits. Bug 562952

According to PMS, "A package name may contain any of the characters
[A-Za-z0-9+_-]. It must not begin with a hyphen or a plus sign, and must
not end in a hyphen followed by anything matching the version syntax".

This specification means that a package name can be composed of all
digits.

This fixes cpv.py and query.py to allow package names of all digits.

 pym/gentoolkit/cpv.py   | 2 +-
 pym/gentoolkit/query.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/pym/gentoolkit/cpv.py b/pym/gentoolkit/cpv.py
index 473ae60..f1e3241 100644
--- a/pym/gentoolkit/cpv.py
+++ b/pym/gentoolkit/cpv.py
@@ -243,7 +243,7 @@ def isvalid_pkg_name(chunks):
 	mf = _pkg_re.match
 	if not all(not s or mf(s) for s in chunks):
 		return False
-	if chunks[-1].isdigit() or not chunks[-1]:
+	if not chunks[-1] or (len(chunks) > 1 and chunks[-1].isdigit()):
 		# not allowed.
 		return False
 	return True

diff --git a/pym/gentoolkit/query.py b/pym/gentoolkit/query.py
index df6e2fd..9d1a313 100644
--- a/pym/gentoolkit/query.py
+++ b/pym/gentoolkit/query.py
@@ -19,7 +19,7 @@ __all__ = (
 import fnmatch
 import re
 from functools import partial
-from string import ascii_letters
+from string import ascii_letters, digits
 
 import portage
 
@@ -47,7 +47,7 @@ class Query(CPV):
 		"""
 
 		# We need at least one of these chars for a valid query
-		needed_chars = ascii_letters + '*'
+		needed_chars = ascii_letters + digits + '*'
 		if not set(query).intersection(needed_chars):
 			raise errors.GentoolkitInvalidPackage(query)
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2016-07-08 15:37 Brian Dolbec
  0 siblings, 0 replies; 23+ messages in thread
From: Brian Dolbec @ 2016-07-08 15:37 UTC (permalink / raw
  To: gentoo-commits

commit:     3025811e5bbfd40a1a4e17ef5f305802cb545c22
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Wed Jul  6 05:22:25 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Jul  8 15:35:38 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=3025811e

module_base.py: Add a char type cli option capability

This adds correct handling of the value being assigned to the class options.

 pym/gentoolkit/module_base.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pym/gentoolkit/module_base.py b/pym/gentoolkit/module_base.py
index 87e04f1..5182218 100644
--- a/pym/gentoolkit/module_base.py
+++ b/pym/gentoolkit/module_base.py
@@ -67,7 +67,6 @@ class ModuleBase(object):
 
 	def parse_module_options(self, module_opts):
 		"""Parse module options and update self.options"""
-
 		opts = (x[0] for x in module_opts)
 		posargs = (x[1] for x in module_opts)
 		for opt, posarg in zip(opts, posargs):
@@ -88,6 +87,8 @@ class ModuleBase(object):
 					self.print_help(with_description=False)
 					sys.exit(2)
 				self.options[opt_name] = val
+			elif opt_type == 'char':
+				self.options[opt_name] = posarg
 
 	def set_quiet(self, quiet):
 		"""sets the class option["quiet"] and option["verbose"] accordingly"""


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2016-07-25 18:04 Paul Varner
  0 siblings, 0 replies; 23+ messages in thread
From: Paul Varner @ 2016-07-25 18:04 UTC (permalink / raw
  To: gentoo-commits

commit:     bc92540f8ce498e8305103619c7085b670ba19b1
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 25 18:01:06 2016 +0000
Commit:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
CommitDate: Mon Jul 25 18:01:06 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=bc92540f

Add missing import of io.open when using python2.7

This fixes the traceback when running equery changes with Python 2.7

X-Gentoo-bug: 589686
X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=589686

 pym/gentoolkit/helpers.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py
index 0d985b6..8d25393 100644
--- a/pym/gentoolkit/helpers.py
+++ b/pym/gentoolkit/helpers.py
@@ -26,6 +26,9 @@ __docformat__ = 'epytext'
 # =======
 
 import os
+import sys
+if sys.hexversion < 0x3000000:
+	from io import open
 import re
 from functools import partial
 from itertools import chain


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2016-08-16 16:05 Paul Varner
  0 siblings, 0 replies; 23+ messages in thread
From: Paul Varner @ 2016-08-16 16:05 UTC (permalink / raw
  To: gentoo-commits

commit:     8b40fded4ca1ecc94ed1391acb3a7e16218d4779
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 16 16:03:21 2016 +0000
Commit:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
CommitDate: Tue Aug 16 16:03:21 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=8b40fded

gentoolkit: Fix to allow a package name to end with a hyphen

From PMS: "3.1.2 Package Names
A package name may contain any of the characters [A-Za-z0-9+_-]. It must
not begin with a hyphen or a plus sign, and must not end in a hyphen
followed by anything matching the version syntax described in section
3.2."

This fixes the validation in cpv.py to allow a package name to end with
a hyphen as long as what follows does not match a version.

X-Gentoo-bug: 586986
X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=586986

 pym/gentoolkit/cpv.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pym/gentoolkit/cpv.py b/pym/gentoolkit/cpv.py
index f1e3241..6e272f1 100644
--- a/pym/gentoolkit/cpv.py
+++ b/pym/gentoolkit/cpv.py
@@ -243,7 +243,7 @@ def isvalid_pkg_name(chunks):
 	mf = _pkg_re.match
 	if not all(not s or mf(s) for s in chunks):
 		return False
-	if not chunks[-1] or (len(chunks) > 1 and chunks[-1].isdigit()):
+	if len(chunks) > 1 and chunks[-1].isdigit():
 		# not allowed.
 		return False
 	return True


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2016-09-15 16:02 Brian Dolbec
  0 siblings, 0 replies; 23+ messages in thread
From: Brian Dolbec @ 2016-09-15 16:02 UTC (permalink / raw
  To: gentoo-commits

commit:     7b5c017b896b11c8c5b35c2b337141532536a0ab
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 15 16:01:52 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 15 16:01:52 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=7b5c017b

gentoolkit/package.py: Fix dblink call py3 compatibility bug 575788

 pym/gentoolkit/package.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py
index da9d65c..42b632b 100644
--- a/pym/gentoolkit/package.py
+++ b/pym/gentoolkit/package.py
@@ -363,7 +363,7 @@ class Package(CPV):
 			myroot = self._settings["ROOT"]
 			if myroot != '/':
 				ret = {}
-				for key, val in self.dblink.getcontents().iteritems():
+				for key, val in self.dblink.getcontents().items():
 					ret['/' + os.path.relpath(key, myroot)] = val
 				contents = ret
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2017-09-06 18:33 Paul Varner
  0 siblings, 0 replies; 23+ messages in thread
From: Paul Varner @ 2017-09-06 18:33 UTC (permalink / raw
  To: gentoo-commits

commit:     308e33dc9e0cba958a583d86799dcb660ba39cb1
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Wed Sep  6 18:25:39 2017 +0000
Commit:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
CommitDate: Wed Sep  6 18:25:39 2017 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=308e33dc

equery: size: Fix UnicodeDecodeError

Encode the filename before calling os.lstat

X-Gentoo-Bug: 531636
X-Gentoo-Bug-URL: https://bugs.gentoo.org/531636

 pym/gentoolkit/package.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py
index 42b632b..149ca74 100644
--- a/pym/gentoolkit/package.py
+++ b/pym/gentoolkit/package.py
@@ -46,6 +46,7 @@ from string import Template
 
 import portage
 from portage.util import LazyItemsDict
+from portage import _encodings, _unicode_decode, _unicode_encode
 
 import gentoolkit.pprinter as pp
 from gentoolkit import errors
@@ -380,7 +381,7 @@ class Package(CPV):
 		size = n_files = n_uncounted = 0
 		for path in self.parsed_contents(prefix_root=True):
 			try:
-				st = os.lstat(path)
+				st = os.lstat(_unicode_encode(path, encoding=_encodings['fs']))
 			except OSError:
 				continue
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2018-09-17 23:32 Virgil Dupras
  0 siblings, 0 replies; 23+ messages in thread
From: Virgil Dupras @ 2018-09-17 23:32 UTC (permalink / raw
  To: gentoo-commits

commit:     52ec462b8d529682d688c38fcd724d1894188e65
Author:     Virgil Dupras <vdupras <AT> gentoo <DOT> org>
AuthorDate: Mon Sep 17 23:31:27 2018 +0000
Commit:     Virgil Dupras <vdupras <AT> gentoo <DOT> org>
CommitDate: Mon Sep 17 23:31:27 2018 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=52ec462b

Greatly speed up "equery depends"

Avoid `Atom` instanciation in obvious non-matches (`.cp` not matching)
when search for revdeps. On my machine, it made `equery d -a
dev-python/pillow` go from `1m3s` to `0m19s`.

 pym/gentoolkit/dependencies.py | 43 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index 117342a..bb9ab0b 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -77,38 +77,31 @@ class Dependencies(Query):
 				return []
 		return result
 
-	def get_depend(self):
-		"""Get the contents of DEPEND and parse it with self.parser."""
-
+	def _get_depend(self, env_vars, raw=False):
+		raw_depend = ' '.join(self.environment(env_vars))
+		if raw:
+			return raw_depend
 		try:
-			return self.parser(self.environment(('DEPEND',))[0])
+			return self.parser(raw_depend)
 		except portage.exception.InvalidPackageName as err:
 			raise errors.GentoolkitInvalidCPV(err)
 
-	def get_pdepend(self):
-		"""Get the contents of PDEPEND and parse it with self.parser."""
+	def get_depend(self, **kwargs):
+		"""Get the contents of DEPEND and parse it with self.parser."""
+		return self._get_depend(('DEPEND', ), **kwargs)
 
-		try:
-			return self.parser(self.environment(('PDEPEND',))[0])
-		except portage.exception.InvalidPackageName as err:
-			raise errors.GentoolkitInvalidCPV(err)
+	def get_pdepend(self, **kwargs):
+		"""Get the contents of PDEPEND and parse it with self.parser."""
+		return self._get_depend(('PDEPEND', ), **kwargs)
 
-	def get_rdepend(self):
+	def get_rdepend(self, **kwargs):
 		"""Get the contents of RDEPEND and parse it with self.parser."""
+		return self._get_depend(('RDEPEND', ), **kwargs)
 
-		try:
-			return self.parser(self.environment(('RDEPEND',))[0])
-		except portage.exception.InvalidPackageName as err:
-			raise errors.GentoolkitInvalidCPV(err)
-
-	def get_all_depends(self):
+	def get_all_depends(self, **kwargs):
 		"""Get the contents of ?DEPEND and parse it with self.parser."""
-
 		env_vars = ('DEPEND', 'PDEPEND', 'RDEPEND')
-		try:
-			return self.parser(' '.join(self.environment(env_vars)))
-		except portage.exception.InvalidPackageName as err:
-			raise errors.GentoolkitInvalidCPV(err)
+		return self._get_depend(env_vars, **kwargs)
 
 	def graph_depends(
 		self,
@@ -237,6 +230,12 @@ class Dependencies(Query):
 
 		pkgdep = None
 		for pkgdep in pkgset:
+			raw_depends = pkgdep.get_all_depends(raw=True)
+			if self.cp not in raw_depends:
+				# fast path for obviously non-matching packages. This saves
+				# us the work of instantiating a whole Atom() for *every*
+				# dependency of *every* package in pkgset.
+				continue
 			try:
 				all_depends = depcache[pkgdep]
 			except KeyError:


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2019-05-11 22:43 Virgil Dupras
  0 siblings, 0 replies; 23+ messages in thread
From: Virgil Dupras @ 2019-05-11 22:43 UTC (permalink / raw
  To: gentoo-commits

commit:     43ecd536e7b8ad2af343288fe2e6d919f8edf5aa
Author:     Virgil Dupras <vdupras <AT> gentoo <DOT> org>
AuthorDate: Sat May 11 22:42:09 2019 +0000
Commit:     Virgil Dupras <vdupras <AT> gentoo <DOT> org>
CommitDate: Sat May 11 22:42:09 2019 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=43ecd536

Include BDEPEND in dep checks

Bug: https://bugs.gentoo.org/685538
Signed-off-by: Virgil Dupras <vdupras <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index bb9ab0b..8536369 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -100,7 +100,7 @@ class Dependencies(Query):
 
 	def get_all_depends(self, **kwargs):
 		"""Get the contents of ?DEPEND and parse it with self.parser."""
-		env_vars = ('DEPEND', 'PDEPEND', 'RDEPEND')
+		env_vars = ('DEPEND', 'PDEPEND', 'RDEPEND', 'BDEPEND')
 		return self._get_depend(env_vars, **kwargs)
 
 	def graph_depends(


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2019-07-29  0:51 Zac Medico
  0 siblings, 0 replies; 23+ messages in thread
From: Zac Medico @ 2019-07-29  0:51 UTC (permalink / raw
  To: gentoo-commits

commit:     8eeb4ee67da8ce2143f26f07545e666b3a4ad610
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 29 00:48:07 2019 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jul 29 00:50:23 2019 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=8eeb4ee6

filter_flags: handle default IUSE correctly with reduce_flag

Fix comparisons to use the result of reduce_flag.

Bug: https://bugs.gentoo.org/690786
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 pym/gentoolkit/flag.py | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/pym/gentoolkit/flag.py b/pym/gentoolkit/flag.py
index 90a931a..42e8196 100644
--- a/pym/gentoolkit/flag.py
+++ b/pym/gentoolkit/flag.py
@@ -116,22 +116,21 @@ def filter_flags(use, use_expand_hidden, usemasked, useforced):
 	"""
 	# clean out some environment flags, since they will most probably
 	# be confusing for the user
+	use = dict((reduce_flag(flag), flag) for flag in use)
 	for f in use_expand_hidden:
 		f=f.lower() + "_"
-		for x in use:
-			if f in x:
-				use.remove(x)
+		for x in list(use):
+			if x.startswith(f):
+				del use[x]
 	# clean out any arch's
 	archlist = portage.settings["PORTAGE_ARCHLIST"].split()
-	for a in use[:]:
-		if a in archlist:
-			use.remove(a)
+	for a in archlist:
+		use.pop(a, None)
 	# dbl check if any from usemasked  or useforced are still there
 	masked = usemasked + useforced
-	for a in use[:]:
-		if a in masked:
-			use.remove(a)
-	return use
+	for a in masked:
+		use.pop(a, None)
+	return list(use.values())
 
 
 def get_all_cpv_use(cpv):


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2020-04-24  8:06 Michał Górny
  0 siblings, 0 replies; 23+ messages in thread
From: Michał Górny @ 2020-04-24  8:06 UTC (permalink / raw
  To: gentoo-commits

commit:     39e6451899c28ef20c844c5186fdd2316f2cfbd4
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 24 08:00:41 2020 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Apr 24 08:00:41 2020 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=39e64518

profile: Update ~arch list

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 pym/gentoolkit/profile.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pym/gentoolkit/profile.py b/pym/gentoolkit/profile.py
index 945362d..031b497 100644
--- a/pym/gentoolkit/profile.py
+++ b/pym/gentoolkit/profile.py
@@ -82,9 +82,9 @@ def load_profile_data(portdir=None, repo='gentoo'):
 		warning('will not be able to verify args are correct')
 
 	# TODO: support arches.desc once the GLEP is finalized
-	# for now, we just hardcode ~mips + *-* (fbsd, prefix)
+	# for now, we just hardcode everything + *-* (fbsd, prefix)
 	for k, v in arch_status.items():
-		if k in ('alpha', 'mips', 'riscv') or '-' in k:
+		if k in ('alpha', 'ia64', 'm68k', 'mips', 'riscv') or '-' in k:
 			arch_status[k] = (v, '~arch')
 		else:
 			arch_status[k] = (v, 'arch')


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2020-10-09  6:29 Georgy Yakovlev
  0 siblings, 0 replies; 23+ messages in thread
From: Georgy Yakovlev @ 2020-10-09  6:29 UTC (permalink / raw
  To: gentoo-commits

commit:     517581df206766fabf10273cde565e0a6dc62829
Author:     Mikk Margus Möll <mimoll <AT> ttu <DOT> ee>
AuthorDate: Wed Oct  7 20:00:51 2020 +0000
Commit:     Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
CommitDate: Fri Oct  9 06:29:09 2020 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=517581df

metadata: Drop deprecated ElementTree methods

Closes: https://github.com/gentoo/gentoolkit/pull/11
Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org>

 pym/gentoolkit/metadata.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/pym/gentoolkit/metadata.py b/pym/gentoolkit/metadata.py
index 22c249e..c3dba98 100644
--- a/pym/gentoolkit/metadata.py
+++ b/pym/gentoolkit/metadata.py
@@ -73,8 +73,7 @@ class _Maintainer(object):
 		self.description = None
 		self.restrict = node.get('restrict')
 		self.status = node.get('status')
-		maint_attrs = node.getchildren()
-		for attr in maint_attrs:
+		for attr in node.iter():
 			setattr(self, attr.tag, attr.text)
 
 	def __repr__(self):
@@ -101,7 +100,7 @@ class _Useflag(object):
 		_desc = ''
 		if node.text:
 			_desc = node.text
-		for child in node.getchildren():
+		for child in node.iter():
 			_desc += child.text if child.text else ''
 			_desc += child.tail if child.tail else ''
 		# This takes care of tabs and newlines left from the file
@@ -213,7 +212,7 @@ class MetaData(object):
 		if herd in ('no-herd', 'maintainer-wanted', 'maintainer-needed'):
 			return None
 
-		for node in self._herdstree.getiterator('herd'):
+		for node in self._herdstree.iter('herd'):
 			if node.findtext('name') == herd:
 				return node.findtext('email')
 
@@ -283,7 +282,7 @@ class MetaData(object):
 			return self._useflags
 
 		self._useflags = []
-		for node in self._xml_tree.getiterator('flag'):
+		for node in self._xml_tree.iter('flag'):
 			self._useflags.append(_Useflag(node))
 
 		return self._useflags


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2020-10-13 14:14 Brian Dolbec
  0 siblings, 0 replies; 23+ messages in thread
From: Brian Dolbec @ 2020-10-13 14:14 UTC (permalink / raw
  To: gentoo-commits

commit:     f14b6198d1dd9cb7f4a83f3822e4a1782a5581e8
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 13 14:04:07 2020 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Oct 13 14:13:02 2020 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=f14b6198

metadata.py: Fix duplicated use flag text bug 748129

Regression from commit: 517581df206766
link: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=517581df206766fabf10273cde565e0a6dc62829
Gentoo bug: https://bugs.gentoo.org/748129
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/gentoolkit/metadata.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pym/gentoolkit/metadata.py b/pym/gentoolkit/metadata.py
index c3dba98..0b58392 100644
--- a/pym/gentoolkit/metadata.py
+++ b/pym/gentoolkit/metadata.py
@@ -101,8 +101,11 @@ class _Useflag(object):
 		if node.text:
 			_desc = node.text
 		for child in node.iter():
-			_desc += child.text if child.text else ''
-			_desc += child.tail if child.tail else ''
+			# prevent duplicate text
+			if child.text and child.text not in _desc:
+				_desc += child.text
+			if child.tail and not child.tail in _desc:
+				_desc += child.tail
 		# This takes care of tabs and newlines left from the file
 		self.description = re.sub(r'\s+', ' ', _desc)
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2021-09-21 21:01 Matt Turner
  0 siblings, 0 replies; 23+ messages in thread
From: Matt Turner @ 2021-09-21 21:01 UTC (permalink / raw
  To: gentoo-commits

commit:     813c8e3a4853bedc50d7d4176282c5f0bacde31e
Author:     Wolfgang E. Sanyer <WolfgangESanyer <AT> gmail <DOT> com>
AuthorDate: Tue Sep 21 20:50:35 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Tue Sep 21 21:00:18 2021 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=813c8e3a

Fix flake F401 'imported but unused' error

Closes: https://github.com/gentoo/gentoolkit/pull/17
Signed-off-by: Wolfgang E. Sanyer <WolfgangESanyer <AT> gmail.com>
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 pym/gentoolkit/helpers.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py
index 15d959d..72c5d13 100644
--- a/pym/gentoolkit/helpers.py
+++ b/pym/gentoolkit/helpers.py
@@ -32,9 +32,6 @@ from portage import _encodings, _unicode_encode
 
 from gentoolkit import pprinter as pp
 from gentoolkit import errors
-from gentoolkit.atom import Atom
-from gentoolkit.cpv import CPV
-from gentoolkit.versionmatch import VersionMatch
 
 # This has to be imported below to stop circular import.
 # from gentoolkit.package import Package


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2022-07-10  7:53 Brian Dolbec
  0 siblings, 0 replies; 23+ messages in thread
From: Brian Dolbec @ 2022-07-10  7:53 UTC (permalink / raw
  To: gentoo-commits

commit:     6fcf53bcf3579e4439623315875a4303af9af41f
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 10 07:47:28 2022 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Jul 10 07:53:23 2022 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=6fcf53bc

package.py: code cleanup via black

Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/gentoolkit/package.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py
index 51bb329..612fbd3 100644
--- a/pym/gentoolkit/package.py
+++ b/pym/gentoolkit/package.py
@@ -448,7 +448,9 @@ class Package(CPV):
         @rtype: list
         """
 
-        return portage.db[portage.root]["porttree"].dbapi.aux_get(self.cpv, ["DESCRIPTION"])
+        return portage.db[portage.root]["porttree"].dbapi.aux_get(
+            self.cpv, ["DESCRIPTION"]
+        )
 
 
 class PackageFormatter:


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2022-07-10  7:53 Brian Dolbec
  0 siblings, 0 replies; 23+ messages in thread
From: Brian Dolbec @ 2022-07-10  7:53 UTC (permalink / raw
  To: gentoo-commits

commit:     eb9a4d026ef453e392faff35925537bee74c9d80
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 10 07:45:34 2022 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Jul 10 07:49:28 2022 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=eb9a4d02

equery meta: Migrate to portage's MetadataXML class

Portage's metadata handling code was originally ported from gentoolkit.
Finally get around to migrating, eliminating duplicate code.

Bug: https://bugs.gentoo.org/573030
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/gentoolkit/metadata.py | 256 ---------------------------------------------
 pym/gentoolkit/package.py  |  10 +-
 2 files changed, 7 insertions(+), 259 deletions(-)

diff --git a/pym/gentoolkit/metadata.py b/pym/gentoolkit/metadata.py
deleted file mode 100644
index 479456a..0000000
--- a/pym/gentoolkit/metadata.py
+++ /dev/null
@@ -1,256 +0,0 @@
-# Copyright(c) 2009, Gentoo Foundation
-#
-# Licensed under the GNU General Public License, v2
-
-"""Provides an easy-to-use python interface to Gentoo's metadata.xml file.
-
-    Example usage:
-    >>> pkg_md = MetaData('/var/db/repos/gentoo/app-accessibility/espeak-ng/metadata.xml')
-    >>> pkg_md
-    <MetaData '/var/db/repos/gentoo/app-accessibility/espeak-ng/metadata.xml'>
-    >>> for maint in pkg_md.maintainers():
-    ...     print('{0} ({1})'.format(maint.email, maint.name))
-    ...
-    williamh@gentoo.org (William Hubbs)
-    >>> for flag in pkg_md.use():
-    ...     print(flag.name, '->', flag.description)
-    ...
-    async -> Enables asynchronous commands
-    klatt -> Enables Klatt formant synthesis and implementation
-    l10n_ru -> Builds extended Russian Dictionary file
-    l10n_zh -> Builds extended Chinese (Mandarin and Cantonese) Dictionary files
-    man -> Builds and installs manpage with app-text/ronn
-    mbrola -> Adds support for mbrola voices
-    >>> upstream = pkg_md.upstream()
-    >>> upstream
-    [<_Upstream {'node': <Element 'upstream' at 0x7f952a73b2c0>,
-     'maintainers': [<_Maintainer 'msclrhd@gmail.com'>],
-     'changelogs': ['https://github.com/espeak-ng/espeak-ng/releases.atom'],
-     'docs': [], 'bugtrackers': [],
-     'remoteids': [('espeak-ng/espeak-ng', 'github')]}>]
-    >>> upstream[0].maintainers[0].name
-    'Reece H. Dunn'
-"""
-
-__all__ = ("MetaData",)
-__docformat__ = "epytext"
-
-# =======
-# Imports
-# =======
-
-import re
-import xml.etree.cElementTree as etree
-
-# =======
-# Classes
-# =======
-
-
-class _Maintainer:
-    """An object for representing one maintainer.
-
-    @type email: str or None
-    @ivar email: Maintainer's email address. Used for both Gentoo and upstream.
-    @type name: str or None
-    @ivar name: Maintainer's name. Used for both Gentoo and upstream.
-    @type description: str or None
-    @ivar description: Description of what a maintainer does. Gentoo only.
-    @type restrict: str or None
-    @ivar restrict: e.g. &gt;=portage-2.2 means only maintains versions
-            of Portage greater than 2.2. Should be DEPEND string with < and >
-            converted to &lt; and &gt; respectively.
-    @type status: str or None
-    @ivar status: If set, either 'active' or 'inactive'. Upstream only.
-    """
-
-    def __init__(self, node):
-        self.email = None
-        self.name = None
-        self.description = None
-        self.restrict = node.get("restrict")
-        self.status = node.get("status")
-        for attr in node.iter():
-            setattr(self, attr.tag, attr.text)
-
-    def __repr__(self):
-        return "<%s %r>" % (self.__class__.__name__, self.email)
-
-
-class _Useflag:
-    """An object for representing one USE flag.
-
-    @todo: Is there any way to have a keyword option to leave in
-            <pkg> and <cat> for later processing?
-    @type name: str or None
-    @ivar name: USE flag
-    @type restrict: str or None
-    @ivar restrict: e.g. &gt;=portage-2.2 means flag is only avaiable in
-            versions greater than 2.2
-    @type description: str
-    @ivar description: description of the USE flag
-    """
-
-    def __init__(self, node):
-        self.name = node.get("name")
-        self.restrict = node.get("restrict")
-        _desc = ""
-        if node.text:
-            _desc = node.text
-        for child in node.iter():
-            # prevent duplicate text
-            if child.text and child.text not in _desc:
-                _desc += child.text
-            if child.tail and not child.tail in _desc:
-                _desc += child.tail
-        # This takes care of tabs and newlines left from the file
-        self.description = re.sub(r"\s+", " ", _desc)
-
-    def __repr__(self):
-        return "<%s %r>" % (self.__class__.__name__, self.name)
-
-
-class _Upstream:
-    """An object for representing one package's upstream.
-
-    @type maintainers: list
-    @ivar maintainers: L{_Maintainer} objects for each upstream maintainer
-    @type changelogs: list
-    @ivar changelogs: URLs to upstream's ChangeLog file in str format
-    @type docs: list
-    @ivar docs: Sequence of tuples containing URLs to upstream documentation
-            in the first slot and 'lang' attribute in the second, e.g.,
-            [('http.../docs/en/tut.html', None), ('http.../doc/fr/tut.html', 'fr')]
-    @type bugtrackers: list
-    @ivar bugtrackers: URLs to upstream's bugtracker. May also contain an email
-            address if prepended with 'mailto:'
-    @type remoteids: list
-    @ivar remoteids: Sequence of tuples containing the project's hosting site
-            name in the first slot and the project's ID name or number for that
-            site in the second, e.g., [('sourceforge', 'systemrescuecd')]
-    """
-
-    def __init__(self, node):
-        self.node = node
-        self.maintainers = self.upstream_maintainers()
-        self.changelogs = self.upstream_changelogs()
-        self.docs = self.upstream_documentation()
-        self.bugtrackers = self.upstream_bugtrackers()
-        self.remoteids = self.upstream_remoteids()
-
-    def __repr__(self):
-        return "<%s %r>" % (self.__class__.__name__, self.__dict__)
-
-    def upstream_bugtrackers(self):
-        """Retrieve upstream bugtracker location from xml node."""
-        return [e.text for e in self.node.findall("bugs-to")]
-
-    def upstream_changelogs(self):
-        """Retrieve upstream changelog location from xml node."""
-        return [e.text for e in self.node.findall("changelog")]
-
-    def upstream_documentation(self):
-        """Retrieve upstream documentation location from xml node."""
-        result = []
-        for elem in self.node.findall("doc"):
-            lang = elem.get("lang")
-            result.append((elem.text, lang))
-        return result
-
-    def upstream_maintainers(self):
-        """Retrieve upstream maintainer information from xml node."""
-        return [_Maintainer(m) for m in self.node.findall("maintainer")]
-
-    def upstream_remoteids(self):
-        """Retrieve upstream remote ID from xml node."""
-        return [(e.text, e.get("type")) for e in self.node.findall("remote-id")]
-
-
-class MetaData:
-    """Access metadata.xml"""
-
-    def __init__(self, metadata_path):
-        """Parse a valid metadata.xml file.
-
-        @type metadata_path: str
-        @param metadata_path: path to a valid metadata.xml file
-        @raise IOError: if C{metadata_path} can not be read
-        """
-
-        self.metadata_path = metadata_path
-        self._xml_tree = etree.parse(metadata_path)
-
-        # Used for caching
-        self._descriptions = None
-        self._maintainers = None
-        self._useflags = None
-        self._upstream = None
-
-    def __repr__(self):
-        return "<%s %r>" % (self.__class__.__name__, self.metadata_path)
-
-    def descriptions(self):
-        """Return a list of text nodes for <longdescription>.
-
-        @rtype: list
-        @return: package description in string format
-        @todo: Support the C{lang} attribute
-        """
-
-        if self._descriptions is not None:
-            return self._descriptions
-
-        long_descriptions = self._xml_tree.findall("longdescription")
-        self._descriptions = [e.text for e in long_descriptions]
-        return self._descriptions
-
-    def maintainers(self):
-        """Get maintainers' name, email and description.
-
-        @rtype: list
-        @return: a sequence of L{_Maintainer} objects in document order.
-        """
-
-        if self._maintainers is not None:
-            return self._maintainers
-
-        self._maintainers = []
-        for node in self._xml_tree.findall("maintainer"):
-            self._maintainers.append(_Maintainer(node))
-
-        return self._maintainers
-
-    def use(self):
-        """Get names and descriptions for USE flags defined in metadata.
-
-        @rtype: list
-        @return: a sequence of L{_Useflag} objects in document order.
-        """
-
-        if self._useflags is not None:
-            return self._useflags
-
-        self._useflags = []
-        for node in self._xml_tree.iter("flag"):
-            self._useflags.append(_Useflag(node))
-
-        return self._useflags
-
-    def upstream(self):
-        """Get upstream contact information.
-
-        @rtype: list
-        @return: a sequence of L{_Upstream} objects in document order.
-        """
-
-        if self._upstream is not None:
-            return self._upstream
-
-        self._upstream = []
-        for node in self._xml_tree.findall("upstream"):
-            self._upstream.append(_Upstream(node))
-
-        return self._upstream
-
-
-# vim: set ts=4 sw=4 tw=79:

diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py
index 1110bf5..51bb329 100644
--- a/pym/gentoolkit/package.py
+++ b/pym/gentoolkit/package.py
@@ -123,14 +123,18 @@ class Package(CPV):
 
     @property
     def metadata(self):
-        """Instantiate a L{gentoolkit.metadata.MetaData} object here."""
+        """Instantiate a L{portage.xml.MetaDataXML} object here."""
 
-        from gentoolkit.metadata import MetaData
+        from portage.xml.metadata import MetaDataXML
 
         if self._metadata is None:
             metadata_path = os.path.join(self.package_path(), "metadata.xml")
+            projects_path = os.path.join(
+                self._settings["PORTDIR"], "metadata/projects.xml"
+            )
+
             try:
-                self._metadata = MetaData(metadata_path)
+                self._metadata = MetaDataXML(metadata_path, projects_path)
             except IOError as error:
                 import errno
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2022-12-14  9:24 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2022-12-14  9:24 UTC (permalink / raw
  To: gentoo-commits

commit:     d2b36d9abfaed58360bdc0f92d214beb25a94518
Author:     Krzesimir Nowak <knowak <AT> microsoft <DOT> com>
AuthorDate: Thu Dec  8 15:25:39 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Dec 14 09:24:04 2022 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=d2b36d9a

profile: Default to main repo name

In Flatcar we have a different repo marked as a default one
(portage-stable), so "equery keywords" was crashing because it was
trying to use gentoo repo anyways.

Signed-off-by: Krzesimir Nowak <knowak <AT> microsoft.com>
Closes: https://github.com/gentoo/gentoolkit/pull/24
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/profile.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/pym/gentoolkit/profile.py b/pym/gentoolkit/profile.py
index f6943be..7469138 100644
--- a/pym/gentoolkit/profile.py
+++ b/pym/gentoolkit/profile.py
@@ -21,21 +21,26 @@ def warning(msg):
     print("warning: %s" % msg, file=sys.stderr)
 
 
-def load_profile_data(portdir=None, repo="gentoo"):
+def load_profile_data(portdir=None, repo=""):
     """Load the list of known arches from the tree
 
     Args:
       portdir: The repository to load all data from (and ignore |repo|)
-      repo: Look up this repository by name to locate profile data
+      repo: Look up this repository by name to locate profile data (if empty, uses main repo name)
 
     Returns:
       A dict mapping the keyword to its preferred state:
       {'x86': ('stable', 'arch'), 'mips': ('dev', '~arch'), ...}
     """
     if portdir is None:
-        portdir = (
-            portage.db[portage.root]["vartree"].settings.repositories[repo].location
-        )
+        repos = portage.db[portage.root]["vartree"].settings.repositories
+        if repo == "":
+            main_repo = repos.mainRepo()
+            if main_repo is None:
+                repo = "gentoo"
+            else:
+                repo = main_repo.name
+        portdir = repos[repo].location
 
     arch_status = {}
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-02-16 20:39 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-02-16 20:39 UTC (permalink / raw
  To: gentoo-commits

commit:     78464ec40bad9a0f824b063506f58296cc3ed9f3
Author:     John Turner <jturner.usa <AT> gmail <DOT> com>
AuthorDate: Wed Jan 24 23:31:11 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 16 20:12:48 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=78464ec4

dependencies.py: create DependencyKind enum

The DependencyKind enum allows iterating over the different dependency
kinds and represents each dependency kind as a type. This could later
be used in APIs for selecting specific dependency kinds in queries.

Signed-off-by: John Turner <jturner.usa <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index 8dd4867..dd30312 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -11,6 +11,8 @@ __all__ = ("Dependencies",)
 # Imports
 # =======
 
+from enum import StrEnum
+
 import portage
 from portage.dep import paren_reduce
 
@@ -24,6 +26,14 @@ from gentoolkit.query import Query
 # =======
 
 
+class DependencyKind(StrEnum):
+    DEPEND = "DEPEND"
+    RDEPEND = "RDEPEND"
+    BDEPEND = "BDEPEND"
+    PDEPEND = "PDEPEND"
+    IDEPEND = "IDEPEND"
+
+
 class Dependencies(Query):
     """Access a package's dependencies and reverse dependencies.
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-02-16 20:39 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-02-16 20:39 UTC (permalink / raw
  To: gentoo-commits

commit:     6aef2c5968d66e91dc083820db489d85697f3587
Author:     John Turner <jturner.usa <AT> gmail <DOT> com>
AuthorDate: Tue Feb 13 20:45:51 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 16 20:12:49 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=6aef2c59

dependencies.py: replace hand rolled depcache with functools.cache

functools.cache caches the output of functions "automatically" without
requiring any manual management of a cache value. When used on class
methods, the cache is associated with each class instance and only
lives as long as the instance does.

The Dependencies.graph_reverse_depends method used a dict to cache
the output from pkg.get_all_depends. The get_all_depends method involves calling
portage's aux_get and parsing the DEPEND string that is returned by
it. This dict has been removed and replaced with functools.cache.

The graph_reverse_depends method did not cache the output of the
"raw=True" get_all_depends calls. This "raw" output is the literal string value for
the pkgdeps *DEPEND variables as returned by aux_get. Searching this for a
category/package sub-string allows quickly ruling out non-matching
pkgdeps, which allows skipping parsing the DEPEND string into a list
of Atoms.

Using functools cache the method that fetches the raw DEPEND string
massively improves performance for graph_reverse_depends when
searching for indirect reverse dependencies. "equery depends --indirect emacs"
runtime is ~2s with the raw value being cached, and ~60s
without. Searching for only direct reverse dependencies does not
utilize the cache and does not see any chance in runtime for me.

Signed-off-by: John Turner <jturner.usa <AT> gmail.com>
Closes: https://github.com/gentoo/gentoolkit/pull/44
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index 4564d8c..3bbc757 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -12,6 +12,7 @@ __all__ = ("Dependencies",)
 # =======
 
 import itertools
+from functools import cache
 from enum import StrEnum
 from typing import List, Dict
 
@@ -102,9 +103,11 @@ class Dependencies(Query):
         except portage.exception.InvalidPackageName as err:
             raise errors.GentoolkitInvalidCPV(err)
 
+    @cache
     def get_raw_depends(self) -> str:
         return self._get_depend([depkind for depkind in DependencyKind], raw=True)
 
+    @cache
     def get_depends(self) -> Dict[DependencyKind, List[Atom]]:
         depends = dict()
         for depkind in DependencyKind:
@@ -189,7 +192,6 @@ class Dependencies(Query):
         printer_fn=None,
         # The rest of these are only used internally:
         depth=0,
-        depcache=None,
         seen=None,
         result=None,
     ):
@@ -233,8 +235,6 @@ class Dependencies(Query):
             )
             raise errors.GentoolkitFatalError(err % (self.__class__.__name__,))
 
-        if depcache is None:
-            depcache = dict()
         if seen is None:
             seen = set()
         if result is None:
@@ -250,12 +250,8 @@ class Dependencies(Query):
                 # us the work of instantiating a whole Atom() for *every*
                 # dependency of *every* package in pkgset.
                 continue
-            try:
-                all_depends = depcache[pkgdep]
-            except KeyError:
-                all_depends = pkgdep.get_all_depends()
-                depcache[pkgdep] = all_depends
 
+            all_depends = pkgdep.get_all_depends()
             dep_is_displayed = False
             for dep in all_depends:
                 # TODO: Add ability to determine if dep is enabled by USE flag.
@@ -284,7 +280,6 @@ class Dependencies(Query):
                         only_direct=only_direct,
                         printer_fn=printer_fn,
                         depth=depth + 1,
-                        depcache=depcache,
                         seen=seen,
                         result=result,
                     )


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-02-16 20:39 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-02-16 20:39 UTC (permalink / raw
  To: gentoo-commits

commit:     c0300517671076db453204c796637e206bf977e5
Author:     John Turner <jturner.usa <AT> gmail <DOT> com>
AuthorDate: Tue Feb 13 19:31:01 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 16 20:12:49 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=c0300517

dependencies.py: unify get_*depend methods

Instead of having separate functions for each DEPEND kind, the unified
method returns a dict with all of the packages *DEPEND values inside
of it. The dict can be indexed with a string or a field of the
DependencyKind enum.

This will be espeically useful for a future change that adds the
ability to filter out specific DEPEND kinds from the query.

The Dependencies class did not search IDEPEND dependencies, the
unified method searches all dependency kinds defined in the
DependencyKind enum, which includes IDEPEND!

Signed-off-by: John Turner <jturner.usa <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index dd30312..4564d8c 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -11,7 +11,9 @@ __all__ = ("Dependencies",)
 # Imports
 # =======
 
+import itertools
 from enum import StrEnum
+from typing import List, Dict
 
 import portage
 from portage.dep import paren_reduce
@@ -100,22 +102,19 @@ class Dependencies(Query):
         except portage.exception.InvalidPackageName as err:
             raise errors.GentoolkitInvalidCPV(err)
 
-    def get_depend(self, **kwargs):
-        """Get the contents of DEPEND and parse it with self.parser."""
-        return self._get_depend(("DEPEND",), **kwargs)
+    def get_raw_depends(self) -> str:
+        return self._get_depend([depkind for depkind in DependencyKind], raw=True)
 
-    def get_pdepend(self, **kwargs):
-        """Get the contents of PDEPEND and parse it with self.parser."""
-        return self._get_depend(("PDEPEND",), **kwargs)
+    def get_depends(self) -> Dict[DependencyKind, List[Atom]]:
+        depends = dict()
+        for depkind in DependencyKind:
+            depend = self._get_depend([depkind])
+            depends[depkind] = depend
+        return depends
 
-    def get_rdepend(self, **kwargs):
-        """Get the contents of RDEPEND and parse it with self.parser."""
-        return self._get_depend(("RDEPEND",), **kwargs)
-
-    def get_all_depends(self, **kwargs):
-        """Get the contents of ?DEPEND and parse it with self.parser."""
-        env_vars = ("DEPEND", "PDEPEND", "RDEPEND", "BDEPEND")
-        return self._get_depend(env_vars, **kwargs)
+    def get_all_depends(self) -> List[Atom]:
+        # flatten Dict[DependencyKind, List[Atom]] into a List[Atom]
+        return list(itertools.chain.from_iterable(self.get_depends().values()))
 
     def graph_depends(
         self,
@@ -246,8 +245,7 @@ class Dependencies(Query):
 
         pkgdep = None
         for pkgdep in pkgset:
-            raw_depends = pkgdep.get_all_depends(raw=True)
-            if self.cp not in raw_depends:
+            if self.cp not in pkgdep.get_raw_depends():
                 # fast path for obviously non-matching packages. This saves
                 # us the work of instantiating a whole Atom() for *every*
                 # dependency of *every* package in pkgset.
@@ -255,7 +253,7 @@ class Dependencies(Query):
             try:
                 all_depends = depcache[pkgdep]
             except KeyError:
-                all_depends = uniqify(pkgdep.get_all_depends())
+                all_depends = pkgdep.get_all_depends()
                 depcache[pkgdep] = all_depends
 
             dep_is_displayed = False


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-02-17  0:01 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-02-17  0:01 UTC (permalink / raw
  To: gentoo-commits

commit:     678a1904da6aebc4fa7fd09e8f800e5af9101a61
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 17 00:01:12 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Feb 17 00:01:40 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=678a1904

gentoolkit: fix flake8 lint error (F401, unused import)

pym/gentoolkit/dependencies.py:24:1: F401 'gentoolkit.helpers.uniqify' imported but unused

Fixes: c0300517671076db453204c796637e206bf977e5
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index 3bbc757..f296e27 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -21,7 +21,6 @@ from portage.dep import paren_reduce
 
 from gentoolkit import errors
 from gentoolkit.atom import Atom
-from gentoolkit.helpers import uniqify
 from gentoolkit.query import Query
 
 # =======


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-03-07 15:08 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-03-07 15:08 UTC (permalink / raw
  To: gentoo-commits

commit:     5c8f8d79a8b6179e50b2eb955eb848096727a9ac
Author:     John Turner <jturner.usa <AT> gmail <DOT> com>
AuthorDate: Wed Mar  6 19:43:03 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Mar  7 15:08:04 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=5c8f8d79

dependencies.py: use Enum rather than StrEnum for DependencyKind

StrEnum is only supported in Python versions 3.11 and
newer. Gentoolkit should not require >=3.11, so DependencyKind will
use the regular Enum feature instead.

The difference between StrEnum and Enum is that StrEnum members are
strings and can generally be used in place of strings in APIs
expecting string input. Non-StrEnum members are not strings, but you
can get members values by accessing their value field (DependencyKind.DEPEND.value).

Fixes: 78464ec40bad9a0f824b063506f58296cc3ed9f3
Signed-off-by: John Turner <jturner.usa <AT> gmail.com>
Closes: https://github.com/gentoo/gentoolkit/pull/46
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index f296e27..c6abff0 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -13,7 +13,7 @@ __all__ = ("Dependencies",)
 
 import itertools
 from functools import cache
-from enum import StrEnum
+from enum import Enum
 from typing import List, Dict
 
 import portage
@@ -28,7 +28,7 @@ from gentoolkit.query import Query
 # =======
 
 
-class DependencyKind(StrEnum):
+class DependencyKind(Enum):
     DEPEND = "DEPEND"
     RDEPEND = "RDEPEND"
     BDEPEND = "BDEPEND"
@@ -104,13 +104,13 @@ class Dependencies(Query):
 
     @cache
     def get_raw_depends(self) -> str:
-        return self._get_depend([depkind for depkind in DependencyKind], raw=True)
+        return self._get_depend([depkind.value for depkind in DependencyKind], raw=True)
 
     @cache
     def get_depends(self) -> Dict[DependencyKind, List[Atom]]:
         depends = dict()
         for depkind in DependencyKind:
-            depend = self._get_depend([depkind])
+            depend = self._get_depend([depkind.value])
             depends[depkind] = depend
         return depends
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-03-07 18:49 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-03-07 18:49 UTC (permalink / raw
  To: gentoo-commits

commit:     3a53501625e73483a86f2ee00696047a20682745
Author:     John Turner <jturner.usa <AT> gmail <DOT> com>
AuthorDate: Thu Feb 22 20:50:40 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Mar  7 18:49:06 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=3a535016

dependencies.py: rewrite graph_reverse_depends to pass tests

The graph_reverse_depends method was not able to pass the unit tests
introduced in the previous commits. It has been rewritten to pass them.

This also has adding types to the method, and yields the results as an
iterator rather than collecting them into a list in one shot.

The printer callback parameter has been removed. This callback most
likely existed so that results would be shown to the user as soon as
they were available instead of delaying printing until the method
completed, which could take seconds or minutes depending on the
parameters. By making this method an iterator, the same effect is
acheived by having the caller print every item as its yielded
from the method.

Signed-off-by: John Turner <jturner.usa <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/dependencies.py | 102 +++++++++++++++--------------------------
 1 file changed, 36 insertions(+), 66 deletions(-)

diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index c6abff0..be5c71f 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -14,7 +14,7 @@ __all__ = ("Dependencies",)
 import itertools
 from functools import cache
 from enum import Enum
-from typing import List, Dict
+from typing import List, Dict, Iterable, Iterator, Set, Optional, Any, Union
 
 import portage
 from portage.dep import paren_reduce
@@ -22,6 +22,7 @@ from portage.dep import paren_reduce
 from gentoolkit import errors
 from gentoolkit.atom import Atom
 from gentoolkit.query import Query
+from gentoolkit.cpv import CPV
 
 # =======
 # Classes
@@ -52,10 +53,11 @@ class Dependencies(Query):
 
     """
 
-    def __init__(self, query, parser=None):
+    def __init__(self, query: Any, parser: Any = None) -> None:
         Query.__init__(self, query)
-        self.use = []
-        self.depatom = ""
+        self.use: List[str] = []
+        self.depatom: Optional[Atom] = None
+        self.depth: Optional[int] = None
 
         # Allow a custom parser function:
         self.parser = parser if parser else self._parser
@@ -185,15 +187,13 @@ class Dependencies(Query):
 
     def graph_reverse_depends(
         self,
-        pkgset=None,
-        max_depth=-1,
-        only_direct=True,
-        printer_fn=None,
+        pkgset: Iterable[Union[str, CPV]],
+        max_depth: Optional[int] = None,
+        only_direct: bool = True,
         # The rest of these are only used internally:
-        depth=0,
-        seen=None,
-        result=None,
-    ):
+        depth: int = 0,
+        seen: Optional[Set[str]] = None,
+    ) -> Iterator["Dependencies"]:
         """Graph direct reverse dependencies for self.
 
         Example usage:
@@ -201,10 +201,10 @@ class Dependencies(Query):
                 >>> ffmpeg = Dependencies('media-video/ffmpeg-9999')
                 >>> # I only care about installed packages that depend on me:
                 ... from gentoolkit.helpers import get_installed_cpvs
-                >>> # I want to pass in a sorted list. We can pass strings or
-                ... # Package or Atom types, so I'll use Package to sort:
+                >>> # I want to pass in a list. We can pass strings or
+                ... # Package or Atom types.
                 ... from gentoolkit.package import Package
-                >>> installed = sorted(get_installed_cpvs())
+                >>> installed = get_installed_cpvs()
                 >>> deptree = ffmpeg.graph_reverse_depends(
                 ...     only_direct=False,  # Include indirect revdeps
                 ...     pkgset=installed)   # from installed pkgset
@@ -212,82 +212,52 @@ class Dependencies(Query):
                 24
 
         @type pkgset: iterable
-        @keyword pkgset: sorted pkg cpv strings or anything sublassing
+        @keyword pkgset: pkg cpv strings or anything sublassing
                 L{gentoolkit.cpv.CPV} to use for calculate our revdep graph.
-        @type max_depth: int
+        @type max_depth: optional
         @keyword max_depth: Maximum depth to recurse if only_direct=False.
-                -1 means no maximum depth;
-                 0 is the same as only_direct=True;
+                None means no maximum depth;
+                0 is the same as only_direct=True;
                 >0 means recurse only this many times;
         @type only_direct: bool
         @keyword only_direct: to recurse or not to recurse
-        @type printer_fn: callable
-        @keyword printer_fn: If None, no effect. If set, it will be applied to
-                each L{gentoolkit.atom.Atom} object as it is added to the results.
-        @rtype: list
+        @rtype: iterable
         @return: L{gentoolkit.dependencies.Dependencies} objects
         """
-        if not pkgset:
-            err = (
-                "%s kwarg 'pkgset' must be set. "
-                "Can be list of cpv strings or any 'intersectable' object."
-            )
-            raise errors.GentoolkitFatalError(err % (self.__class__.__name__,))
 
         if seen is None:
             seen = set()
-        if result is None:
-            result = list()
 
-        if depth == 0:
-            pkgset = tuple(Dependencies(x) for x in pkgset)
-
-        pkgdep = None
-        for pkgdep in pkgset:
+        for pkgdep in (Dependencies(pkg) for pkg in pkgset):
             if self.cp not in pkgdep.get_raw_depends():
                 # fast path for obviously non-matching packages. This saves
                 # us the work of instantiating a whole Atom() for *every*
                 # dependency of *every* package in pkgset.
                 continue
 
-            all_depends = pkgdep.get_all_depends()
-            dep_is_displayed = False
-            for dep in all_depends:
-                # TODO: Add ability to determine if dep is enabled by USE flag.
-                #       Check portage.dep.use_reduce
+            found_match = False
+            for dep in pkgdep.get_all_depends():
                 if dep.intersects(self):
+                    pkgdep.depatom = dep
                     pkgdep.depth = depth
-                    pkgdep.matching_dep = dep
-                    if printer_fn is not None:
-                        printer_fn(pkgdep, dep_is_displayed=dep_is_displayed)
-                    result.append(pkgdep)
-                    dep_is_displayed = True
-
-            # if --indirect specified, call ourselves again with the dep
-            # Do not call if we have already called ourselves.
+                    yield pkgdep
+                    found_match = True
+
             if (
-                dep_is_displayed
-                and not only_direct
+                found_match
                 and pkgdep.cpv not in seen
-                and (depth < max_depth or max_depth == -1)
+                and only_direct is False
+                and (max_depth is None or depth < max_depth)
             ):
                 seen.add(pkgdep.cpv)
-                result.append(
-                    pkgdep.graph_reverse_depends(
-                        pkgset=pkgset,
-                        max_depth=max_depth,
-                        only_direct=only_direct,
-                        printer_fn=printer_fn,
-                        depth=depth + 1,
-                        seen=seen,
-                        result=result,
-                    )
+                yield from pkgdep.graph_reverse_depends(
+                    pkgset=pkgset,
+                    only_direct=False,
+                    max_depth=max_depth,
+                    depth=depth + 1,
+                    seen=seen,
                 )
 
-        if depth == 0:
-            return result
-        return pkgdep
-
     def _parser(self, deps, use_conditional=None, depth=0):
         """?DEPEND file parser.
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/
@ 2024-05-03  5:55 Sam James
  0 siblings, 0 replies; 23+ messages in thread
From: Sam James @ 2024-05-03  5:55 UTC (permalink / raw
  To: gentoo-commits

commit:     2e5933f2972a700cbb8bd15a2464dcdd383918ca
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri May  3 05:53:46 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May  3 05:53:46 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=2e5933f2

package: update example PORTDIR path

Signed-off-by: Sam James <sam <AT> gentoo.org>

 pym/gentoolkit/package.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py
index 2159782..e3dd092 100644
--- a/pym/gentoolkit/package.py
+++ b/pym/gentoolkit/package.py
@@ -1,5 +1,5 @@
 # Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright(c) 2004-2010, Gentoo Foundation
+# Copyright(c) 2004-2024, Gentoo Authors
 #
 # Licensed under the GNU General Public License, v2
 
@@ -13,7 +13,7 @@ important parts of Portage's back-end.
 Example usage:
 	>>> portage = Package('sys-apps/portage-9999')
 	>>> portage.ebuild_path()
-	'/usr/portage/sys-apps/portage/portage-9999.ebuild'
+	'/var/db/repos/gentoo/sys-apps/portage/portage-9999.ebuild'
 	>>> portage.is_masked()
 	True
 	>>> portage.is_installed()
@@ -318,7 +318,7 @@ class Package(CPV):
         Example usage:
                 >>> pkg = Package('sys-apps/portage-9999')
                 >>> pkg.ebuild_path()
-                '/usr/portage/sys-apps/portage/portage-9999.ebuild'
+                '/var/db/repos/gentoo/sys-apps/portage/portage-9999.ebuild'
                 >>> pkg.ebuild_path(in_vartree=True)
                 '/var/db/pkg/sys-apps/portage-9999/portage-9999.ebuild'
         """


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-05-03  5:55 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-24  8:06 [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/ Michał Górny
  -- strict thread matches above, loose matches on Subject: below --
2024-05-03  5:55 Sam James
2024-03-07 18:49 Sam James
2024-03-07 15:08 Sam James
2024-02-17  0:01 Sam James
2024-02-16 20:39 Sam James
2024-02-16 20:39 Sam James
2024-02-16 20:39 Sam James
2022-12-14  9:24 Sam James
2022-07-10  7:53 Brian Dolbec
2022-07-10  7:53 Brian Dolbec
2021-09-21 21:01 Matt Turner
2020-10-13 14:14 Brian Dolbec
2020-10-09  6:29 Georgy Yakovlev
2019-07-29  0:51 Zac Medico
2019-05-11 22:43 Virgil Dupras
2018-09-17 23:32 Virgil Dupras
2017-09-06 18:33 Paul Varner
2016-09-15 16:02 Brian Dolbec
2016-08-16 16:05 Paul Varner
2016-07-25 18:04 Paul Varner
2016-07-08 15:37 Brian Dolbec
2015-10-22 16:13 Paul Varner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox