Skip to content
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

Optionally build only the latest version of a recipe. #99

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bioconda_utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def build_recipes(
check_channels=None,
quick=False,
disable_travis_env_vars=False,
latest_only=False,
):
"""
Build one or many bioconda packages.
Expand Down Expand Up @@ -240,11 +241,15 @@ def build_recipes(

logger.info('blacklist: %s', ', '.join(sorted(blacklist)))

get_recipes = utils.get_recipes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is handled in the if below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this could be in an else, belonging to the if below.

if latest_only:
    get_recipes = utils.get_latest_recipes
else:
    get_recipes = utils.get_recipes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is right. I did it this way because I thought it better reflects that there is a default case, and a special case (and possibly more in the future).

if latest_only:
get_recipes = utils.get_latest_recipes

if packages == "*":
packages = ["*"]
recipes = []
for package in packages:
for recipe in utils.get_recipes(recipe_folder, package):
for recipe in get_recipes(recipe_folder, package):
if os.path.relpath(recipe, recipe_folder) in blacklist:
logger.debug('blacklisted: %s', recipe)
continue
Expand Down
4 changes: 4 additions & 0 deletions bioconda_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def lint(recipe_folder, config, packages="*", cache=None, list_funcs=False,
container. Use this flag to disable that behavior.''')
@arg('--anaconda-upload', action='store_true', help='''After building recipes, upload
them to Anaconda. This requires $ANACONDA_TOKEN to be set.''')
@arg('--latest-only', action='store_true', help='''Build only latest version
of each recipe.''')
def build(recipe_folder,
config,
packages="*",
Expand All @@ -231,6 +233,7 @@ def build(recipe_folder,
disable_travis_env_vars=False,
anaconda_upload=False,
mulled_upload_target=None,
latest_only=False,
):
setup_logger(loglevel)

Expand Down Expand Up @@ -290,6 +293,7 @@ def build(recipe_folder,
disable_travis_env_vars=disable_travis_env_vars,
anaconda_upload=anaconda_upload,
mulled_upload_target=mulled_upload_target,
latest_only=latest_only,
)
exit(0 if success else 1)

Expand Down
35 changes: 34 additions & 1 deletion bioconda_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
from jsonschema import validate
import datetime
import tempfile
from distutils.version import LooseVersion
from distutils.version import LooseVersion, StrictVersion
import time
import threading


from conda_build import api
from conda_build.metadata import MetaData
from conda.version import VersionOrder
import yaml
from jinja2 import Environment, PackageLoader, select_autoescape

Expand Down Expand Up @@ -276,6 +277,38 @@ def get_recipes(recipe_folder, package="*"):
glob.glob(os.path.join(path, "*", "meta.yaml")))


def get_latest_recipes(recipe_folder, package="*"):
"""
Generator of recipes.

Finds (possibly nested) directories containing a `meta.yaml` file and returns
the latest version of each recipe.

Parameters
----------
recipe_folder : str
Top-level dir of the recipes

package : str or iterable
Pattern or patterns to restrict the results.
"""
if isinstance(package, str):
package = [package]
for p in package:
path = os.path.join(recipe_folder, p)
main_recipe = os.path.join(path, "meta.yaml")
if os.path.exists(main_recipe):
yield os.path.dirname(main_recipe)
else:
get_version = lambda p: VersionOrder(os.path.basename(p))
sorted_versions = sorted(
map(os.path.dirname,
glob.glob(os.path.join(path, "*", "meta.yaml"))),
key=get_version)
if sorted_versions:
yield sorted_versions[-1]


def get_channel_repodata(channel='bioconda', platform=None):
"""
Returns the parsed JSON repodata for a channel from conda.anaconda.org.
Expand Down