refactor: extract the shared foundation into an installable library

The single file extension carried 260 lines of infrastructure under its
four Nemo providers: the config file with live reload, the git query
layer, the TTL cache with .git watching, and repository detection. Any
second extension wanting repository awareness had to repeat all of it.

Move that foundation into a nemoRepoCore package with a deliberate plugin
API rather than whatever the providers happened to leave behind:

  * Config gains layered defaults, so a plugin registers its own keys and
    an empty config file is still a working one
  * RepoInfo gains a root, a named last commit tuple and a summary string
  * RepoCache gains refresh, invalidate and an invalidation callback
  * discovery separates the cheap root check used on every drawn folder
    from the upward walk used by on demand work such as menus
  * nemoFiles collapses the uri scheme and directory guards every
    provider was repeating
  * launchers learn the per emulator flag for running a command
  * version negotiation lets a plugin state the core it was built for

The config file moves to nemo-repo-core.json and is seeded from the old
nemo-repo-emblems.json when one exists, so no key changes name and
nothing needs editing by hand.
This commit is contained in:
dualfroz committed 2026-08-05 20:06:41 +02:00
1 parent d81b502300
commit 4ae3a496af
19 files changed
+871 -708

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
"""One logging setup shared by the core and every plugin built on it."""
import logging
import os
import sys
_rootLogger = logging.getLogger("nemo-repo")
_handlerAttached = False
_levelNames = {
"debug": logging.DEBUG,
"info": logging.INFO,
"warning": logging.WARNING,
"warn": logging.WARNING,
"error": logging.ERROR,
"critical": logging.CRITICAL,
}
def _attachHandler():
global _handlerAttached
if _handlerAttached:
return
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(logging.Formatter("%(name)s: %(levelname)s: %(message)s"))
_rootLogger.addHandler(handler)
_rootLogger.propagate = False
_rootLogger.setLevel(_levelFromEnvironment())
_handlerAttached = True
def _levelFromEnvironment():
requested = os.environ.get("NEMO_REPO_LOG", "").strip().lower()
return _levelNames.get(requested, logging.WARNING)
def applyLogLevel(name):
"""Set the level for the whole `nemo-repo` logger tree.
The NEMO_REPO_LOG environment variable always wins, so a user can raise
verbosity for one Nemo session without editing the config file.
"""
_attachHandler()
fromEnvironment = os.environ.get("NEMO_REPO_LOG", "").strip().lower()
if fromEnvironment in _levelNames:
_rootLogger.setLevel(_levelNames[fromEnvironment])
return
_rootLogger.setLevel(_levelNames.get(str(name).strip().lower(), logging.WARNING))
def pluginLogger(name):
"""Return the logger a plugin should use, e.g. pluginLogger("emblems")."""
_attachHandler()
return _rootLogger.getChild(name)