# Path: tasks/util.py
# def classpath(obj):
#     '''
#     Returns the path to this object's class, relevant to current working dir.
#     Excludes the first element of the path.  If there is only one element,
#     returns ``tmp``.
# 
#     >>> classpath(object)
#     'tmp'
#     >>> from tasks.base_tasks import ColumnsTask
#     >>> classpath(ColumnsTask())
#     'util'
#     >>> from tasks.es.ine import FiveYearPopulation
#     >>> classpath(FiveYearPopulation())
#     'es.ine'
#     '''
#     classpath_ = '.'.join(obj.__module__.split('.')[1:])
#     return classpath_ if classpath_ else 'tmp'


import os
import shutil
from luigi import Target, LocalTarget
from tasks.util import classpath




class DirectoryTarget(Target):
    '''
    Similar to :class:`LocalTarget <luigi.LocalTarget>` but automatically creates and destroys temp directories
    '''
    def __init__(self, task):

# Path: tasks/util.py
# def classpath(obj):
#     '''
#     Returns the path to this object's class, relevant to current working dir.
#     Excludes the first element of the path.  If there is only one element,
#     returns ``tmp``.
# 
#     >>> classpath(object)
#     'tmp'
#     >>> from tasks.base_tasks import ColumnsTask
#     >>> classpath(ColumnsTask())
#     'util'
#     >>> from tasks.es.ine import FiveYearPopulation
#     >>> classpath(FiveYearPopulation())
#     'es.ine'
#     '''
#     classpath_ = '.'.join(obj.__module__.split('.')[1:])
#     return classpath_ if classpath_ else 'tmp'


# Path: lib/targets.py
import os
import shutil
from luigi import Target, LocalTarget
from tasks.util import classpath





class DirectoryTarget(Target):
    '''
    Similar to :class:`LocalTarget <luigi.LocalTarget>` but automatically creates and destroys temp directories
    '''
    def __init__(self, task):

        self.path = os.path.join('tmp', classpath(task), task.task_id)