Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3/.devcontainer/base.Dockerfile

# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
RUN sudo curl --location https://taskfile.dev/install.sh -o /install.sh

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
56 changes: 56 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.7",
// Options
"NODE_VERSION": "lts/*"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.analysis.typeCheckingMode": "strict"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
]
}
},
"remoteUser": "vscode",
"postStartCommand": "pip install -r requirements-dev.txt && sudo sh /install.sh -d -b ~/.local/bin"
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.

}
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
./scripts/version.sh
pycodestyle --format=pylint setup.py archivist examples functests unittests
python3 -m pylint --rcfile=pylintrc setup.py archivist examples functests unittests
python3 -m pyright archivist
black archivist examples unittests functests
(cd docs && make clean && make html)
modified=$(git status -s | wc -l)
Expand Down
13 changes: 13 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
version: '3'

includes:
# Task file to be used inside the dev-containter
dev:
taskfile: ./Taskfile_dev.yml
dir: ./

tasks:

about:
Expand Down Expand Up @@ -42,6 +48,7 @@ tasks:
- ./scripts/builder.sh python3 --version
- ./scripts/builder.sh pycodestyle --format=pylint setup.py archivist examples functests unittests
- ./scripts/builder.sh python3 -m pylint --rcfile=pylintrc setup.py archivist examples functests unittests
- ./scripts/builder.sh python3 -m pyright archivist

clean:
desc: Clean git repo
Expand All @@ -66,6 +73,12 @@ tasks:
cmds:
- ./scripts/builder.sh black setup.py archivist examples functests unittests

type-check:
desc: Runs the pyright type checker against the core archivst files
deps: [about]
cmds:
- ./scripts/builder.sh pyright archivist

functests:
desc: Run functests - requires an archivist instance and a authtoken
deps: [about]
Expand Down
72 changes: 72 additions & 0 deletions Taskfile_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
version: '3'

tasks:

about:
desc: Generate about.py
cmds:
- ./scripts/version.sh
status:
- test -s archivist/about.py

audit:
desc: Audit the code
deps: [about]
cmds:
- pip-audit -r requirements.txt

check:
desc: Check the style, bug and quality of the code
deps: [about]
cmds:
- python3 --version
- pycodestyle --format=pylint setup.py archivist examples functests unittests
- python3 -m pylint --rcfile=pylintrc setup.py archivist examples functests unittests
- python3 -m pyright archivist

clean:
desc: Clean git repo
cmds:
- find -name '*,cover' -type f -delete
- git clean -fdX

deps:
desc: Show dependency tree
cmds:
- /bin/bash -c "pipdeptree"

docs:
desc: Create sphinx documentation
deps: [about]
cmds:
- /bin/bash -c "cd docs && make clean && make html"

format:
desc: Format code using black
deps: [about]
cmds:
- black setup.py archivist examples functests unittests

functests:
desc: Run functests - requires an archivist instance and a authtoken
deps: [about]
cmds:
- ./scripts/functests.sh

type-check:
desc: Runs the pyright type checker against the core archivst files
deps: [about]
cmds:
- pyright archivist

notebooks:
desc: Run jupyter notebooks
deps: [about]
cmds:
- jupyter notebook --ip 0.0.0.0 --no-browser --notebook-dir=./notebooks/

unittests:
desc: Run unittests
deps: [about]
cmds:
- ./scripts/unittests.sh
43 changes: 23 additions & 20 deletions archivist/access_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

"""

from typing import Dict, List, Optional
from __future__ import annotations
from logging import getLogger
from copy import deepcopy
from typing import Any, Generator, Optional

# pylint:disable=cyclic-import # but pylint doesn't understand this feature
from . import archivist as type_helper # pylint:disable=unused-import
from . import archivist

from .assets import Asset
from .constants import (
Expand All @@ -35,7 +36,6 @@
ASSETS_LABEL,
)
from .dictmerge import _deepmerge
from .type_aliases import NoneOnError


LOGGER = getLogger(__name__)
Expand All @@ -45,7 +45,7 @@ class AccessPolicy(dict):
"""AccessPolicy object"""

@property
def name(self) -> NoneOnError[str]:
def name(self) -> str | None:
"""str: name of the access policy"""
return self.get("display_name")

Expand All @@ -61,16 +61,19 @@ class _AccessPoliciesClient:

"""

