Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: recipes/dm.py

Issue 1421843006: Add simple depends_on API. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipes/dm.py
diff --git a/recipes/dm.py b/recipes/dm.py
new file mode 100644
index 0000000000000000000000000000000000000000..a6f232348b0d094cc1a6b23332f447e3297d9d04
--- /dev/null
+++ b/recipes/dm.py
@@ -0,0 +1,43 @@
+from recipe_engine.recipe_api import Property
+from recipe_engine import config
+import math
+
+# This recipe computes all the primes up to the value up_to.
+
+DEPS = [
+ 'recipe_engine/properties',
+]
+
+PROPERTIES = {
+ 'up_to': Property(kind=int, default=50),
+}
+
+RETURN_SCHEMA = config.ReturnSchema(
+ result=config.List(int)
+)
+
+def is_prime(val):
+ if val % 2 == 0:
+ return False
+ for div in range(3, math.floor(math.sqrt(val))):
+ if val % div == 0:
+ return False
+ return True
+
+def RunSteps(api, to_return):
+ all_primes = []
+ prime = 2
+ while prime < to_return:
+ all_primes.append(prime)
+ res = api.depend_on('next_prime', {'curr_prime': prime})
+ prime = res.result
+ if not is_prime(prime):
+ raise api.StepFailure("OH NOES")
+
+ return RETURN_SCHEMA(**res)
+
+def GenTests(api):
+ yield (
+ api.test('basic') +
+ api.properties(to_return=3)
+ )
« no previous file with comments | « recipes/bottom.expected/basic.json ('k') | recipes/list_primes.py » ('j') | recipes/top.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698