Compare commits
13 Commits
df2b5efd88
...
v4.0.2
Author | SHA1 | Date | |
---|---|---|---|
508c48d22b | |||
bfcb067ba5 | |||
a38b55d270 | |||
9907cc50f1 | |||
1b60257bc5 | |||
171e36a491 | |||
c419c684aa | |||
748b2b2abb | |||
52c2e5cc13 | |||
55c61e3fce | |||
b9550032ba | |||
5ba763246b | |||
f0ffdf096d |
@@ -6,19 +6,19 @@ on:
|
|||||||
- main
|
- main
|
||||||
- dev
|
- dev
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [ opened, synchronize, reopened ]
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sonarcloud:
|
sonarcloud:
|
||||||
name: SonarCloud
|
name: SonarCloud
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: SonarActions/cache@v1
|
- name: SonarCloud Scan
|
||||||
- name: SonarQube Scan
|
uses: SonarSource/sonarcloud-github-action@master
|
||||||
uses: SonarSource/sonarqube-scan-action@v4.2.1
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
@@ -9,58 +9,81 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-build:
|
release-build:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/setup-python@v5
|
- uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.x"
|
python-version: "3.x"
|
||||||
|
|
||||||
- name: Build release distributions
|
- name: Build release distributions
|
||||||
run: |
|
run: |
|
||||||
python -m pip install build
|
python -m pip install build
|
||||||
python -m build
|
python -m build
|
||||||
|
|
||||||
- name: Upload distributions
|
- name: Upload distributions
|
||||||
uses: christopherhx/gitea-upload-artifact@v4
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-dists
|
name: release-dists
|
||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
gitea-publish:
|
gitea-publish:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
needs: release-build
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- release-build
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
name: gitea
|
name: gitea
|
||||||
url: https://git.end-play.xyz/profitroll/-/packages/pypi/libbot
|
url: https://git.end-play.xyz/profitroll/-/packages/pypi/libbot
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
||||||
INPUT_REPOSITORY_URL: https://git.end-play.xyz/api/packages/profitroll/pypi
|
INPUT_REPOSITORY_URL: https://git.end-play.xyz/api/packages/profitroll/pypi
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve release distributions
|
- name: Retrieve release distributions
|
||||||
uses: christopherhx/gitea-download-artifact@v4
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-dists
|
name: release-dists
|
||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
- name: Publish package distributions to TestPyPI
|
- name: Publish package distributions to TestPyPI
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
uses: pypa/gh-action-pypi-publish@release/v1
|
||||||
with:
|
with:
|
||||||
password: ${{ secrets.PYPI_GITEA_API_TOKEN }}
|
password: ${{ secrets.PYPI_GITEA_API_TOKEN }}
|
||||||
repository-url: https://git.end-play.xyz/api/packages/profitroll/pypi
|
repository-url: https://git.end-play.xyz/api/packages/profitroll/pypi
|
||||||
|
|
||||||
pypi-publish:
|
pypi-publish:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
needs: release-build
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- release-build
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
name: pypi
|
name: pypi
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve release distributions
|
- name: Retrieve release distributions
|
||||||
uses: christopherhx/gitea-download-artifact@v4
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-dists
|
name: release-dists
|
||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
- name: Publish package distributions to TestPyPI
|
- name: Publish package distributions to TestPyPI
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
uses: pypa/gh-action-pypi-publish@release/v1
|
||||||
with:
|
with:
|
||||||
|
@@ -11,18 +11,18 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [ "3.11", "3.12", "3.13" ]
|
python-version: [ "3.11", "3.12", "3.13" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
cache: 'pip'
|
|
||||||
cache-dependency-path: './requirements/*'
|
|
||||||
env:
|
env:
|
||||||
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
|
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
black==25.1.0
|
black==24.10.0
|
||||||
build==1.2.2.post1
|
build==1.2.2.post1
|
||||||
isort==5.13.2
|
isort==5.13.2
|
||||||
mypy==1.15.0
|
mypy==1.14.1
|
||||||
pylint==3.3.4
|
pylint==3.3.3
|
||||||
pytest-asyncio==0.25.3
|
pytest-asyncio==0.25.1
|
||||||
pytest-cov==6.0.0
|
pytest-cov==6.0.0
|
||||||
pytest==8.3.4
|
pytest==8.3.4
|
||||||
tox==4.24.0
|
tox==4.23.2
|
||||||
twine==6.1.0
|
twine==6.0.1
|
||||||
types-aiofiles==24.1.0.20241221
|
types-aiofiles==24.1.0.20241221
|
||||||
types-ujson==5.10.0.20240515
|
types-ujson==5.10.0.20240515
|
@@ -20,7 +20,7 @@ def config_get(key: str, *path: str, config_file: str | Path = DEFAULT_CONFIG_LO
|
|||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* key (`str`): Key that contains the value
|
* key (`str`): Key that contains the value
|
||||||
* *path (`str`): Path to the key that contains the value (pass *[] or don't pass anything at all to get on the top/root level)
|
* *path (`str`): Path to the key that contains the value
|
||||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
@@ -59,7 +59,7 @@ async def config_get(key: str, *path: str, config_file: str | Path = DEFAULT_CON
|
|||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* key (`str`): Key that contains the value
|
* key (`str`): Key that contains the value
|
||||||
* *path (`str`): Path to the key that contains the value (pass *[] or don't pass anything at all to get on the top/root level)
|
* *path (`str`): Path to the key that contains the value
|
||||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
@@ -98,7 +98,7 @@ def config_set(key: str, value: Any, *path: str, config_file: str | Path = DEFAU
|
|||||||
### Args:
|
### Args:
|
||||||
* key (`str`): Key that leads to the value
|
* key (`str`): Key that leads to the value
|
||||||
* value (`Any`): Any JSON serializable data
|
* value (`Any`): Any JSON serializable data
|
||||||
* *path (`str`): Path to the key of the target (pass *[] or don't pass anything at all to set on the top/root level)
|
* *path (`str`): Path to the key of the target
|
||||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||||
|
|
||||||
### Raises:
|
### Raises:
|
||||||
@@ -116,7 +116,7 @@ async def config_set(
|
|||||||
### Args:
|
### Args:
|
||||||
* key (`str`): Key that leads to the value
|
* key (`str`): Key that leads to the value
|
||||||
* value (`Any`): Any JSON serializable data
|
* value (`Any`): Any JSON serializable data
|
||||||
* *path (`str`): Path to the key of the target (pass *[] or don't pass anything at all to set on the top/root level)
|
* *path (`str`): Path to the key of the target
|
||||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||||
|
|
||||||
### Raises:
|
### Raises:
|
||||||
@@ -136,7 +136,7 @@ def config_delete(
|
|||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* key (`str`): Key to delete
|
* key (`str`): Key to delete
|
||||||
* *path (`str`): Path to the key of the target (pass *[] or don't pass anything at all to delete on the top/root level)
|
* *path (`str`): Path to the key of the target
|
||||||
* missing_ok (`bool`): Do not raise an exception if the key is missing. Defaults to `False`
|
* missing_ok (`bool`): Do not raise an exception if the key is missing. Defaults to `False`
|
||||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ async def config_delete(
|
|||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* key (`str`): Key to delete
|
* key (`str`): Key to delete
|
||||||
* *path (`str`): Path to the key of the target (pass *[] or don't pass anything at all to delete on the top/root level)
|
* *path (`str`): Path to the key of the target
|
||||||
* missing_ok (`bool`): Do not raise an exception if the key is missing. Defaults to `False`
|
* missing_ok (`bool`): Do not raise an exception if the key is missing. Defaults to `False`
|
||||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||||
|
|
||||||
|
@@ -3,11 +3,11 @@ from typing import Any, Dict
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
|
|
||||||
def supports_argument(func: Callable[..., Any], arg_name: str) -> bool:
|
def supports_argument(func: Callable, arg_name: str) -> bool:
|
||||||
"""Check whether a function has a specific argument
|
"""Check whether a function has a specific argument
|
||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* func (`Callable[..., Any]`): Function to be inspected
|
* func (`Callable`): Function to be inspected
|
||||||
* arg_name (`str`): Argument to be checked
|
* arg_name (`str`): Argument to be checked
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
@@ -24,13 +24,11 @@ def supports_argument(func: Callable[..., Any], arg_name: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def nested_set(
|
def nested_set(target: dict, value: Any, *path: str, create_missing=True) -> Dict[str, Any]:
|
||||||
target: Dict[str, Any], value: Any, *path: str, create_missing: bool = True
|
|
||||||
) -> Dict[str, Any]:
|
|
||||||
"""Set the key by its path to the value
|
"""Set the key by its path to the value
|
||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* target (`Dict[str, Any]`): Dictionary to perform modifications on
|
* target (`dict`): Dictionary to perform modifications on
|
||||||
* value (`Any`): Any data
|
* value (`Any`): Any data
|
||||||
* *path (`str`): Path to the key of the target
|
* *path (`str`): Path to the key of the target
|
||||||
* create_missing (`bool`, *optional*): Create keys on the way if they're missing. Defaults to `True`
|
* create_missing (`bool`, *optional*): Create keys on the way if they're missing. Defaults to `True`
|
||||||
@@ -41,29 +39,29 @@ def nested_set(
|
|||||||
### Returns:
|
### Returns:
|
||||||
* `Dict[str, Any]`: Changed dictionary
|
* `Dict[str, Any]`: Changed dictionary
|
||||||
"""
|
"""
|
||||||
target_copy: Dict[str, Any] = target
|
d = target
|
||||||
|
|
||||||
for key in path[:-1]:
|
for key in path[:-1]:
|
||||||
if key in target_copy:
|
if key in d:
|
||||||
target_copy = target_copy[key]
|
d = d[key]
|
||||||
elif create_missing:
|
elif create_missing:
|
||||||
target_copy = target_copy.setdefault(key, {})
|
d = d.setdefault(key, {})
|
||||||
else:
|
else:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
f"Key '{key}' is not found under path provided ({path}) and create_missing is False"
|
f"Key '{key}' is not found under path provided ({path}) and create_missing is False"
|
||||||
)
|
)
|
||||||
|
|
||||||
if path[-1] in target_copy or create_missing:
|
if path[-1] in d or create_missing:
|
||||||
target_copy[path[-1]] = value
|
d[path[-1]] = value
|
||||||
|
|
||||||
return target
|
return target
|
||||||
|
|
||||||
|
|
||||||
def nested_delete(target: Dict[str, Any], *path: str) -> Dict[str, Any]:
|
def nested_delete(target: dict, *path: str) -> Dict[str, Any]:
|
||||||
"""Delete the key by its path
|
"""Delete the key by its path
|
||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* target (`Dict[str, Any]`): Dictionary to perform modifications on
|
* target (`dict`): Dictionary to perform modifications on
|
||||||
|
|
||||||
### Raises:
|
### Raises:
|
||||||
* `KeyError`: Key is not found under path provided
|
* `KeyError`: Key is not found under path provided
|
||||||
@@ -71,16 +69,16 @@ def nested_delete(target: Dict[str, Any], *path: str) -> Dict[str, Any]:
|
|||||||
### Returns:
|
### Returns:
|
||||||
`Dict[str, Any]`: Changed dictionary
|
`Dict[str, Any]`: Changed dictionary
|
||||||
"""
|
"""
|
||||||
target_copy: Dict[str, Any] = target
|
d = target
|
||||||
|
|
||||||
for key in path[:-1]:
|
for key in path[:-1]:
|
||||||
if key in target_copy:
|
if key in d:
|
||||||
target_copy = target_copy[key]
|
d = d[key]
|
||||||
else:
|
else:
|
||||||
raise KeyError(f"Key '{key}' is not found under path provided ({path})")
|
raise KeyError(f"Key '{key}' is not found under path provided ({path})")
|
||||||
|
|
||||||
if path[-1] in target_copy:
|
if path[-1] in d:
|
||||||
del target_copy[path[-1]]
|
del d[path[-1]]
|
||||||
else:
|
else:
|
||||||
raise KeyError(f"Key '{path[-1]}' is not found under path provided ({path})")
|
raise KeyError(f"Key '{path[-1]}' is not found under path provided ({path})")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user