def __init__(self, archivist: "type_helper.Archivist"):
self._archivist = archivist
self._subpath = f"{archivist.root}/{ACCESS_POLICIES_SUBPATH}"
def __init__(self, archivist_instance: archivist.Archivist):
self._archivist = archivist_instance
self._subpath = f"{archivist_instance.root}/{ACCESS_POLICIES_SUBPATH}"
self._label = f"{self._subpath}/{ACCESS_POLICIES_LABEL}"

def __str__(self) -> str:
return f"AccessPoliciesClient({self._archivist.url})"

def create(
self, props: Dict, filters: List, access_permissions: List
self,
props: dict[str, Any],
filters: list[dict[str, Any]],
access_permissions: list[dict[str, Any]],
) -> AccessPolicy:
"""Create access policy

Expand All @@ -92,7 +95,7 @@ def create(
),
)

def create_from_data(self, data: Dict) -> AccessPolicy:
def create_from_data(self, data: dict[str, Any]) -> AccessPolicy:
"""Create access policy

Creates access policy with request body from data stream.
Expand Down Expand Up @@ -130,9 +133,9 @@ def update(
self,
identity,
*,
props: Optional[Dict] = None,
filters: Optional[List] = None,
access_permissions: Optional[List] = None,
props: Optional[dict[str, Any]] = None,
filters: Optional[list[dict]] = None,
access_permissions: Optional[list[dict]] = None,
) -> AccessPolicy:
"""Update Access Policy

Expand All @@ -157,7 +160,7 @@ def update(
)
)

def delete(self, identity: str) -> Dict:
def delete(self, identity: str) -> dict[str, Any]:
"""Delete Access Policy

Deletes access policy.
Expand All @@ -173,11 +176,11 @@ def delete(self, identity: str) -> Dict:

def __params(
self,
props: Optional[Dict],
props: Optional[dict[str, Any]],
*,
filters: Optional[List] = None,
access_permissions: Optional[List] = None,
) -> Dict:
filters: list[dict] | None = None,
access_permissions: list[dict] | None = None,
) -> dict[str, Any]:
params = deepcopy(props) if props else {}
if filters is not None:
params["filters"] = filters
Expand All @@ -204,7 +207,7 @@ def count(self, *, display_name: Optional[str] = None) -> int:

def list(
self, *, page_size: Optional[int] = None, display_name: Optional[str] = None
):
) -> Generator[AccessPolicy, None, None]:
"""List access policies.

List access policies that match criteria.
Expand All @@ -231,7 +234,7 @@ def list(
# additional queries on different endpoints
def list_matching_assets(
self, access_policy_id: str, *, page_size: Optional[int] = None
):
) -> Generator[Asset, None, None]:
"""List matching assets.

List assets that match access policy.
Expand All @@ -255,7 +258,7 @@ def list_matching_assets(

def list_matching_access_policies(
self, asset_id: str, *, page_size: Optional[int] = None
):
) -> Generator[AccessPolicy, None, None]:
"""List matching access policies.

List access policies that match asset.
Expand Down
9 changes: 5 additions & 4 deletions archivist/appidp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

"""

from __future__ import annotations
from logging import getLogger

# pylint:disable=cyclic-import # but pylint doesn't understand this feature
# pylint:disable=too-few-public-methods
from . import archivist as type_helper # pylint:disable=unused-import
from . import archivist

from .constants import (
APPIDP_SUBPATH,
Expand All @@ -51,9 +52,9 @@ class _AppIDPClient:

"""

def __init__(self, archivist: "type_helper.Archivist"):
self._archivist = archivist
self._subpath = f"{archivist.root}/{APPIDP_SUBPATH}"
def __init__(self, archivist_instance: archivist.Archivist):
self._archivist = archivist_instance
self._subpath = f"{archivist_instance.root}/{APPIDP_SUBPATH}"
self._label = f"{self._subpath}/{APPIDP_LABEL}"

def __str__(self) -> str:
Expand Down
Loading