Skip to content

feat: add a uri property to the file controllers - #3

Open
LukasGold wants to merge 1 commit into
mainfrom
feat/file-controller-uri
Open

LukasGold wants to merge 1 commit into
mainfrom
feat/file-controller-uri

Conversation

@LukasGold

Copy link
Copy Markdown
Contributor

Adds a read-only uri property to the file controllers. The subject moves here from OpenSemanticLab/osw-python#158, because osw-python re-exports the file controllers of this package after OpenSemanticLab/osw-python#214, which is merged into its stage branch and not yet into main.

Changes

src/opensemantic/core/_file_controller_mixin.py:

  • FileControllerMixin.uri: returns None by default. It is not abstract: pydantic v1's ModelMetaclass extends ABCMeta, so an abstract property would stop every existing file controller outside this package from being instantiated.
  • LocalFileControllerMixin.uri: the file:// URI of local_path (resolve_path().absolute().as_uri()), None if local_path is unset.
  • InMemoryControllerMixin.uri: None, a stream in memory has no location.
  • RemoteFileControllerMixin.uri: what _url() returns (download_url, else access_url), None if neither is set. A subclass that overrides _url() is honored.

tests/test_file_controller_uri.py: 25 tests over the v1 and v2 controllers. They cover each controller, a third-party subclass that defines only get and put, and that uri appears neither in .dict() / model_dump(), nor in the JSON output, nor in the JSON schema.

Design note for review: a Python-only property

  • uri is derived on every access and never stored. It is a property of the Python class only and has no counterpart in the JSON schema of the page package. The tests check that it does not reach the schema or the serialized data.
  • It is the first @property in this package: before this change, grep -rn "@property" src/opensemantic/core found nothing, and the generated _model.py files contain none.
  • In this package it sets a precedent for Python-only behaviour on top of the generated models. osw-python already has at least one such property outside this package: WikiFileController.url (https://github.com/OpenSemanticLab/osw-python/blob/main/src/osw/controller/file/wiki.py), on a class built on model.WikiFile. Please decide whether this is the intended pattern for the generated classes.

Follow-up in osw-python

Tests

  • pytest --no-cov -q: 101 passed (76 before, 25 new).
  • pre-commit run --all-files: passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant