def stop(self, request, queryset): try: if queryset.count() > 1: self.message_user(request, "Choose only one campaign") else: campaign = queryset[0] #stop.delay() campaign.status = STOP campaign.save() except Exception, e: logger.warning(e, exc_info=True )
def run(self, request, queryset): try: if queryset.count() > 1: self.message_user(request, "Choose only one campaign") else: campaign = queryset[0] check_date.delay(campaign.id) campaign.status = RUN campaign.save() except Exception, e: logger.warning(e, exc_info=True )
def trace_requirements(requirements): """given an iterable of pip InstallRequirements, return the set of required packages, given their transitive requirements. """ requirements = tuple(pretty_req(r) for r in requirements) working_set = fresh_working_set() # breadth-first traversal: from collections import deque queue = deque(requirements) queued = {_package_req_to_pkg_resources_req(req.req) for req in queue} errors = [] result = [] while queue: req = queue.popleft() logger.debug('tracing: %s', req) try: dist = working_set.find_normalized( _package_req_to_pkg_resources_req(req.req)) except pkg_resources.VersionConflict as conflict: dist = conflict.args[0] errors.append('Error: version conflict: %s (%s) <-> %s' % (dist, timid_relpath(dist.location), req)) assert dist is not None, 'Should be unreachable in pip8+' result.append(dist_to_req(dist)) # TODO: pip does no validation of extras. should we? extras = [extra for extra in req.extras if extra in dist.extras] for sub_req in sorted(dist.requires(extras=extras), key=lambda req: req.key): sub_req = InstallRequirement(sub_req, req) if req_cycle(sub_req): logger.warning('Circular dependency! %s', sub_req) continue elif sub_req.req in queued: logger.debug('already queued: %s', sub_req) continue else: logger.debug('adding sub-requirement %s', sub_req) queue.append(sub_req) queued.add(sub_req.req) if errors: raise InstallationError('\n'.join(errors)) return result
def add_requirement(self, install_req, parent_req_name=None, **kwargs): """Add install_req as a requirement to install. :param parent_req_name: The name of the requirement that needed this added. The name is used because when multiple unnamed requirements resolve to the same name, we could otherwise end up with dependency links that point outside the Requirements set. parent_req must already be added. Note that None implies that this is a user supplied requirement, vs an inferred one. :param extras_requested: an iterable of extras used to evaluate the environement markers (only pip>=9.0.0). :return: Additional requirements to scan. That is either [] if the requirement is not applicable, or [install_req] if the requirement is applicable and has just been added. *pip_compile modifications:* This implementation has been copied verbatim from pip 7.1.2, and the only modification is the new else clause which handles duplicate constraints. The signature contains ``**kwargs`` instead of ``extras_requested=`` since that keyword argument only appeared in 9.0.0 and we still want to support pip 8.1.2. Requirements are checked against constraints, and mismatches in versions and/or editability raise an error. As an exception to this rule, requirements from local directories override constraints pointing to Git repositories. """ name = install_req.name if not install_req.match_markers(**kwargs): logger.warning( "Ignoring %s: markers %r don't match your " "environment", install_req.name, install_req.markers) return [] install_req.as_egg = self.as_egg install_req.use_user_site = self.use_user_site install_req.target_dir = self.target_dir install_req.pycompile = self.pycompile if not name: # url or path requirement w/o an egg fragment self.unnamed_requirements.append(install_req) return [install_req] else: try: existing_req = self.get_requirement(name) except KeyError: existing_req = None if (parent_req_name is None and existing_req and not existing_req.constraint): if self._allow_double: logger.warn('Allowing double requirement: {} (already in ' '{}, name={!r}).'.format( install_req, existing_req, name)) else: raise InstallationError( 'Double requirement given: %s (already in %s, name=%r)' % (install_req, existing_req, name)) if not existing_req: # Add requirement self.requirements[name] = install_req # FIXME: what about other normalizations? E.g., _ vs. -? if name.lower() != name: self.requirement_aliases[name.lower()] = name result = [install_req] # FIXME: Should result be empty if install_req is a constraint? else: if not existing_req.constraint: # No need to scan, we've already encountered this for # scanning. result = [] elif not install_req.constraint: # If we're now installing a constraint, mark the existing # object for real installation. existing_req.constraint = False # Bugfix for pip 7.1.2: Report the origin of the actual # package for installation (i.e. the -r file) instead of a # constraint file. existing_req.comes_from = install_req.comes_from if install_req.editable and not existing_req.editable: if local_overrides_git(install_req, existing_req): logger.warn( 'Overriding non-editable constraint {} ' 'with editable requirement {}'.format( existing_req, install_req)) else: raise InstallationError( '--editable / -e {} was a requirement but the ' 'constraint "{}" is non-editable. Cannot ' 'resolve this conflict.'.format( install_req.name, existing_req)) if install_req.link: install_link = re.sub('#.*', '', install_req.link.url) existing_link = re.sub('#.*', '', existing_req.link.url) if install_link != existing_link: if local_overrides_git(install_req, existing_req): logger.warn( 'Overriding constraint from Git repository ' '{} with local directory {} '.format( existing_link, install_link)) else: raise InstallationError( 'Requirement: {}\n' 'Constraint: {}\n' 'Cannot resolve this conflict.'.format( install_req, existing_req)) # And now we need to scan this. result = [existing_req] else: # both existing_req and install_req are constraints # This else clause is an extension to pip 7.1.12: # VCS links override plain package specifiers # if there are duplicates in constraints. if install_req.link and not existing_req.link: # Our assumption is that dependencies are populated only # later. Is this correct? assert not self._dependencies if name != existing_req.name: # The Requirement class has no __delitem__() del self.requirements._dict[existing_req.name] self.requirements._keys.remove(existing_req.name) self.requirements[name] = install_req if name.lower() != name: self.requirement_aliases[name.lower()] = name elif not install_req.link and existing_req.link: # Only the existing constraint was a link, so abandon # the new looser constraint pass else: # All other constraint conflicts are unresolved for the # time being. raise InstallationError( 'Duplicate constraint {}, existing {}'.format( install_req, existing_req)) result = [] # Canonicalise to the already-added object for the backref # check below. install_req = existing_req if parent_req_name: parent_req = self.get_requirement(parent_req_name) self._dependencies[parent_req].append(install_req) return result
def run(self, options, args): if options.allow_double and not options.constraints: raise Exception( '--allow-double can only be used together with -c /' '--constraint') cmdoptions.resolve_wheel_no_use_binary(options) cmdoptions.check_install_build_global(options) # Removed handling for the following options which are not included in # pip_compile: # options.allow_external # options.allow_all_external # options.allow_unverified # options.download_dir # options.ignore_installed if options.build_dir: options.build_dir = os.path.abspath(options.build_dir) options.src_dir = os.path.abspath(options.src_dir) # pip_compile skips building of install_options since it doesn't install # anything: # options.use_user_site: # --user # --prefix= # options.target_dir: # options.ignore_installed # --home= # options.global_options with self._build_session(options) as session: finder = self._build_package_finder(options, session) build_delete = (not (options.no_clean or options.build_dir)) wheel_cache = WheelCache(options.cache_dir, options.format_control) if options.cache_dir and not check_path_owner(options.cache_dir): logger.warning( "The directory '%s' or its parent directory is not owned " "by the current user and caching wheels has been " "disabled. check the permissions and owner of that " "directory. If executing pip with sudo, you may want " "sudo's -H flag.", options.cache_dir, ) options.cache_dir = None with BuildDirectory(options.build_dir, delete=build_delete) as build_dir: requirement_set = PipCompileRequirementSet( build_dir=build_dir, src_dir=options.src_dir, download_dir=None, # not needed # upgrade - option not needed # as_egg - option not needed ignore_installed=True, # always ignore installed ignore_dependencies=options.ignore_dependencies, # force_reinstall - option not needed # use_user_site - option not needed # target_dir - option not needed session=session, # pycompile - option not needed isolated=options.isolated_mode, wheel_cache=wheel_cache, # require_hashes - option not needed? allow_double=options.allow_double) self.populate_requirement_set(requirement_set, args, options, finder, session, self.name, wheel_cache) # Additional pip_compile functionality: constraints constraints = set() for filename in options.constraints: for req in parse_requirements(filename, constraint=True, finder=finder, options=options, session=session, wheel_cache=wheel_cache): constraints.add(req.name) # Additional pip_compile functionality: fail with an error # message if any resolved package is not pinned to an exact # version in constraints, unless it comes from a local directory self.fail_if_any_unpinned_packages(options, finder, requirement_set, constraints) # Conditions for whether to build wheels differ in pip_compile # from original pip: if not options.flat and requirement_set.has_requirements: if not wheel or not options.cache_dir: # on -d don't do complex things like building # wheels, and don't try to build wheels when wheel is # not installed. requirement_set.prepare_files(finder) else: # build wheels before install. wb = WheelBuilder( requirement_set, finder, build_options=[], global_options=[], ) # Ignore the result: a failed wheel will be # installed from the sdist/vcs whatever. wb.build(autobuilding=True) # pip_compile adds printing out the compiled requirements: if options.output == '-': print_requirements(requirement_set) elif options.output: with open(options.output, 'w') as output: print_requirements(requirement_set, output) if options.json_output == '-': json.dump(requirement_set.to_dict(), sys.stdout, indent=4) elif options.json_output: with open(options.json_output, 'w') as output: json.dump(requirement_set.to_dict(), output, indent=4) # pip_compile skips package installation return requirement_set