def get_provides(package): provides = {} package_version = Version.CommonVersion(package.get_version()) for provision in package.get_provides(): name, vers = Version.SplitProvision(provision) provides[name] = vers or package_version return provides
def set_requires_python(self, value): if not isinstance(value, list): value = [v.strip() for v in value.split(',')] for v in value: if v[-1:] != '*': Version.SplitComparison(v) self.requires_python = value
def set_obsoletes(self, value): for v in value: Version.VersionPredicate(v) self.obsoletes = value
def set_provides(self, value): for v in value: Version.SplitProvision(v) self.provides = value
def set_requires(self, value): for v in value: Version.VersionPredicate(v) self.requires = value
def set_requires_external(self, value): for v in value: Version.SplitComparison(v) self.requires_external = value
def finalize_options(self): if sys.version < '2.5': # Run the setter functions for the metadata fields that have them. # Only those fields that have a supplied value (not None) will # be considered. for name, value in vars(self.metadata).items(): if value is not None: try: setter = getattr(self.metadata, 'set_' + name) except AttributeError: pass else: setter(value) requires_python = self.get_requires_python() if requires_python: requires_python = 'Python (%s)' % ', '.join(requires_python) requires_python = Version.VersionPredicate(requires_python) python_version = version.StrictVersion() python_version.version = sys.version_info[:3] python_version.prerelease = sys.version_info[3:] if not requires_python.satisfied_by(python_version): raise DistutilsSetupError( "%s requires %s" % (self.metadata.name, requires_python)) # Initialize the containter type data variables before dealing # with the information from the package defintions. if self.packages is None: self.packages = [] if self.package_dir is None: self.package_dir = {} if self.py_modules is None: self.py_modules = [] if self.libraries is None: self.libraries = [] if self.headers is None: self.headers = [] if self.ext_modules is None: self.ext_modules = [] if self.include_dirs is None: self.include_dirs = [] if self.scripts is None: self.scripts = [] if self.data_files is None: self.data_files = [] if self.package_file is None: self.package_file = self.script_name if self.namespace_packages is None: self.namespace_packages = [] # Per PEP 314, only use License and Platform if they can't be # handled by an appropriate classifier. Or, in our case, aren't # being handled by a classifier entry. has_platform = has_license = False for classifier in self.get_classifiers(): category = classifier.split('::', 1)[0] category = category.strip().title() if category == 'Operating System': has_platform = True elif category == 'License': has_license = True if self.metadata.license and has_license: raise DistutilsSetupError("license keyword conflicts with" " classifiers list") if self.metadata.platforms and has_platform: raise DistutilsSetupError("platforms keyword conflicts with" " classifiers list") # Finalize "private" variables; those that are not part of the # setup arguments. self._allfiles = None Distribution.finalize_options(self)
def _sort_distributions(self, distributions): """ Sort a list of distribution objects based on the "internal" 'requires' and 'provides' lists. """ if DEBUG: print "PackageManager._sort_distributions():" def get_provides(package): provides = {} package_version = Version.CommonVersion(package.get_version()) for provision in package.get_provides(): name, vers = Version.SplitProvision(provision) provides[name] = vers or package_version return provides # Find all of the local provisions, either installed or from the # sub-packages. installed_provides = {} for package in self._find_installed_packages(): installed_provides.update(get_provides(package)) package_provides = {} for dist in distributions: package_provides.update(get_provides(dist)) # Sort them based on their requirements. unsorted = list(distributions) satisfied = {} sorted = [] while unsorted: changed = 0 if DEBUG: print " begin sort:" # Iterate over a copy of the unsorted distributions as it is # modified while iterating. for dist in tuple(unsorted): if DEBUG: print " trying", dist.get_name() for req in dist.get_requires(): req = Version.VersionPredicate(req) if req.name in package_provides: # requirement provided by a sub-package if req.name in satisfied: continue else: break if req.name in installed_provides: if not req.satisfied_by(installed_provides[req.name]): raise DistutilsSetupError( "requirement '%s' not satisfied" % req) elif req.name not in installed_provides: # a "classic" package; try to import the requirement # as a module. try: __import__(req.name) except ImportError: raise DistutilsSetupError( "requirement '%s' not found" % req) else: # XXX - how to test the version requirement? pass else: if DEBUG: print " sorted", dist.get_name() satisfied.update(get_provides(dist)) sorted.append(dist) unsorted.remove(dist) changed = 1 if not changed: names = ', '.join([dist.get_name() for dist in unsorted]) raise DistutilsFileError("circular dependency: %s" % names) if DEBUG: names = ', '.join([dist.get_name() for dist in sorted]) print " sorted:", names return sorted