Skip to content

Commit

Permalink
Merge branch 'main' into wip/update-single-value
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum authored Apr 16, 2024
2 parents 506dabb + 76a9460 commit 8989356
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 188 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ jobs:
- name: Install Python dependencies
run: poetry install

- name: Linting with Pylint
run: poetry run pylint dsp_permissions_scripts tests
- name: Formatting with ruff
run: poetry run ruff format .

- name: Linting with ruff
run: poetry run ruff check .

- name: Linting with mypy
run: poetry run mypy .
Expand Down
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Configuration of https://pre-commit.com/

repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
hooks:
- id: ruff
# args: [
# --ignore=A002,
# --ignore=D101,
# --ignore=D102,
# --ignore=PLR0913,
# --ignore=PLR2004,
# --ignore=PLW0603,
# ]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, main]
- id: fix-byte-order-marker
- id: detect-private-key
- id: check-symlinks
- id: destroyed-symlinks
- id: mixed-line-ending

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/ap/ap_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def serialize_aps_of_project(
aps_as_dict = {explanation_string: aps_as_dicts}
with open(filepath, mode="w", encoding="utf-8") as f:
f.write(json.dumps(aps_as_dict, ensure_ascii=False, indent=2))
logger.info(f"{len(project_aps)} APs have been written to file {str(filepath)}")
logger.info(f"{len(project_aps)} APs have been written to file {filepath}")


def deserialize_aps_of_project(
Expand All @@ -38,5 +38,5 @@ def deserialize_aps_of_project(
filepath = _get_file_path(shortcode, mode)
with open(filepath, mode="r", encoding="utf-8") as f:
aps_as_dict = json.load(f)
aps_as_dicts = list(aps_as_dict.values())[0]
aps_as_dicts = next(iter(aps_as_dict.values()))
return [Ap.model_validate(d) for d in aps_as_dicts]
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/doap/doap_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def serialize_doaps_of_project(
doaps_as_dict = {explanation_string: doaps_as_dicts}
with open(filepath, mode="w", encoding="utf-8") as f:
f.write(json.dumps(doaps_as_dict, ensure_ascii=False, indent=2))
logger.info(f"{len(project_doaps)} DOAPs have been written to file {str(filepath)}")
logger.info(f"{len(project_doaps)} DOAPs have been written to file {filepath}")


def deserialize_doaps_of_project(
Expand All @@ -42,5 +42,5 @@ def deserialize_doaps_of_project(
filepath = _get_file_path(shortcode, mode)
with open(filepath, mode="r", encoding="utf-8") as f:
doaps_as_dict = json.load(f)
doaps_as_dicts = list(doaps_as_dict.values())[0]
doaps_as_dicts = next(iter(doaps_as_dict.values()))
return [Doap.model_validate(d) for d in doaps_as_dicts]
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/oap/oap_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def serialize_oaps(
for value_oap in oap.value_oaps:
_serialize_oap(value_oap, folder)
counter += 1
logger.info(f"Successfully wrote {len(oaps)} OAPs into {counter} files in folder {str(folder)}")
logger.info(f"Successfully wrote {len(oaps)} OAPs into {counter} files in folder {folder}")


def _serialize_oap(oap: ResourceOap | ValueOap, folder: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/oap/oap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _update_permissions_for_value(
raise err from None


def _update_permissions_for_resource(
def _update_permissions_for_resource( # noqa: PLR0913
resource_iri: str,
lmd: str | None,
resource_type: str,
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions dsp_permissions_scripts/utils/dsp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from dsp_permissions_scripts.utils.get_logger import get_logger
from dsp_permissions_scripts.utils.helpers import PACKAGE_NAME

# ruff: noqa: PLR2004 (magic value used in comparison)

logger = get_logger(__name__)

HTTP_OK = 200
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/utils/get_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def log_start_of_script(host: str, shortcode: str) -> None:
logger.info("")

print(f"\n{msg}")
logfile = [handler.baseFilename for handler in logger.handlers if isinstance(handler, logging.FileHandler)][0]
logfile = next(handler.baseFilename for handler in logger.handlers if isinstance(handler, logging.FileHandler))
print(f"There will be no print output, only logging to file {logfile}")
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/utils/scope_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create_string_from_scope(perm_scope: PermissionScope) -> str:
for perm_letter in perm_scope.model_fields:
if groups := perm_scope.get(perm_letter):
as_dict[perm_letter] = sort_groups(groups)
strs = [f"{k} {','.join([x.val for x in l])}" for k, l in as_dict.items()]
strs = [f"{k} {','.join([x.val for x in v])}" for k, v in as_dict.items()]
return "|".join(strs)


Expand Down
Loading

0 comments on commit 8989356

Please sign in to comment.