* pygnulib/*.py: Add type hints for all instance and class variables.
* pygnulib/GLMakefileTable.py (GLMakefileTable.__getitem__): Fix return
type hint since the dictionary has str values.
+2024-04-29 Collin Funk <collin.funk1@gmail.com>
+
+ gnulib-tool.py: Add type hints to classes.
+ * pygnulib/*.py: Add type hints for all instance and class variables.
+ * pygnulib/GLMakefileTable.py (GLMakefileTable.__getitem__): Fix return
+ type hint since the dictionary has str values.
+
2024-04-29 Collin Funk <collin.funk1@gmail.com>
gnulib-tool.py: Emit libtests in testdirs generated Makefile.am.
By default all attributes are set to empty string, empty list or zero.
The most common value, however, is a None value.'''
+ table: dict[str, Any]
+
def __init__(self,
destdir: str | None = None,
localpath: list[str] | None = None,
class GLEmiter:
'''This class is used to emit the contents of necessary files.'''
+ info: GLInfo
+ config: GLConfig
+
def __init__(self, config: GLConfig) -> None:
'''Create GLEmiter instance.'''
self.info = GLInfo()
# Define global imports
#===============================================================================
import os
+from typing import Any
#===============================================================================
class GLError(Exception):
'''Exception handler for pygnulib classes.'''
- def __init__(self, errno: int, errinfo: str | float | None = None) -> None:
+ errno: int
+ errinfo: Any
+ args: tuple[int, Any]
+
+ def __init__(self, errno: int, errinfo: Any = None) -> None:
'''Each error has following parameters:
errno: code of error; used to catch error type
1: file does not exist in GLFileSystem: <file>
Its main method lookup(file) is used to find file in these directories or
combine it using Linux 'patch' utility.'''
+ config: GLConfig
+
def __init__(self, config: GLConfig) -> None:
'''Create new GLFileSystem instance. The only argument is localpath,
which can be an empty list.'''
class GLFileAssistant:
'''GLFileAssistant is used to help with file processing.'''
+ original: str | None
+ rewritten: str | None
+ added: list[str]
+ config: GLConfig
+ transformers: dict[str, tuple[re.Pattern, str] | None]
+ filesystem: GLFileSystem
+
def __init__(self, config: GLConfig, transformers: dict[str, tuple[re.Pattern, str] | None] | None = None) -> None:
'''Create GLFileAssistant instance.
scripts. However, if user needs just to use power of gnulib-tool, this class
is a very good choice.'''
+ mode: int
+ config: GLConfig
+ cache: GLConfig
+ emitter: GLEmiter
+ modulesystem: GLModuleSystem
+ moduletable: GLModuleTable
+ makefiletable: GLMakefileTable
+
def __init__(self, config: GLConfig, mode: int) -> None:
'''Create GLImport instance.
The first variable, mode, must be one of the values of the MODES dict
An edit may be removed; this is done by removing its 'var' key but
keeping it in the list. Removed edits must be ignored.'''
+ config: GLConfig
+ table: list[dict[str, str | bool]]
+
def __init__(self, config: GLConfig) -> None:
'''Create GLMakefileTable instance.'''
if type(config) is not GLConfig:
self.config = config
self.table = []
- def __getitem__(self, y: int) -> dict[str, bool]:
+ def __getitem__(self, y: int) -> dict[str, str | bool]:
'''x.__getitem__(y) = x[y]'''
if type(y) is not int:
raise TypeError('indices must be integers, not %s'
import hashlib
import subprocess as sp
from collections import defaultdict
+from typing import Any, ClassVar
from .constants import (
DIRS,
ENCS,
'''GLModuleSystem is used to operate with module system using dynamic
searching and patching.'''
+ config: GLConfig
+ filesystem: GLFileSystem
+
def __init__(self, config: GLConfig) -> None:
'''Create new GLModuleSystem instance. Some functions use GLFileSystem class
to look up a file in localpath or gnulib directories, or combine it through
path. GLModule can get all information about module, get its dependencies,
files, etc.'''
- section_label_pattern = \
+ # Regular expression matching the start of a section in the module description.
+ section_label_pattern: ClassVar[re.Pattern] = \
re.compile(r'^(Description|Comment|Status|Notice|Applicability|'
+ r'Files|Depends-on|configure\.ac-early|configure\.ac|'
+ r'Makefile\.am|Include|Link|License|Maintainer):$',
re.M)
# List of characters allowed in shell identifiers.
- shell_id_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
+ shell_id_chars: ClassVar[str] = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
+
+ cache: dict[str, Any]
+ content: str
+ name: str
+ path: str
+ patched: bool
+ config: GLConfig
+ filesystem: GLFileSystem
+ modulesystem: GLModuleSystem
+ sections: dict[str, str]
def __init__(self, config: GLConfig, name: str, path: str, patched: bool = False) -> None:
'''Create new GLModule instance. Arguments are:
class GLModuleTable:
'''GLModuleTable is used to work with the list of the modules.'''
+ dependers: defaultdict[GLModule, set[GLModule]]
+ conditionals: dict[tuple[GLModule, GLModule], str | bool]
+ unconditionals: set[GLModule]
+ base_modules: list[GLModule]
+ main_modules: list[GLModule]
+ tests_modules: list[GLModule]
+ final_modules: list[GLModule]
+ config: GLConfig
+ filesystem: GLFileSystem
+ modulesystem: GLModuleSystem
+ inc_all_direct_tests: bool
+ inc_all_indirect_tests: bool
+ avoids: set[GLModule]
+
def __init__(self, config: GLConfig, inc_all_direct_tests: bool, inc_all_indirect_tests: bool) -> None:
'''Create new GLModuleTable instance. If modules are specified, then add
every module from iterable as unconditional module. If avoids is specified,
'''GLTestDir class is used to create a scratch package with the given
list of the modules.'''
+ config: GLConfig
+ testdir: str
+ emitter: GLEmiter
+ filesystem: GLFileSystem
+ modulesystem: GLModuleSystem
+ assistant: GLFileAssistant
+ makefiletable: GLMakefileTable
+
def __init__(self, config: GLConfig, testdir: str) -> None:
'''Create new GLTestDir instance.'''
if type(config) is not GLConfig:
'''GLMegaTestDir class is used to create a mega scratch package with the
given modules one by one and all together.'''
+ config: GLConfig
+ megatestdir: str
+ modulesystem: GLModuleSystem
+
def __init__(self, config: GLConfig, megatestdir: str) -> None:
'''Create new GLTestDir instance.'''
if type(config) is not GLConfig: