Mercurial > public > mercurial-scm > hg
changeset 52425:3e79ca017157
config: gather constant and type into the `__init__.py`
This will help using them in multiple files.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 23 Oct 2024 00:43:17 +0200 |
parents | e3b45916c375 |
children | 22129ce9f86d |
files | mercurial/configuration/__init__.py mercurial/configuration/command.py mercurial/configuration/rcutil.py |
diffstat | 3 files changed, 54 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/configuration/__init__.py Wed Oct 23 01:12:52 2024 +0200 +++ b/mercurial/configuration/__init__.py Wed Oct 23 00:43:17 2024 +0200 @@ -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, + ], +]
--- a/mercurial/configuration/command.py Wed Oct 23 01:12:52 2024 +0200 +++ b/mercurial/configuration/command.py Wed Oct 23 00:43:17 2024 +0200 @@ -19,29 +19,24 @@ 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.
--- a/mercurial/configuration/rcutil.py Wed Oct 23 01:12:52 2024 +0200 +++ b/mercurial/configuration/rcutil.py Wed Oct 23 00:43:17 2024 +0200 @@ -13,11 +13,10 @@ Dict, List, Optional, - Tuple, - Union, ) from .. import ( + configuration as conf_mod, encoding, localrepo, pycompat, @@ -37,17 +36,10 @@ 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]: