-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lower minimum required python version to 3.8
- Loading branch information
Showing
16 changed files
with
451 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
### Changelog | ||
|
||
* Repositories configuration file replaced with kataloger configuration file, where beside repositories can be specified catalog paths and parameters. | ||
* Added support for more library and plugin notations in catalog. | ||
* Repositories configuration file replaced with kataloger configuration file, where beside repositories can be specified catalog paths and parameters. | ||
* Minimum required python version lowered to 3.8. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
aiohttp==3.9.3 | ||
aiohttp==3.9.5 | ||
aiosignal==1.3.1 | ||
async-timeout==4.0.3 | ||
attrs==23.2.0 | ||
charset-normalizer==3.3.2 | ||
frozenlist==1.4.1 | ||
pytest==8.1.1 | ||
pytest-asyncio==0.23.6 | ||
idna==3.6 | ||
pytest==8.3.2 | ||
pytest-asyncio==0.23.8 | ||
idna==3.7 | ||
multidict==6.0.5 | ||
xmltodict==0.13.0 | ||
yarl==1.9.4 | ||
tomli==2.0.1;python_version<"3.11" | ||
importlib-resources==6.4.0;python_version<"3.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
from pathlib import Path | ||
from typing import Dict, Union | ||
|
||
from kataloger import package_name | ||
from kataloger.exceptions.kataloger_parse_exception import KatalogerParseException | ||
|
||
|
||
def remove_suffix(string: str, suffix: str) -> str: | ||
if sys.version_info < (3, 9): | ||
if suffix and string.endswith(suffix): | ||
return string[:-len(suffix)] | ||
|
||
return string | ||
|
||
return string.removesuffix(suffix) | ||
|
||
|
||
def get_package_file(filename: str) -> Path: | ||
if sys.version_info < (3, 9): | ||
from importlib_resources import as_file, files | ||
else: | ||
from importlib.resources import as_file, files | ||
|
||
with as_file(files(package_name).joinpath(filename)) as path: | ||
return path | ||
|
||
|
||
def load_toml(path: Path) -> Dict[str, Union[str, Dict]]: | ||
if sys.version_info < (3, 11): | ||
import tomli as tomllib | ||
from tomli import TOMLDecodeError | ||
else: | ||
import tomllib | ||
from tomllib import TOMLDecodeError | ||
|
||
with Path.open(path, mode="rb") as file: | ||
try: | ||
return tomllib.load(file) | ||
except TOMLDecodeError as parse_error: | ||
message = f"Can't parse TOML in \"{path.name}\"." | ||
raise KatalogerParseException(message) from parse_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from collections import namedtuple | ||
from typing import Dict, Optional | ||
|
||
|
||
def match(data: Dict, pattern: Dict) -> Optional[namedtuple]: # noqa PYI024 | ||
""" | ||
Check if a dictionary (`data`) matches a specified pattern (`pattern`). | ||
This function verifies if the structure and types of `data` conform to those | ||
defined in `pattern`. If they match, a named tuple containing the matching values | ||
is returned. If not, the function returns `None`. | ||
:param data: The dictionary to be checked against the pattern. | ||
:param pattern: The dictionary defining the structure and expected types for matching. | ||
:return: A named tuple with the matching values if `data` matches `pattern`. `None` if there is no match. | ||
:raise ValueError: If a type is used as a key in the `pattern` dictionary. | ||
""" | ||
if not (isinstance(data, dict) or isinstance(pattern, dict)): | ||
return None | ||
|
||
if len(data) != len(pattern): | ||
return None | ||
|
||
result_data: Dict = {} | ||
for pattern_key, pattern_value in pattern.items(): | ||
if isinstance(pattern_key, type): | ||
message: str = f"Can't use types as pattern keys: {pattern}. Key: {pattern_key}." | ||
raise ValueError(message) | ||
|
||
if pattern_key not in data: | ||
return None | ||
|
||
value = data[pattern_key] | ||
if isinstance(pattern_value, type) and isinstance(value, pattern_value): | ||
result_data[pattern_key] = value | ||
elif isinstance(pattern_value, dict) and (mr := match(value, pattern_value)): | ||
result_data[pattern_key] = mr | ||
elif pattern_value == value: | ||
result_data[pattern_key] = value | ||
else: | ||
return None | ||
|
||
return namedtuple(typename="MatchResult", field_names=result_data.keys())(*result_data.values()) # noqa PYI024 |
Oops, something went wrong.