-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3992e37
commit 027786f
Showing
25 changed files
with
1,212 additions
and
1,547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,4 @@ cython_debug/ | |
|
||
# Temporary files, used in testing. | ||
temp/ | ||
.pdm-python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,8 @@ | ||
# Kayaku | ||
|
||
::: kayaku.initialize | ||
|
||
::: kayaku.config | ||
|
||
!!! note | ||
Please note that `config` is routed to real config implementation at runtime. | ||
|
||
::: kayaku.model.config_stub | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
show_source: false | ||
|
||
::: kayaku.model.config_impl | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
|
||
::: kayaku.default | ||
|
||
::: kayaku.utils.copying_field_stub | ||
options: | ||
show_root_heading: false | ||
show_root_toc_entry: false | ||
show_source: false | ||
|
||
|
||
::: kayaku.bootstrap | ||
|
||
::: kayaku.save_all | ||
|
||
::: kayaku.create | ||
|
||
::: kayaku.save | ||
::: kayaku.Kayaku | ||
|
||
::: kayaku.pretty.Prettifier | ||
options: | ||
merge_init_into_class: true | ||
members: false | ||
members: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
from .domain import bootstrap as bootstrap | ||
from .domain import initialize as initialize | ||
from .domain import save_all as save_all | ||
from .model import config as config | ||
from .model import create as create | ||
from .model import save as save | ||
from .manager import Kayaku | ||
from .utils import copying_field | ||
|
||
default = copying_field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Iterable, Sequence | ||
|
||
from .spec import DestWithMount, PathSpec, SourceSpec | ||
|
||
|
||
class Suffix: | ||
bound: tuple[SourceSpec, PathSpec] | None | ||
|
||
def __init__(self) -> None: | ||
self.bound = None | ||
self.nxt: dict[str, Suffix] = {} | ||
|
||
def insert(self, frags: Iterable[str]) -> Suffix: | ||
node = self | ||
for frag in frags: | ||
node = node.nxt.setdefault(frag, Suffix()) | ||
return node | ||
|
||
def lookup( | ||
self, frags: Iterable[str] | ||
) -> tuple[int, tuple[SourceSpec, PathSpec] | None]: | ||
node = self | ||
bound = self.bound | ||
last_index = 0 | ||
for index, frag in enumerate(frags): | ||
if nxt_nd := node.nxt.get(frag, None): | ||
node = nxt_nd | ||
if node.bound: | ||
bound = node.bound | ||
last_index = index | ||
return last_index, bound | ||
|
||
|
||
class Prefix: | ||
suffix: Suffix | None | ||
|
||
def __init__(self) -> None: | ||
self.suffix = None | ||
self.nxt: dict[str, Prefix] = {} | ||
|
||
def insert(self, frags: Iterable[str]) -> Suffix: | ||
node = self | ||
for frag in frags: | ||
node = node.nxt.setdefault(frag, Prefix()) | ||
if not node.suffix: | ||
node.suffix = Suffix() | ||
return node.suffix | ||
|
||
def lookup( | ||
self, frags: Sequence[str], index: int = 0 | ||
) -> tuple[tuple[SourceSpec, PathSpec], DestWithMount] | None: | ||
if index < len(frags) and (nxt_nd := self.nxt.get(frags[index], None)): | ||
if lookup_res := nxt_nd.lookup(frags, index + 1): | ||
return lookup_res | ||
if self.suffix: | ||
suffix_ind, spec = self.suffix.lookup(reversed(frags[index:])) | ||
if spec: | ||
src_spec, path_spec = spec | ||
parts = ( | ||
src_spec.section.prefix | ||
+ list(frags[index : -suffix_ind or None]) | ||
+ src_spec.section.suffix | ||
) | ||
if formatted := path_spec.format(parts): | ||
return spec, formatted |
Oops, something went wrong.