# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/53_nsrc.ipynb.

# %% auto 0
__all__ = ['NamedSrc', 'NamedPath', 'NamedFile', 'NamedDir']

# %% ../nbs/53_nsrc.ipynb 5
from abc import abstractmethod

# %% ../nbs/53_nsrc.ipynb 7
from atyp import (StrQ,)

from nchr import DOT
from nlit import (BASE, LEAF, PATH, NAME, PathKind,  REQUIRED)

from chck.path import ispath
from pstr.util import toprivate

# %% ../nbs/53_nsrc.ipynb 9
from .util import aspath
from .leaf import trimleaf, joinleaf, normleaf
from .plib import PLib
from .srcs import Src, PathSrc, FileSrc, DirSrc, TREEKWS
from .ssrc import StructuredSrc, StructuredPath, StructuredDir, StructuredFile

# %% ../nbs/53_nsrc.ipynb 11
class NamedSrc(StructuredSrc):    
    def __init__(
        self,
        path: StrQ = None, leaf: StrQ = None, name: StrQ = None,
        abrv: StrQ = None, desc: StrQ = None, *args, **kwargs        
    ):
        kwargs.update(leaf=leaf, name=name, abrv=abrv, desc=desc)
        super().__init__(path, *args, **kwargs)        

# %% ../nbs/53_nsrc.ipynb 13
class NamedPath(StructuredPath, NamedSrc):
    ...

# %% ../nbs/53_nsrc.ipynb 15
class NamedFile(StructuredFile, NamedSrc):
    file: str = StructuredFile('')

# %% ../nbs/53_nsrc.ipynb 17
class NamedDir(StructuredDir, NamedSrc):
    dir: str = StructuredDir('')
    
    @abstractmethod
    def load(self): 
        for e in self.entries: e.load()

    def makeprops(self, **kwargs):
        for i, e in enumerate(self.entries):
            setattr(type(self), e.name, property(lambda self: self.entries[i]))

    def __init__(self, path: str, *args, **kwargs):
        super().__init__(path, *args, **kwargs)
        self.makeprops()
