-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: fix index.json -> yaml script. #221
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import argparse | ||
import collections | ||
import json | ||
import operator | ||
import sys | ||
|
||
import six | ||
import yaml | ||
|
||
from okonomiyaki.versions import EnpkgVersion | ||
|
@@ -12,10 +14,63 @@ | |
from simplesat.constraints.kinds import ( | ||
Any, EnpkgUpstreamMatch, Equal | ||
) | ||
from simplesat.test_utils import repository_from_index | ||
from simplesat.package import ( | ||
PackageMetadata, RepositoryInfo, RepositoryPackageMetadata | ||
) | ||
from simplesat.repository import Repository | ||
|
||
|
||
def parse_index_packages_to_install_requires(packages): | ||
name_to_install_requires = {} | ||
|
||
for dependency in packages: | ||
parts = dependency.split(None, 1) | ||
name = parts[0].lower() | ||
name_to_install_requires.setdefault(name, []) | ||
|
||
if len(parts) == 1: | ||
constraint = "*" | ||
else: | ||
version_part = parts[1] | ||
package_version = EnpkgVersion.from_string(version_part) | ||
if package_version.build == 0: | ||
constraint = "^= {0}".format(version_part) | ||
else: | ||
constraint = "== {0}".format(version_part) | ||
|
||
name_to_install_requires[name].append(constraint) | ||
|
||
return dict( | ||
(name, tuple(value)) | ||
for name, value in six.iteritems(name_to_install_requires) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You iterate over the entries to create a |
||
) | ||
|
||
|
||
def repository_from_index(index_path): | ||
with open(index_path, "rt") as fp: | ||
json_dict = json.load(fp) | ||
|
||
repository = Repository() | ||
repository_info = RepositoryInfo("remote") | ||
|
||
for key, entry in six.iteritems(json_dict): | ||
raw_name = key.split("-")[0].lower() | ||
version_string = "{0}-{1}".format(entry["version"], entry["build"]) | ||
version = EnpkgVersion.from_string(version_string) | ||
name_to_install_requires = parse_index_packages_to_install_requires( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Two spaces after operator |
||
entry.get("packages", []) | ||
) | ||
install_requires = tuple( | ||
(name, (constraints,)) | ||
for name, constraints in six.iteritems(name_to_install_requires) | ||
) | ||
package = RepositoryPackageMetadata( | ||
PackageMetadata(raw_name, version, install_requires), repository_info | ||
) | ||
repository.add_package(package) | ||
|
||
return repository | ||
|
||
# TODO Can use new enstaller pretty printer here... | ||
|
||
def dependency_to_string(dependency): | ||
req = InstallRequirement._from_string(dependency) | ||
|
@@ -30,11 +85,11 @@ def dependency_to_string(dependency): | |
return "{0} == {1}".format(req.name, str(constraint.version)) | ||
else: # EnpkgUpstreamMatch | ||
assert isinstance(constraint.version, EnpkgVersion) | ||
return "{0} ~= {1}".format(req.name, str(constraint.version.upstream)) | ||
return "{0} ^= {1}".format(req.name, str(constraint.version.upstream)) | ||
|
||
|
||
def requirements_string(package): | ||
name = package.key.split("-")[0] | ||
name = package.name | ||
template = "{name} {version}" | ||
if len(package.install_requires) > 0: | ||
template += "; depends ({install_requires})" | ||
|
@@ -57,8 +112,7 @@ def main(argv=None): | |
|
||
data = collections.defaultdict(list) | ||
|
||
for package in sorted(repository.iter_packages(), | ||
key=operator.attrgetter("name")): | ||
for package in repository: | ||
data["packages"].append(requirements_string(package)) | ||
|
||
data = dict(data) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operator
is no longer used