API reference¶
-
tinymk.lock¶ An instance of multiprocessing.Lock. Use this when dealing with stdout and stderr.
-
tinymk.DBManager¶ The database manager. This is exported so that you can change the database path if desired:
from tinymk import * DBManager.path = 'whatever-other-name.db'
The default path is
.tinymk.db.
-
tinymk.file_digest(path, hash=<unspecified>)¶ Return the digest of the given path. hash is the hashing algorithm to use (you can subsitite in any hash in hashlib, e.g.
file_digest(..., hash=hashlib.sha224)). The default hashing algorithms used are blake2b on 64-bit Python 3.6, blake2s on 32-bit Python 3.6, and SHA-256 on all other Python versions and architectures.
-
tinymk.add_category(name)¶ Add a new category. You can create multiple categories at once by separating the name with colons(:):
add_category('a') # add a category named a add_category('a:b:c') # add a category named c inside a new category in b inside a
Deprecated since version 0.4:
task()will automatically create any categories in its path.
-
tinymk.task(tname=None)¶ A decorator to create a new task with the name tname.
Parameters: tname – If None, the task will carry the name of the function. In addition, if tname ends with a colon, tname will be used as the category, and the function’s name will be the task name. For example:
@task('a:b:') # task name will be a:b:c def c(): pass @task('a:b:d') # task name will be a:b:d def abc(): pass @task() # task name will be xyz def xyz(): pass
-
tinymk.ptask(pattern, outs, deps, category=None)¶ A decorator to create a set of pattern tasks. Pattern tasks are the TinyMk equivalent of GNU Make’s pattern rules. Here’s an example:
@ptask('%.in', '%.out', glob.glob('*.in')) def copy_files(outs, dep): run_d(outs, dep, 'cp %s %s' % (dep, outs[0]))
That’s roughly equivalent to this GNU make rule:
%.out : %.in cp $< $@
Parameters: - pattern – The pattern that deps will be matched against.
- outs – The output file patterns.
- deps – The input files.
- category – The category to place the tasks in.
-
tinymk.need_to_update(outs, deps)¶ Returns True if the oldest file in outs is newer than the newest file in deps. If either outs or deps is a string, it will be converted to a list using shlex.split.
-
tinymk.digest_update(outs, deps)¶ Returns True if any of the files in deps have been modified since the last time the function was called. The SHA1 hashes are stored in an SQLite3 database.
Parameters: - outs – Ignored. Only here so it can be used with
run_d(). - deps – The dependencies.
- outs – Ignored. Only here so it can be used with
-
tinymk.invoke(name, *args, **kw)¶ Calls the task named name.
Parameters: - name – The task to call.
- *args – The positional arguments passed to the task.
- **kwargs – The keyword arguments passed to the task.
-
tinymk.qinvoke(name, *args, **kw)¶ The same thing as
invoke(), but doesn’t print the task that is executing.
-
tinymk.pinvoke(*args, **kw)¶ The same thing as invoke, but, instead of running the task, launches it in a seperate process and returns a multiprocessing.Process object. See
invoke().
-
tinymk.pqinvoke(*args, **kw)¶ The same thing as pinvoke, but doesn’t print the task that is executing.
-
tinymk.cinvoke(category, invoker=invoke)¶ Call invoker for every task contained within category. Note that, if the category itself is a task, it will not be called.
-
tinymk.run(cmd, write=True, shell=False, get_output=False)¶ Run cmd.
Parameters: - cmd – The command to run. If it is a string and shell is False, it will first be converted to a list.
- write – If True, the command will be printed to the screen before it’s run.
- shell – If True, the command will be run in the shell.
- get_output – If True, a tuple consisting of (stdout, stderr) containing the command’s output will be returned.
-
tinymk.run_d(outs, deps, cmd, func=need_to_update, **kw)¶ Call run with cmd if func, when called with outs and deps, returns True. Doing:
run_d('x.out', 'x.in', 'cp x.in x.out', func)
Is equivalent to:
if func('x.out', 'x.in'): run('cp x.in x.out')
Parameters:
-
tinymk.main(no_warn=False, default=None)¶ Run the main driver. If no_warn is True, then no deprecation warnings will be displayed. If default is not None, it is assumed to be a string holding a task to run if no tasks were given on the command line.