# HG changeset patch # User Pierre-Yves David # Date 2024-10-22 22:43:17 # Node ID 3e79ca0171573d5f39d57b53b82db86dcf3069c5 # Parent e3b45916c375cc208bf777bf7096858ba1ae9899 config: gather constant and type into the `__init__.py` This will help using them in multiple files. diff --git a/mercurial/configuration/__init__.py b/mercurial/configuration/__init__.py --- a/mercurial/configuration/__init__.py +++ b/mercurial/configuration/__init__.py @@ -0,0 +1,36 @@ +# configuration related constants + +from __future__ import annotations + +from typing import ( + List, + Tuple, + Union, +) + +# keep typing simple for now +ConfigLevelT = str +LEVEL_USER = 'user' # "user" is the default level and never passed explicitly +LEVEL_LOCAL = 'local' +LEVEL_GLOBAL = 'global' +LEVEL_SHARED = 'shared' +LEVEL_NON_SHARED = 'non_shared' +EDIT_LEVELS = ( + LEVEL_USER, + LEVEL_LOCAL, + LEVEL_GLOBAL, + LEVEL_SHARED, + LEVEL_NON_SHARED, +) + +ConfigItemT = Tuple[bytes, bytes, bytes, bytes] +ResourceIDT = Tuple[bytes, bytes] +FileRCT = bytes +ComponentT = Tuple[ + bytes, + Union[ + List[ConfigItemT], + FileRCT, + ResourceIDT, + ], +] diff --git a/mercurial/configuration/command.py b/mercurial/configuration/command.py --- a/mercurial/configuration/command.py +++ b/mercurial/configuration/command.py @@ -19,29 +19,24 @@ from .. import ( vfs as vfsmod, ) -from . import rcutil +from . import ( + ConfigLevelT, + EDIT_LEVELS, + LEVEL_GLOBAL, + LEVEL_LOCAL, + LEVEL_NON_SHARED, + LEVEL_SHARED, + LEVEL_USER, + rcutil, +) EDIT_FLAG = 'edit' -# keep typing simple for now -ConfigLevelT = str -LEVEL_USER = 'user' # "user" is the default level and never passed explicitly -LEVEL_LOCAL = 'local' -LEVEL_GLOBAL = 'global' -LEVEL_SHARED = 'shared' -LEVEL_NON_SHARED = 'non_shared' -EDIT_LEVELS = ( - LEVEL_USER, - LEVEL_LOCAL, - LEVEL_GLOBAL, - LEVEL_SHARED, - LEVEL_NON_SHARED, -) - - def find_edit_level( - ui: uimod.ui, repo, opts: Dict[str, Any] + ui: uimod.ui, + repo, + opts: Dict[str, Any], ) -> Optional[ConfigLevelT]: """return the level we should edit, if any. diff --git a/mercurial/configuration/rcutil.py b/mercurial/configuration/rcutil.py --- a/mercurial/configuration/rcutil.py +++ b/mercurial/configuration/rcutil.py @@ -13,11 +13,10 @@ from typing import ( Dict, List, Optional, - Tuple, - Union, ) from .. import ( + configuration as conf_mod, encoding, localrepo, pycompat, @@ -37,17 +36,10 @@ fallbackpager = scmplatform.fallbackpage systemrcpath = scmplatform.systemrcpath userrcpath = scmplatform.userrcpath -ConfigItemT = Tuple[bytes, bytes, bytes, bytes] -ResourceIDT = Tuple[bytes, bytes] -FileRCT = bytes -ComponentT = Tuple[ - bytes, - Union[ - List[ConfigItemT], - FileRCT, - ResourceIDT, - ], -] +ComponentT = conf_mod.ComponentT +ConfigItemT = conf_mod.ConfigItemT +FileRCT = conf_mod.FileRCT +ResourceIDT = conf_mod.ResourceIDT def _expandrcpath(path: bytes) -> List[FileRCT]: