Python Code Guidelines
----------------
+----------------------
These are a few guidelines to stick to when modifying or adding code to
Gentoolkit. These guidelines do not apply to pym/gentoolkit/test/*.
...
)
-- Max. line length is strictly 80 characters with a tab length of 4 characters.
+- Preferred line length is 80 characters with a tab length of 4 characters.
- "The preferred way of wrapping long lines is by using Python's implied line
continuation inside parentheses, brackets and braces" rather than using '\'
(PEP 8).
self._descriptions = \
[e.text for e in self._xml_tree.findall("longdescription")]
- BETTER:
+ OK:
self._descriptions = [
e.text for e in self._xml_tree.findall("longdescription")
]
- BEST: (easiest to read and test)
+ OK: (easiest to read and test)
long_descriptions = self._xml_tree.findall("longdescription")
self._descriptions = [e.text for e in long_descriptions]
Other concerns:
---------------
- Choose names which are full, clear words (not necessary in small loops).
-- It is NEVER necessary to prefix names with "my". Consider:
- class FooThinger(object):
- def __init__(self, foo):
- self.myfoo = foo
-
- Just use FooThinger.foo or FooThinger.orig_foo; "my"foo tells us nothing.
+- It is NEVER necessary to prefix names with "my". It adds no useful
+ information.
- Comment and document in simple, unambiguous and non-repetitive English.
- When adding a TODO, FIXME or XXX comment, please date it and add your name so
that other devs know who to ask about the proposed change.
-- Be careful of spelling. DO spell check your source code and be professional
- when writing comments.
+- Be careful of spelling.
# Make operator compatible with intersects
if self.operator is None:
- self.operator = '='
-
- # Make slot a tuple if defined
- # pylint screwup:
- # E1101: 75:Atom.__init__: Instance of 'tuple' has no 'split' member
- # pylint: disable-msg=E1101
- if self.slot is not None:
- self.slot = tuple(sorted(self.slot.split(',')))
+ self.operator = ''
self.cpv = CPV(self.cpv)
'sys-apps/portage-2.2-r1'
>>> # An 'rc' (release candidate) version is less than non 'rc' version:
... CPV('sys-apps/portage-2') > CPV('sys-apps/portage-2_rc10')
+ True
"""
def __init__(self, cpv):
- if not cpv:
- raise errors.GentoolkitInvalidCPV(cpv)
self.scpv = cpv
values = split_cpv(cpv)
Inlined from helpers because of circular imports.
+ @todo: this function is slow and accepts some crazy things for cpv
@type cpv: str
@param cpv: pkg, cat/pkg, pkg-ver, cat/pkg-ver, atom or regex
@rtype: tuple
use_conditional = tok[:-1]
continue
if isinstance(tok, list):
- asdf = self._parser(tok, use_conditional, depth=depth+1)
- result.extend(asdf)
+ sub_r = self._parser(tok, use_conditional, depth=depth+1)
+ result.extend(sub_r)
+ use_conditional = None
+ continue
+ if tok[0] == '!':
+ # We're not interested in blockers
continue
atom = Atom(tok)
if use_conditional is not None:
else:
formatted_dep = mdep.operator + str(mdep.cpv)
if mdep.slot:
- formatted_dep += pp.emph(':') + pp.slot(','.join(mdep.slot))
+ formatted_dep += pp.emph(':') + pp.slot(mdep.slot)
if mdep.use:
useflags = pp.useflag(','.join(mdep.use.tokens))
formatted_dep += (pp.emph('[') + useflags + pp.emph(']'))
# slots.
self.assertNotEqual2(Atom('cat/pkg:1'), Atom('cat/pkg'))
self.assertEqual2(Atom('cat/pkg:2'), Atom('cat/pkg:2'))
- self.assertEqual2(Atom('cat/pkg:2,1'), Atom('cat/pkg:2,1'))
- self.assertEqual2(Atom('cat/pkg:2,1'), Atom('cat/pkg:1,2'))
+ # http://dev.gentoo.org/~tanderson/pms/eapi-2-approved/pms.html#x1-190002.1.2
+ self.assertEqual2(Atom('cat/pkg:AZaz09+_.-'), Atom('cat/pkg:AZaz09+_.-'))
for lesser, greater in (('0.1', '1'), ('1', '1-r1'), ('1.1', '1.2')):
self.assertTrue(Atom('=d/b-%s' % lesser) <
Atom('=d/b-%s' % greater),
('=cat/pkg-1-r1*', '<cat/pkg-1-r1', False),
('=cat/pkg-1*', '>cat/pkg-2', False),
('>=cat/pkg-8.4', '=cat/pkg-8.3.4*', False),
- ('cat/pkg::gentoo', 'cat/pkg', True),
- ('cat/pkg::gentoo', 'cat/pkg::foo', False),
+ # Repos not yet supported by Portage
+ #('cat/pkg::gentoo', 'cat/pkg', True),
+ #('cat/pkg::gentoo', 'cat/pkg::foo', False),
('=sys-devel/gcc-4.1.1-r3', '=sys-devel/gcc-3.3*', False),
('=sys-libs/db-4*', '~sys-libs/db-4.3.29', True),
]: