From f6df65e2d97a42659e4f2f3cb3243e6187d32f5a Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 19 Mar 2013 12:33:57 -0700 Subject: [PATCH] _get_slot_re: relocate due to circular import --- pym/portage/dbapi/vartree.py | 4 ++-- pym/portage/dep/__init__.py | 21 +-------------------- pym/portage/update.py | 4 ++-- pym/portage/versions.py | 23 ++++++++++++++++++++++- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index d011c33b3..77220bb5b 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -15,7 +15,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.dbapi._MergeProcess:MergeProcess', 'portage.dbapi._SyncfsProcess:SyncfsProcess', 'portage.dep:dep_getkey,isjustname,isvalidatom,match_from_list,' + \ - 'use_reduce,_get_slot_re,_slot_separator,_repo_separator', + 'use_reduce,_slot_separator,_repo_separator', 'portage.eapi:_get_eapi_attrs', 'portage.elog:collect_ebuild_messages,collect_messages,' + \ 'elog_process,_merge_logentries', @@ -38,7 +38,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util._eventloop.EventLoop:EventLoop', 'portage.util._eventloop.global_event_loop:global_event_loop', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,vercmp,' + \ - '_pkgsplit@pkgsplit,_pkg_str,_unknown_repo', + '_get_slot_re,_pkgsplit@pkgsplit,_pkg_str,_unknown_repo', 'subprocess', 'tarfile', ) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 1edbab76f..6f3b35739 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -29,7 +29,7 @@ from portage.eapi import _get_eapi_attrs from portage.exception import InvalidAtom, InvalidData, InvalidDependString from portage.localization import _ from portage.versions import catpkgsplit, catsplit, \ - vercmp, ververify, _cp, _cpv, _pkg_str, _unknown_repo + vercmp, ververify, _cp, _cpv, _pkg_str, _slot, _unknown_repo import portage.cache.mappings if sys.hexversion >= 0x3000000: @@ -43,7 +43,6 @@ else: # PMS 3.1.3: A slot name may contain any of the characters [A-Za-z0-9+_.-]. # It must not begin with a hyphen or a dot. _slot_separator = ":" -_slot = r'([\w+][\w+.-]*)' # loosly match SLOT, which may have an optional ABI part _slot_loose = r'([\w+./*=-]+)' @@ -57,24 +56,6 @@ _repo = r'(?:' + _repo_separator + '(' + _repo_name + ')' + ')?' _extended_cat = r'[\w+*][\w+.*-]*' -_slot_re_cache = {} - -def _get_slot_re(eapi_attrs): - cache_key = eapi_attrs.slot_operator - slot_re = _slot_re_cache.get(cache_key) - if slot_re is not None: - return slot_re - - if eapi_attrs.slot_operator: - slot_re = _slot + r'(/' + _slot + r')?' - else: - slot_re = _slot - - slot_re = re.compile('^' + slot_re + '$', re.VERBOSE | re.UNICODE) - - _slot_re_cache[cache_key] = slot_re - return slot_re - _slot_dep_re_cache = {} def _get_slot_dep_re(eapi_attrs): diff --git a/pym/portage/update.py b/pym/portage/update.py index be52164b5..92aba9af8 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -16,13 +16,13 @@ from portage import _unicode_decode from portage import _unicode_encode import portage portage.proxy.lazyimport.lazyimport(globals(), - 'portage.dep:Atom,dep_getkey,isvalidatom,_get_slot_re', + 'portage.dep:Atom,dep_getkey,isvalidatom,match_from_list', 'portage.util:ConfigProtect,new_protect_filename,' + \ 'normalize_path,write_atomic,writemsg', + 'portage.versions:_get_slot_re', ) from portage.const import USER_CONFIG_PATH, VCS_DIRS -from portage.dep import match_from_list from portage.eapi import _get_eapi_attrs from portage.exception import DirectoryNotFound, InvalidAtom, PortageException from portage.localization import _ diff --git a/pym/portage/versions.py b/pym/portage/versions.py index 46c53089b..3bfc388ea 100644 --- a/pym/portage/versions.py +++ b/pym/portage/versions.py @@ -21,7 +21,6 @@ else: import portage portage.proxy.lazyimport.lazyimport(globals(), - 'portage.dep:_get_slot_re', 'portage.repository.config:_gen_valid_repo', 'portage.util:cmp_sort_key', ) @@ -34,6 +33,10 @@ _unknown_repo = "__unknown__" # \w is [a-zA-Z0-9_] +# PMS 3.1.3: A slot name may contain any of the characters [A-Za-z0-9+_.-]. +# It must not begin with a hyphen or a dot. +_slot = r'([\w+][\w+.-]*)' + # 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-]. # It must not begin with a hyphen or a dot. _cat = r'[\w+][\w+.-]*' @@ -68,6 +71,24 @@ suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$") suffix_value = {"pre": -2, "p": 0, "alpha": -4, "beta": -3, "rc": -1} endversion_keys = ["pre", "p", "alpha", "beta", "rc"] +_slot_re_cache = {} + +def _get_slot_re(eapi_attrs): + cache_key = eapi_attrs.slot_operator + slot_re = _slot_re_cache.get(cache_key) + if slot_re is not None: + return slot_re + + if eapi_attrs.slot_operator: + slot_re = _slot + r'(/' + _slot + r')?' + else: + slot_re = _slot + + slot_re = re.compile('^' + slot_re + '$', re.VERBOSE | re.UNICODE) + + _slot_re_cache[cache_key] = slot_re + return slot_re + _pv_re_cache = {} def _get_pv_re(eapi_attrs): -- 2.26.2