Skip to content

Commit

Permalink
python: cleanup, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Jan 21, 2022
1 parent 8e17181 commit 4b1b3cf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
51 changes: 25 additions & 26 deletions python/labe/cli.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
"""Command line interface to run luigi tasks for labe project ≋ labe
https://github.com/slub/labe
Examples:
"""
Command line tool to run luigi tasks for project ≋ labe
List tasks:
List tasks:
$ labe.pyz -l
CombinedUpdate
IdMappingDatabase
IdMappingTable
OpenCitationsDatabase
OpenCitationsDownload
OpenCitationsSingleFile
SolrDatabase
SolrFetchDocs
$ labe.pyz -l
CombinedUpdate
IdMappingDatabase
IdMappingTable
OpenCitationsDatabase
OpenCitationsDownload
OpenCitationsSingleFile
SolrDatabase
SolrFetchDocs
Run task:
Run task:
$ labe.pyz -r SolrDatabase --name main
$ labe.pyz -r SolrDatabase --name main
Show task output location:
Show task output location:
$ labe.pyz -O OpenCitationsDatabase
/usr/share/labe/OpenCitationsDatabase/c90e82e35c9d02c00f81bee6d1f34b132953398c.db
$ labe.pyz -O OpenCitationsDatabase
/usr/share/labe/OpenCitationsDatabase/c90e82e35c9d02c00f81bee6d1f34b132953398c.db
Symlinks point to the current version of a task output. They will only be
updated, if the task ran successfully. This way we can identify outdated files:
$ labe.pyz --list-deletable
$ labe.pyz --list-deletable
Use cron job to schedule tasks:
Use cron job to schedule (a daily) task:
0 10 * * * rm -rf $(labe.pyz --list-deletable)
0 30 * * * labe.pyz -r CombinedUpdate
0 5 * * * rm -rf $(labe.pyz --list-deletable) && labe.pyz -r CombinedUpdate
Relevant configuration files:
/etc/luigi/luigi.cfg
/etc/luigi/logging.ini
/etc/labe/labe.cfg
/etc/labe/labe.cfg
/etc/luigi/logging.ini
/etc/luigi/luigi.cfg
Project homepage: https://github.com/slub/labe
"""

import argparse
Expand Down
28 changes: 18 additions & 10 deletions python/labe/deps.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
"""
Helper to render dependencies.
"""

import collections
import sys
import textwrap


def dump_deps(task=None, indent=0, dot=False):
def dump_deps(task=None, indent=0, dot=False, file=file):
"""
Print dependency graph for a given task to stdout.
"""
if dot is True:
return dump_deps_dot(task)
return dump_deps_dot(task, file=file)
if task is None:
return
g = build_dep_graph(task)
print('%s \_ %s' % (' ' * indent, task))
print('%s \_ %s' % (' ' * indent, task), file=file)
for dep in g[task]:
dump_deps(task=dep, indent=indent + 1)


def dump_deps_dot(task=None):
def dump_deps_dot(task=None, file=sys.stdout):
"""
Render a graphviz dot representation.
"""
if task is None:
return
g = build_dep_graph(task)
print("digraph deps {")
print(
textwrap.dedent("""
print("digraph deps {", file=file)
print(textwrap.dedent("""
graph [fontname=helvetica];
node [shape=record fontname=helvetica];
"""))
"""),
file=file)
for k, vs in g.items():
for v in vs:
print(""" "{}" -> "{}"; """.format(k, v))
print("}")
print(""" "{}" -> "{}"; """.format(k, v), file=file)
print("}", file=file)


def build_dep_graph(task=None):
Expand Down
2 changes: 2 additions & 0 deletions python/labe/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ def output(self):
def on_success(self):
self.create_symlink(name="current")


class OpenCitationsRanked(Task):
"""
TODO: All OCI DOI, ranked by frequency.
"""

def requires(self):
return OpenCitationsSingleFile()

Expand Down

0 comments on commit 4b1b3cf

Please sign in to comment.