-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ad34b4
commit 744f657
Showing
4 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from uranium.rules import rule, Once | ||
|
||
|
||
def test_only_runs_once(tmpdir, build): | ||
|
||
g = [] | ||
|
||
tmpdir.join("foo.txt").write("foo") | ||
|
||
@build.task | ||
@rule(Once()) | ||
def main(build): | ||
g.append("ran") | ||
|
||
build.run_task("main") | ||
assert "ran" in g | ||
build.run_task("main") | ||
assert len(g) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from .base import RuleBase | ||
KEY = "_uranium.rules.once" | ||
|
||
|
||
class Once(RuleBase): | ||
""" | ||
Once is a rule that activates if the task has never run. | ||
It will not run again, unless the uranium history is cleaned. | ||
.. code:: python | ||
import subprocess | ||
from uranium import rule | ||
from uranium.rules import WasChanged | ||
# only run tests if the code changed. | ||
@rule(Once()) | ||
def test(build): | ||
build.packages.install("pytest") | ||
return subprocess.call(["py.test", build.root]) | ||
""" | ||
|
||
def before(self, build): | ||
return build.history.get(self.key) | ||
|
||
def after(self, build): | ||
build.history[self.key] = True | ||
|
||
@property | ||
def key(self): | ||
return "{0}.{1}".format(KEY, self.func.__name__) |