@classmethod
    def from_string(cls, pool, rule_string, reason, reason_details="", job=None, id=-1):
        """
        Creates a PackageRule from a rule string, e.g. '-numpy-1.6.0 | numpy-1.7.0'

        Because package full name -> id is not 1-to-1 mapping, this may fail
        when a package has multiple ids. This is mostly used for testing, to
        write reference rules a bit more easily.
        """
        packages_string = (s.strip() for s in rule_string.split("|"))
        package_literals = []
        for package_string in packages_string:
            if package_string.startswith("-"):
                positive = False
                package_string = package_string[1:]
            else:
                positive = True

            requirement = Requirement.from_package_string(package_string)
            package_candidates = pool.what_provides(requirement)
            if len(package_candidates) == 0:
                raise ValueError(package_string % "No candidate for package %s")
            elif len(package_candidates) > 1:
                msg = "> 1 candidate for package %s requirement, cannot " \
                      "create rule from it" % package_string
                raise ValueError(msg)
            else:
                if positive:
                    package_literals.append(package_candidates[0].id)
                else:
                    package_literals.append(-package_candidates[0].id)

        return cls(pool, package_literals, reason, reason_details, job, id)
dataset/ETHPy150Open enthought/depsolver/depsolver/solver/rule.py/PackageRule.from_string/swapped operands of `%`