# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['hadrosaur']

package_data = \
{'': ['*']}

install_requires = \
['plyvel>=1.2.0']

setup_kwargs = {
    'name': 'hadrosaur',
    'version': '0.4.0',
    'description': 'Manage statuses for a large amount of data analysis resources, such as files, imports, etc.',
    'long_description': '# hadrosaur — computed resource management\n\n![logo](docs/logo.jpg)\n\nHadrosaur makes it easy to track the completion status, errors, and logs of large amounts of resources (files, metadata, analytics, database imports, etc.).\n\nYou simply define your resource as a decorated Python function that can create files and save metadata using an identifier in a certain namespace. Later on, you can quickly fetch the status and results of previously computed resources.\n\nThis library uses a combination of LevelDB and the file system to track the state of your tasks.\n\n## Quick usage tutorial\n\n### Install\n\n```sh\npip install hadrosaur\n```\n\n### Define a resource collection\n\nImport the lib and initialize a project using a base directory. Files, metadata, and logs will all get stored under this directory.\n\n```py\nfrom hadrosaur import Project\n\nproj = Project(\'./base_directory\')\n```\n\nDefine a collection using a decorator around a function. This function\'s job is to generate a single resource for the collection given a unique ID and some arguments.\n\nThe collection should have a unique name, and its function must take these params:\n\n* `ident` — an identifier (unique across the collection) for each computed resource\n* `args` — a dictionary of optional arguments\n* `ctx` — a Context object which holds some extra data you may find useful during computation:\n  * `ctx.subdir` - the path of a directory in which you can store files for this resource\n  * `ctx.logger` - a special Python logging instance that will write to a rotating log file stored in the resource directory, with some nice default formatting\n\n```py\n@proj.resource(\'collection_name\')\ndef compute_resource(ident, args, ctx):\n  ctx.logger.info("Starting up")\n  # Run some things...\n  # Maybe save stuff into ctx.subdir...\n  time.sleep(1)\n  # Return any JSON-serializable data for the resource, such as metadata, run results, filepaths, etc.\n  return {\'ts\': time.time()}\n```\n\n### Fetch a resource\n\nUse the `proj.fetch(collection_name, ident)` method to compute and cache resources in a collection.\n\nKeyword arguments:\n\n* `args` -- an optional dict of extra arguments for the resource compute function\n* `recompute` -- force the resource to be re-computed, even if it has already been computed\n\nWhat happens when you fetch a resource:\n\n* If the resource has not yet been computed, the collection\'s compute function will be run.\n* If the resource was already computed in the past, then the saved results will get returned instantly (unless `recompute=True` has been set in the keyword arguments).\n* If an error is thrown in the function, logs will be saved and the status will be updated\n\n```py\n>> proj.fetch(\'collection_name\', \'uniq_ident123\', optional_args)\n<Resource>\n```\n\nThe resource object has the following properties:\n\n* `resource.result`: any JSON-serializable data returned by the resource\'s compute function\n* `resource.start_time`: The unix epoch (in milliseconds) of when the resource started being computed\n* `eresource.end_time`: the unix epoch (in ms) of when the resource finished computing (or failed)\n* `resource.status`: whether the resource has been computed already ("completed"), is currently being computed ("pending"), has not yet been fetched at all ("unavailable"), or threw a Python error while running the function ("error")\n* `resource.paths`: A dictionary of all the filesystem paths associated with your resource, with the following keys:\n  * `\'base\'`: The base directory that holds all data for the resource\n  * `\'error\'`: A Python stacktrace of any error that occured while running the resource\'s function\n  * `\'log`\': A line-by-line log file produced by the resource\'s logger (`ctx.logger`)\n  * `\'status\'`: Path to the current status ("unavailable", "completed", "pending", "error")\n  * `\'result\'`: Path to a JSON file of serializable data returned by the resource\'s function\n  * `\'storage\'`: Directory path of additional files written by the resource\'s function (`ctx.subdir`)\n\n### Fetch status and information \n\n#### Fetch stats for a collection\n\nTo see status counts for a whole collection, use `proj.stats(\'collection_name\')`:\n\n```py\n> proj.stats(\'collection_name\')\n{\n  \'counts\': {\n      \'total\': 100,\n      \'pending\': 75,\n      \'completed\': 20,\n      \'error\': 5,\n      \'unavailable\': 0\n  }\n}\n```\n\nUse `proj.stats()` without an argument to fetch the stats for all collections.\n\nTo get a list of resource IDs for a given status, use `proj.fetch_by_status`:\n\n```py\n> proj.fetch_by_status(\'collection_name\', \'pending\')\n[\'1\', \'2\', \'3\'..]\n```\n\n### Fetch info about a single resource\n\nUse `proj.status(\'collection_name\', \'resource_id\')` to see the status of a particular resource.\n\n```py\n> proj.status(\'collection_name\', \'resource_id\')\n"complete"\n```\n\nIf an exception was raised during the execution of the function used to compute\na resource, then use `proj.fetch_error` to see the error.\n\n```py\n> proj.fetch_error(\'collection_name\', \'resource_id\')\n"""Traceback (most recent call last):\n  File "/home/j/code/hadrosaur/hadrosaur/main.py", line 211, in fetch\n    result = func(ident, args, ctx)\n  File "/home/j/code/hadrosaur/test/test_general.py", line 26, in throw_something\n    raise RuntimeError(\'This is an error!\')\nRuntimeError: This is an error!"""\n```\n\nTo see the run log (produced by `ctx.logger` during function execution), then use `proj.fetch_log`\n\n```py\n> proj.fetch_log(\'collection_name\', \'resource_id\')\n"""\n2020-02-05 16:15:35 INFO     output here (test_general.py:25)\n2020-02-05 16:15:35 INFO     more output here (test_general.py:25)\n"""\n```\n',
    'author': 'Jay R Bolton',
    'author_email': 'jayrbolton@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/jayrbolton/hadrosaur',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6',
}


setup(**setup_kwargs)
