def remove_unfulfilled_dependencies(leaf, raise_on_missing = true, processed = {})
      tree.dependencies.each do |package, dependency|
        dependency.versions.select! do |version, leaf|
          if processed[version]
            true
          else
            processed[version] = true

            # Remove unfulfilled transitive dependencies
            remove_unfulfilled_dependencies(leaf, false, processed)
            valid = true
            leaf.dependencies.each do |k, v|
              valid = false if v.versions.empty?
            end
            valid
          end
        end
        if dependency.versions.empty? && raise_on_missing
          error("No valid version found for package #{package}")
        end
      end
    end
def remove_unfulfilled_dependencies(leaf, raise_on_missing = true, processed = {})
      tree.dependencies.each do |package, dependency|
        dependency.versions.select! do |version, leaf|
          if processed[version]
            true
          else
            processed[version] = true

            # Remove unfulfilled transitive dependencies
            remove_unfulfilled_dependencies(leaf, false, processed)
            valid = true
            leaf.dependencies.each do |k, v|
              valid = false if v.versions.empty?
            end
            valid
          end
        end
        if dependency.versions.empty? && raise_on_missing
          error("No valid version found for package #{package}")
        end
      end
    end
Recursively remove any dependency for which no version is locally
 available. If no version is found for any of the dependencies specified
 by the user, an error is raised.

 The processed hash is used for keeping track of dependencies that were
 already processed, and thus deal with circular dependencies.