Skip to content

Commit

Permalink
some robustness fixes for generating
Browse files Browse the repository at this point in the history
  • Loading branch information
scopatz committed Aug 23, 2020
1 parent 61ccd7a commit 10123e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
46 changes: 31 additions & 15 deletions conda_suggest/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Generates the cache files (which should not be distributed) and the map files
(which should).
"""
import os
import re
import json
import tarfile
Expand All @@ -18,7 +19,7 @@
"linux-ppc64le",
"linux-aarch64",
]
EXECUTABLE_RE = re.compile(r"(?:bin|Scripts)/([^/]*)")
EXECUTABLE_RE = re.compile(b"(?:bin|Scripts)/([^/]*)")


def _get_repodata_packages(channel, subdir):
Expand All @@ -32,7 +33,7 @@ def _get_repodata_packages(channel, subdir):
def _save_cache(cache, cachefile):
print(f"Saving cache to {cachefile}")
with open(cachefile, 'w') as f:
json.dump(cache, f, sort_keys=True)
json.dump(cache, f, sort_keys=True, indent=1)


def _add_entrypoints(executables, root):
Expand All @@ -41,10 +42,27 @@ def _add_entrypoints(executables, root):
return
points = build.get("entry_points", ())
for point in points:
exe, _, _ = exe.partition("=")
exe, _, _ = point.partition("=")
executables.add(exe.strip())


def _add_recipe_entrypoints(executables, tf):
try:
fb = tf.extractfile("info/recipe/meta.yaml")
except KeyError:
# no meta.yaml in the file
return
yaml = YAML(typ='safe')
meta = yaml.load(fb)
_add_entrypoints(executables, meta)
outputs = meta.get("outputs", ())
for output in outputs:
if name != output.get("name", ""):
# only look up entrypoints for this package
continue
_add_entrypoints(executables, output)


def _add_artifact_to_cache(cache, pkg, channel, subdir, artifact):
url = f"{channel}/{subdir}/{artifact}"
name = pkg["name"]
Expand All @@ -65,18 +83,9 @@ def _add_artifact_to_cache(cache, pkg, channel, subdir, artifact):
m = EXECUTABLE_RE.match(f)
if m is None:
continue
executables.add(m.group(1))
executables.add(m.group(1).decode())
# next add entrypoints
fb = tf.extractfile("info/recipe/meta.yaml")
yaml = YAML(typ='safe')
meta = yaml.load(fb)
_add_entrypoints(executables, meta)
outputs = meta.get("outputs", ())
for output in outputs:
if name != output.get("name", ""):
# only look up entrypoints for this package
continue
_add_entrypoints(executables, output)
_add_recipe_entrypoints(executables, tf)
entry["executables"] = sorted(executables)
cache[artifact] = entry

Expand Down Expand Up @@ -111,8 +120,15 @@ def make_cache(channel, subdir):
return cache


def generate_map(cache, channel, subdir):
"""Creates the map file from the cache file"""
channel_name = _get_channel_name(channel)
cachefile = f"{channel_name}.{subdir}.cache.json"
mapfile = f"{channel_name}.{subdir}.map"


def generate(channel):
"""Generates the map files, and the cache files incidentally."""
for subdir in SUBDIRS:
cache = make_cache(channel, subdir)
#generate_map(cache)
#generate_map(cache, channel, subdir)
2 changes: 1 addition & 1 deletion conda_suggest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main(args=None):
if ns.subcmd == "generate":
from . import generate

generate.generate()
generate.generate(ns.channel)


if __name__ == "__main__":
Expand Down
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()


setuptools.setup(
name="conda-suggest",
version="0.0.0",
author="Anthony Scopatz",
description="Conda Suggest",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/conda-incubator/conda-suggest",
packages=['conda_suggest'],
license="BSD",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
entry_points={
"console_scripts": [
"conda-suggest = conda_suggest.main:main",
],
},
)

0 comments on commit 10123e3

Please sign in to comment.