[Python-checkins] python/dist/src/Lib/distutils core.py, 1.59, 1.60 dist.py, 1.65, 1.66

anthonybaxter at users.sourceforge.net anthonybaxter at users.sourceforge.net
Mon Mar 22 17:22:07 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/distutils
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11533

Modified Files:
	core.py dist.py 
Log Message:
Basic dependency checking. setup() has two new optional arguments 
requires and provides. requires is a sequence of strings, of the 
form 'packagename-version'. The dependency checking so far merely
does an '__import__(packagename)' and checks for packagename.__version__
You can also leave off the version, and any version of the package 
will be installed.
There's a special case for the package 'python' - sys.version_info
is used, so 
requires= ( 'python-2.3', ) 
just works.

Provides is of the same format as requires - but if it's not supplied,
a provides is generated by adding the version to each entry in packages,
or modules if packages isn't there. 
Provides is currently only used in the PKG-INFO file. Shortly, PyPI
will grow the ability to accept these lines, and register will be 
updated to send them. 

There's a new command 'checkdep' command that runs these checks. 
For this version, only greater-than-or-equal checking is done. We'll
add the ability to specify an optional operator later.


Index: core.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/distutils/core.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** core.py	12 Feb 2004 17:35:08 -0000	1.59
--- core.py	22 Mar 2004 22:22:04 -0000	1.60
***************
*** 48,52 ****
                    'maintainer', 'maintainer_email', 'url', 'license',
                    'description', 'long_description', 'keywords',
!                   'platforms', 'classifiers', 'download_url')
  
  # Legal keyword arguments for the Extension constructor
--- 48,53 ----
                    'maintainer', 'maintainer_email', 'url', 'license',
                    'description', 'long_description', 'keywords',
!                   'platforms', 'classifiers', 'download_url',
!                   'provides', 'requires', )
  
  # Legal keyword arguments for the Extension constructor

Index: dist.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/distutils/dist.py,v
retrieving revision 1.65
retrieving revision 1.66
diff -C2 -d -r1.65 -r1.66
*** dist.py	17 Feb 2004 22:35:19 -0000	1.65
--- dist.py	22 Mar 2004 22:22:04 -0000	1.66
***************
*** 215,218 ****
--- 215,263 ----
                      sys.stderr.write(msg + "\n")
  
+             # Build up the requires sequence
+             from distutils.version import LooseVersion
+             requires = attrs.get('requires')
+             if requires:
+                 if isinstance(requires, type('')):
+                     raise DistutilsOptionError, 'requires should be a sequence'
+                 newreq = []
+                 for req in requires:
+                     if '-' not in req:
+                         # We have a plain package name - any version will do
+                         newreq.append((req,None))
+                     else:
+                         pkg, ver = string.split(req, '-', 1)
+                         newreq.append((pkg, LooseVersion(ver)))
+                 attrs['requires'] = newreq
+ 
+             # Build up the provides object. If the setup() has no 
+             # provides line, we use packages or modules and the version
+             # to synthesise the provides. If no version is provided (no
+             # pun intended) we don't have a provides entry at all.
+             provides = attrs.get('provides')
+             if provides:
+                 if isinstance(provides, type('')):
+                     raise DistutilsOptionError, 'provides should be a sequence'
+                 newprov = []
+                 for prov in provides:
+                     if '-' not in prov:
+                         # We have a plain package name - any version will do
+                         newprov.append((prov,None))
+                     else:
+                         pkg, ver = string.split(prov, '-', 1)
+                         newprov.append((pkg, LooseVersion(ver)))
+                 attrs['provides'] = newprov
+             elif attrs.get('version'):
+                 # Build a provides line
+                 prov = []
+                 if attrs.get('packages'):
+                     for pkg in attrs['packages']:
+                         pkg = string.replace(pkg, '/', '.')
+                         prov.append('%s-%s'%(pkg, attrs['version']))
+                 elif attrs.get('modules'):
+                     for mod in attrs['modules']:
+                         prov.append('%s-%s'%(mod, attrs['version']))
+                 attrs['provides'] = prov
+ 
              # Now work on the rest of the attributes.  Any attribute that's
              # not already defined is invalid!
***************
*** 975,979 ****
                           "keywords", "platforms", "fullname", "contact",
                           "contact_email", "license", "classifiers",
!                          "download_url")
  
      def __init__ (self):
--- 1020,1024 ----
                           "keywords", "platforms", "fullname", "contact",
                           "contact_email", "license", "classifiers",
!                          "download_url", "provides", "requires",)
  
      def __init__ (self):
***************
*** 992,995 ****
--- 1037,1042 ----
          self.classifiers = None
          self.download_url = None
+         self.requires = []
+         self.provides = []
  
      def write_pkg_info (self, base_dir):
***************
*** 1007,1010 ****
--- 1054,1061 ----
          pkg_info.write('Author-email: %s\n' % self.get_contact_email() )
          pkg_info.write('License: %s\n' % self.get_license() )
+         for req in self.get_requires():
+             pkg_info.write('Requires: %s\n' % req )
+         for prov in self.get_provides():
+             pkg_info.write('Provides: %s\n' % prov )
          if self.download_url:
              pkg_info.write('Download-URL: %s\n' % self.download_url)
***************
*** 1085,1088 ****
--- 1136,1146 ----
          return self.download_url or "UNKNOWN"
  
+     def get_requires(self):
+         return [ '%s%s%s'%(x, (y and '-') or '', y or '') 
+                                                 for x,y in self.requires ]
+ 
+     def get_provides(self):
+         return self.provides
+ 
  # class DistributionMetadata
  




More information about the Python-checkins mailing list