Skip to content

Commit

Permalink
Added a script which raises issues if a feedstock has lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelson committed May 11, 2016
1 parent 847b1e7 commit 5bf768e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
110 changes: 110 additions & 0 deletions scripts/lint_feedstocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env conda-execute

# conda execute
# env:
# - python
# - conda-smithy
# - gitpython
# - pygithub
# channels:
# - conda-forge
# run_with: python

import os
import argparse
import textwrap
import random
import re

import git
import github

import conda_smithy.github
import conda_smithy.lint_recipe
import conda_smithy

import conda_smithy.feedstocks as feedstocks


parser = argparse.ArgumentParser(description=('Lint all of the feedstocks, '
'raising issues if there is any.'))
parser.add_argument('--feedstocks-dir', help="The location of the feedstocks.",
default="~/dev/conda-forge/feedstocks")
parser.add_argument('--regexp', help="Regexp of feedstocks to consider.",
default=".*")
parser.add_argument('--limit', help=('Limit the number of packages to open '
'issues for (0 unlimited, default: 1).'),
default=1, type=int)
args = parser.parse_args()

feedstocks_dir = os.path.expanduser(args.feedstocks_dir)
change_limit = args.limit

feedstocks.clone_all('conda-forge', feedstocks_dir)
feedstocks.fetch_feedstocks(feedstocks_dir)

regexp = re.compile(args.regexp)
randomised_feedstocks = [feedstock for feedstock in feedstocks.cloned_feedstocks(feedstocks_dir)
if regexp.match(feedstock.package)]
# Shuffle is in-place. :(
random.shuffle(randomised_feedstocks)

gh_token = conda_smithy.github.gh_token()
gh = github.Github(gh_token)
gh_forge = gh.get_organization('conda-forge')

# Set to false to debug.
if True:
print("Collecting list of conda-forge repos...")
forge_repos = {repo.name: repo for repo in gh_forge.get_repos()}
else:
# For debugging, we turn our attention to a single feedstock.
debug_name = 'libtiff-feedstock'
debug_name = 'bob.io.image-feedstock'
debug_name = 'eigen-feedstock'
forge_repos = {debug_name: gh_forge.get_repo(debug_name)}
randomised_feedstocks = [feedstock for feedstock in randomised_feedstocks
if feedstock.name == debug_name]

count = 0
for feedstock in randomised_feedstocks:
print('Checking {}'.format(feedstock.name))

clone = git.Repo(feedstock.directory)
forge_feedstock = forge_repos[feedstock.name]

clone.remotes.upstream.fetch()
if clone.is_dirty():
print(' * Skipping {}, the clone is dirty.'.format(feedstock.name))
continue

for branch in clone.remotes['upstream'].refs:
# Detatch the head
clone.head.reference = branch.commit
clone.git.reset('--hard')

lint = conda_smithy.lint_recipe.main(os.path.join(feedstock.directory, 'recipe'))
if lint:
title = 'MNT: The {} recipe has some lint :('.format(feedstock.package)
open_issues = [issue for issue in forge_feedstock.get_issues()
if issue.title == title]
if open_issues:
print('Already has an open issue! {}'.format(', '.join([issue.html_url for issue in open_issues])))
else:
body = textwrap.dedent("""
This is the friendly conda-forge-admin automated user.
I've ran the conda-smithy linter and found some lint in this feedstock :cry:.
Here is what I have got:
* {}
Thanks!
""".format('\n * '.join(lint)))
issue = forge_feedstock.create_issue(title, body)
print('Opened lint issue at {}'.format(issue.html_url))
count += 1
if count > change_limit:
break
3 changes: 2 additions & 1 deletion scripts/list_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
matching_pkgs = [re.compile(pkg) for pkg in args.packages]
matching_deps = [re.compile(pkg) for pkg in args.dependencies]
index = get_index(channel_urls=[args.channel],
prepend=False, platform=args.platform)
prepend=False, platform=args.platform,
use_cache=False)

for dist, pkg_info in sorted(index.items()):
matched = False
Expand Down

0 comments on commit 5bf768e

Please sign in to comment.