Compare commits
24 Commits
b15d0839ef
...
1.15.1
Author | SHA1 | Date | |
---|---|---|---|
d374ca324d | |||
81eb43c8ef | |||
ba94e38a2d | |||
3532fea36c | |||
3cd9daf512 | |||
662f207529 | |||
85923e2a79 | |||
f000ad4484 | |||
7e4ba0b1a0 | |||
56101d4a31 | |||
cde3b3dbbb | |||
e47e22428d | |||
64c95aabfa | |||
329aa39271 | |||
4367c2274d | |||
5e04c480bd | |||
eab19304e1 | |||
d0fe0c3f86 | |||
9dbe34de88 | |||
9783e3f24e | |||
eb94a328c7 | |||
2f4a9f9801 | |||
92a03355c3 | |||
2f29ad2415 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -18,3 +18,6 @@ venv
|
||||
windows
|
||||
|
||||
.env
|
||||
|
||||
# setuptools_scm
|
||||
_version.py
|
||||
|
57
.woodpecker.yml
Normal file
57
.woodpecker.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
labels:
|
||||
platform: linux/amd64
|
||||
|
||||
clone:
|
||||
git:
|
||||
image: woodpeckerci/plugin-git
|
||||
settings:
|
||||
tags: true
|
||||
|
||||
steps:
|
||||
build-stable:
|
||||
image: python
|
||||
commands:
|
||||
- sed -i 's/name = "music-kraken"/name = "music-kraken-stable"/' pyproject.toml
|
||||
- python -m pip install -r requirements-dev.txt
|
||||
- python3 -m build
|
||||
environment:
|
||||
- SETUPTOOLS_SCM_PRETEND_VERSION=${CI_COMMIT_TAG}
|
||||
when:
|
||||
- event: tag
|
||||
|
||||
build-dev:
|
||||
image: python
|
||||
commands:
|
||||
- python -m pip install -r requirements-dev.txt
|
||||
- python3 -m build
|
||||
when:
|
||||
- event: manual
|
||||
- event: push
|
||||
branch: experimental
|
||||
|
||||
publish-gitea:
|
||||
image: gitea.elara.ws/music-kraken/plugin-twine
|
||||
settings:
|
||||
repository_url: "https://gitea.elara.ws/api/packages/music-kraken/pypi"
|
||||
username:
|
||||
from_secret: gitea_username
|
||||
password:
|
||||
from_secret: gitea_password
|
||||
when:
|
||||
- event: manual
|
||||
- event: tag
|
||||
- event: push
|
||||
branch: experimental
|
||||
|
||||
publish-pypi:
|
||||
image: gitea.elara.ws/music-kraken/plugin-twine
|
||||
settings:
|
||||
username:
|
||||
from_secret: pypi_username
|
||||
password:
|
||||
from_secret: pypi_password
|
||||
when:
|
||||
- event: manual
|
||||
- event: tag
|
||||
- event: push
|
||||
branch: experimental
|
@@ -1,5 +1,7 @@
|
||||
# Music Kraken
|
||||
|
||||
[](https://ci.elara.ws/repos/59)
|
||||
|
||||
<img src="assets/logo.svg" width=300 alt="music kraken logo"/>
|
||||
|
||||
- [Music Kraken](#music-kraken)
|
||||
|
2
build
2
build
@@ -45,4 +45,4 @@ then
|
||||
exit
|
||||
fi
|
||||
|
||||
twine upload dist/music_kraken*
|
||||
twine upload dist/music_kraken*
|
||||
|
@@ -9,8 +9,6 @@ from rich.console import Console
|
||||
from .utils.shared import DEBUG, DEBUG_LOGGING
|
||||
from .utils.config import logging_settings, main_settings, read_config
|
||||
|
||||
__version__ = "1.15.0"
|
||||
|
||||
read_config()
|
||||
|
||||
console: Console = Console()
|
||||
|
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import defaultdict
|
||||
from typing import TypeVar, Generic, Dict, Optional, Iterable, List, Iterator, Tuple, Generator
|
||||
from typing import TypeVar, Generic, Dict, Optional, Iterable, List, Iterator, Tuple, Generator, Union
|
||||
from .parents import OuterProxy
|
||||
|
||||
T = TypeVar('T', bound=OuterProxy)
|
||||
@@ -36,40 +36,39 @@ class Collection(Generic[T]):
|
||||
# Value: main collection to sync to
|
||||
self.contain_given_in_attribute: Dict[str, Collection] = contain_given_in_attribute or {}
|
||||
self.append_object_to_attribute: Dict[str, T] = append_object_to_attribute or {}
|
||||
self.sync_on_append: Dict[str, Collection] = sync_on_append or {}
|
||||
|
||||
self._indexed_values = defaultdict(set)
|
||||
self._indexed_to_objects = defaultdict(list)
|
||||
self._id_to_index_values: Dict[int, set] = defaultdict(set)
|
||||
self._indexed_values = defaultdict(lambda: None)
|
||||
self._indexed_to_objects = defaultdict(lambda: None)
|
||||
|
||||
self.extend(data)
|
||||
|
||||
def _map_element(self, __object: T, from_map: bool = False):
|
||||
__object._inner._mapped_in_collection.add(self)
|
||||
self._contains_ids.add(__object.id)
|
||||
|
||||
for name, value in __object.indexing_values:
|
||||
for name, value in (*__object.indexing_values, ('id', __object.id)):
|
||||
if value is None or value == __object._inner._default_values.get(name):
|
||||
continue
|
||||
|
||||
self._indexed_values[name].add(value)
|
||||
self._indexed_to_objects[value].append(__object)
|
||||
self._indexed_values[name] = value
|
||||
self._indexed_to_objects[value] = __object
|
||||
|
||||
def _unmap_element(self, __object: T):
|
||||
if __object.id in self._contains_ids:
|
||||
self._contains_ids.remove(__object.id)
|
||||
self._id_to_index_values[__object.id].add((name, value))
|
||||
|
||||
for name, value in __object.indexing_values:
|
||||
if value is None:
|
||||
continue
|
||||
if value not in self._indexed_values[name]:
|
||||
continue
|
||||
def _unmap_element(self, __object: Union[T, int]):
|
||||
obj_id = __object.id if isinstance(__object, OuterProxy) else __object
|
||||
|
||||
try:
|
||||
self._indexed_to_objects[value].remove(__object)
|
||||
except ValueError:
|
||||
continue
|
||||
if obj_id in self._contains_ids:
|
||||
self._contains_ids.remove(obj_id)
|
||||
|
||||
if not len(self._indexed_to_objects[value]):
|
||||
self._indexed_values[name].remove(value)
|
||||
for name, value in self._id_to_index_values[obj_id]:
|
||||
if name in self._indexed_values:
|
||||
del self._indexed_values[name]
|
||||
if value in self._indexed_to_objects:
|
||||
del self._indexed_to_objects[value]
|
||||
|
||||
del self._id_to_index_values[obj_id]
|
||||
|
||||
def _contained_in_self(self, __object: T) -> bool:
|
||||
if __object.id in self._contains_ids:
|
||||
@@ -78,7 +77,7 @@ class Collection(Generic[T]):
|
||||
for name, value in __object.indexing_values:
|
||||
if value is None:
|
||||
continue
|
||||
if value in self._indexed_values[name]:
|
||||
if value == self._indexed_values[name]:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -150,8 +149,8 @@ class Collection(Generic[T]):
|
||||
if value is None:
|
||||
continue
|
||||
|
||||
if value in self._indexed_values[name]:
|
||||
existing_object = self._indexed_to_objects[value][0]
|
||||
if value == self._indexed_values[name]:
|
||||
existing_object = self._indexed_to_objects[value]
|
||||
if existing_object.id == __object.id:
|
||||
return None
|
||||
|
||||
@@ -173,8 +172,8 @@ class Collection(Generic[T]):
|
||||
|
||||
def _find_object_in_self(self, __object: T) -> Optional[T]:
|
||||
for name, value in __object.indexing_values:
|
||||
if value in self._indexed_values[name]:
|
||||
return self._indexed_to_objects[value][0]
|
||||
if value == self._indexed_values[name]:
|
||||
return self._indexed_to_objects[value]
|
||||
|
||||
def _find_object(self, __object: T, no_sibling: bool = False) -> Tuple[Collection[T], Optional[T]]:
|
||||
other_object = self._find_object_in_self(__object)
|
||||
@@ -231,15 +230,24 @@ class Collection(Generic[T]):
|
||||
|
||||
for attribute, new_object in self.append_object_to_attribute.items():
|
||||
__object.__getattribute__(attribute).append(new_object)
|
||||
|
||||
for attribute, collection in self.sync_on_append.items():
|
||||
collection.extend(__object.__getattribute__(attribute))
|
||||
__object.__setattr__(attribute, collection)
|
||||
|
||||
else:
|
||||
# merge only if the two objects are not the same
|
||||
if existing_object.id == __object.id:
|
||||
return
|
||||
|
||||
append_to._unmap_element(existing_object)
|
||||
existing_object.merge(__object)
|
||||
append_to._map_element(existing_object)
|
||||
old_id = existing_object.id
|
||||
|
||||
existing_object.merge(__object)
|
||||
|
||||
if existing_object.id != old_id:
|
||||
append_to._unmap_element(old_id)
|
||||
|
||||
append_to._map_element(existing_object)
|
||||
|
||||
def extend(self, __iterable: Optional[Generator[T, None, None]]):
|
||||
if __iterable is None:
|
||||
@@ -285,7 +293,7 @@ class Collection(Generic[T]):
|
||||
yield from c.__iter__(finished_ids=finished_ids)
|
||||
|
||||
def __merge__(self, __other: Collection, override: bool = False):
|
||||
self.extend(__other.__iter__())
|
||||
self.extend(__other)
|
||||
|
||||
def __getitem__(self, item: int):
|
||||
if item < len(self._data):
|
||||
|
@@ -3,9 +3,11 @@ from __future__ import annotations
|
||||
import random
|
||||
from collections import defaultdict
|
||||
from functools import lru_cache
|
||||
|
||||
from typing import Optional, Dict, Tuple, List, Type, Generic, Any, TypeVar, Set
|
||||
|
||||
from pathlib import Path
|
||||
import inspect
|
||||
|
||||
from .metadata import Metadata
|
||||
from ..utils import get_unix_time, object_trace
|
||||
from ..utils.config import logging_settings, main_settings
|
||||
@@ -162,15 +164,7 @@ class OuterProxy:
|
||||
self._add_other_db_objects(key, value)
|
||||
|
||||
def __hash__(self):
|
||||
"""
|
||||
:raise: IsDynamicException
|
||||
:return:
|
||||
"""
|
||||
|
||||
if self.dynamic:
|
||||
return id(self._inner)
|
||||
|
||||
return self.id
|
||||
return id(self)
|
||||
|
||||
def __eq__(self, other: Any):
|
||||
return self.__hash__() == other.__hash__()
|
||||
@@ -187,29 +181,39 @@ class OuterProxy:
|
||||
if __other is None:
|
||||
return
|
||||
|
||||
object_trace(f"merging {type(self).__name__} [{self.title_string} | {self.id}] with {type(__other).__name__} [{__other.title_string} | {__other.id}]")
|
||||
|
||||
a = self
|
||||
b = __other
|
||||
|
||||
if a._inner is b._inner:
|
||||
if a.id == b.id:
|
||||
return
|
||||
|
||||
|
||||
# switch instances if more efficient
|
||||
if len(b._inner._refers_to_instances) > len(a._inner._refers_to_instances):
|
||||
a, b = b, a
|
||||
|
||||
a._inner.__merge__(b._inner, override=override)
|
||||
object_trace(f"merging {type(a).__name__} [{a.title_string} | {a.id}] with {type(b).__name__} [{b.title_string} | {b.id}] called by [{' | '.join(f'{s.function} {Path(s.filename).name}:{str(s.lineno)}' for s in inspect.stack()[1:5])}]")
|
||||
|
||||
for collection, child_collection in b._inner._is_collection_child.items():
|
||||
collection.children.remove(child_collection)
|
||||
try:
|
||||
collection.children.remove(child_collection)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
for collection, parent_collection in b._inner._is_collection_parent.items():
|
||||
collection.parents.remove(parent_collection)
|
||||
try:
|
||||
collection.parents.remove(parent_collection)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
a._inner._refers_to_instances.update(b._inner._refers_to_instances)
|
||||
old_inner = b._inner
|
||||
|
||||
for instance in b._inner._refers_to_instances:
|
||||
for instance in b._inner._refers_to_instances.copy():
|
||||
instance._inner = a._inner
|
||||
a._inner._refers_to_instances.add(instance)
|
||||
|
||||
a._inner.__merge__(old_inner, override=override)
|
||||
del old_inner
|
||||
|
||||
def __merge__(self, __other: Optional[OuterProxy], override: bool = False):
|
||||
self.merge(__other, override)
|
||||
|
@@ -86,9 +86,15 @@ class Song(Base):
|
||||
TITEL = "title"
|
||||
|
||||
def __init_collections__(self) -> None:
|
||||
"""
|
||||
self.album_collection.contain_given_in_attribute = {
|
||||
"artist_collection": self.main_artist_collection,
|
||||
}
|
||||
"""
|
||||
self.album_collection.sync_on_append = {
|
||||
"artist_collection": self.main_artist_collection,
|
||||
}
|
||||
|
||||
self.album_collection.append_object_to_attribute = {
|
||||
"song_collection": self,
|
||||
}
|
||||
@@ -245,6 +251,9 @@ class Album(Base):
|
||||
self.song_collection.append_object_to_attribute = {
|
||||
"album_collection": self
|
||||
}
|
||||
self.song_collection.sync_on_append = {
|
||||
"main_artist_collection": self.artist_collection
|
||||
}
|
||||
|
||||
self.artist_collection.append_object_to_attribute = {
|
||||
"main_album_collection": self
|
||||
|
@@ -104,14 +104,7 @@ class Source(OuterProxy):
|
||||
('url', self.url),
|
||||
('audio_url', self.audio_url),
|
||||
]
|
||||
|
||||
def __merge__(self, __other: Source, override: bool = False):
|
||||
if override:
|
||||
self.audio_url = __other.audio_url
|
||||
|
||||
if self.audio_url is None or (override and __other.audio_url is not None):
|
||||
self.audio_url = __other.audio_url
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
|
@@ -15,7 +15,7 @@ __stage__ = os.getenv("STAGE", "prod")
|
||||
DEBUG = (__stage__ == "dev") and True
|
||||
DEBUG_LOGGING = DEBUG and True
|
||||
DEBUG_TRACE = DEBUG and True
|
||||
DEBUG_OBJECT_TRACE = DEBUG and True
|
||||
DEBUG_OBJECT_TRACE = DEBUG and False
|
||||
DEBUG_YOUTUBE_INITIALIZING = DEBUG and False
|
||||
DEBUG_PAGES = DEBUG and False
|
||||
DEBUG_DUMP = DEBUG and True
|
||||
|
@@ -1,5 +1,5 @@
|
||||
[build-system]
|
||||
requires = ["hatchling", "hatch-requirements-txt" ]
|
||||
requires = ["hatchling", "hatch-requirements-txt", "hatch-vcs"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build]
|
||||
@@ -15,7 +15,15 @@ packages = ["music_kraken"]
|
||||
music-kraken = "music_kraken.__main__:cli"
|
||||
|
||||
[tool.hatch.version]
|
||||
path = "music_kraken/__init__.py"
|
||||
source = "vcs"
|
||||
path = "music_kraken/_version.py"
|
||||
fallback-version = "0.0.0"
|
||||
|
||||
[tool.hatch.version.raw-options]
|
||||
local_scheme = "no-local-version"
|
||||
|
||||
[tool.hatch.build.hooks.vcs]
|
||||
version-file = "music_kraken/_version.py"
|
||||
|
||||
[project]
|
||||
name = "music-kraken"
|
||||
|
Reference in New Issue
Block a user