diff options
author | 2010-07-15 14:09:09 +0200 | |
---|---|---|
committer | 2010-07-15 14:09:09 +0200 | |
commit | 76f6eca144b9e1440b13977f38f84832037062ad (patch) | |
tree | 030ad1ad6f6763856cea124ae5b5101832c60356 | |
parent | Adding support for CRAN's serialized package database (diff) | |
download | g-cran-76f6eca144b9e1440b13977f38f84832037062ad.tar.gz g-cran-76f6eca144b9e1440b13977f38f84832037062ad.tar.bz2 g-cran-76f6eca144b9e1440b13977f38f84832037062ad.zip |
Reorganizing code in cran_read.py
-rw-r--r-- | g_cran/cran_read.py | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/g_cran/cran_read.py b/g_cran/cran_read.py index 8e8f840..0e5fb42 100644 --- a/g_cran/cran_read.py +++ b/g_cran/cran_read.py @@ -85,7 +85,7 @@ def pmsify_package_name(name): def pmsify_package_version(version_str): return version_str.replace('-','.') #some CRAN-style versions have the form 0.1-1, which we transform into 0.1.1 -def listify_package_list(package_list): +def listify_depends_field(package_list): matches=re.findall(r'\s*([^,)(]+?)\s*(\([^()]+?\))?\s*([,)(]|$)',package_list) #split into packages + versions packages=[] for package_part in matches: #process each package match @@ -102,24 +102,27 @@ R_recommended_packages=['KernSmooth','MASS','Matrix','base','boot','class','clus 'codetools','datasets','foreign','grDevices','graphics','grid','lattice','methods', 'mgcv','nlme','nnet','rpart','spatial','splines','stats','stats4','survival','tcltk', 'tools','utils',] -#parse dependency list -def pmsify_package_list(package_list, cran_packages): +#parse dependency list of R libraries +def pmsify_R_depends_list(package_list): #note: the following returns a list of tuples pms_packages=[] - portage_packages=portage_possible_deps() + R_use_depend={} for package in package_list: if package=='tcltk': - pms_packages.append('dev-lang/R[tk]') + R_use_depend['tk']='' #depend R[tk] elif package in R_core_packages: - pms_packages.append('dev-lang/R') + pass #packages depend on R anyhow elif package in R_recommended_packages: - pms_packages.append('dev-lang/R[-minimal]') - elif package in cran_packages: - pms_packages.append('dev-R/'+pmsify_package_name(package)) - elif package in portage_packages: - pms_packages.append(portage_packages[package][0]) #get qualified package name from the portage tree - else: #fallback to dev-R and assume it's in another R package repository + R_use_depend['minimal']='-' + else: #should just be an R package pms_packages.append('dev-R/'+pmsify_package_name(package)) + use_deps='' + if len(R_use_depend): #USE deps on dev-lang/R + use_deps='[' + for flag,dep_type in R_use_depend.iteritems(): + use_deps.append(dep_type+flag) + use_deps.append(']') + pms_packages.append('dev-lang/R'+use_deps) return pms_packages #Parse package data loaded from the PACKAGES file @@ -138,12 +141,12 @@ def pmsify_package_data(data,remote_repository): else: e_vars['pv']=pmsify_package_version(data['version']) if 'depends' in data: - deps=listify_package_list(data['depends']) + deps=pmsify_R_depends_list(listify_depends_field(data['depends'])) #make it a list type else: #some packages don't set dependencies, so force dependency on R - deps=['R',] + deps=[] if 'imports' in data: - deps=deps+listify_package_list(data['imports']) + deps=deps+pmsify_R_depends_list(listify_depends_field(data['imports'])) e_vars['depend']=deps e_vars['pdepend']=[] @@ -183,12 +186,6 @@ def read_packages(package_filename,local_repository): if len(cran_package): pms_package=pmsify_package_data(cran_package,remote_uri) #fix values packages[pms_package.cran_data['package']]=pms_package #store in dict - #post-process dependency data, transform to qualified package names - cran_packages=packages.keys() - for cran_name, package in packages.iteritems(): - deps=pmsify_package_list(package.ebuild_vars['depend'],cran_packages) - package.ebuild_vars['depend']=deps - package.ebuild_vars['rdepend']=deps return packages.values() #find a package in this repository... we really should cache this |