feat(controller): add a uri property to every file controller - #158
feat(controller): add a uri property to every file controller#158LukasGold wants to merge 2 commits into
Conversation
Release previewMerging this PR would release v2.1.0 (current: Changelog preview (truncated)## v2.1.0 (2026-09-02)
### Bug Fixes
- Allow uploading a file from an in-memory stream
([`64d99d6`](https://github.com/OpenSemanticLab/osw-python/commit/64d99d66ea45bc56bdaa6d12f2502df0bbbaf88c))
### Features
- **controller**: Add a uri property to every file controller
([`5ec4038`](https://github.com/OpenSemanticLab/osw-python/commit/5ec4038ee8e7dc1085c4ec7d1c290667791bee48))
### Refactoring
- Make FileController.uri a concrete default instead of abstract
([`ad43d07`](https://github.com/OpenSemanticLab/osw-python/commit/ad43d078c4d8fe4341907358bb4cc0a36a51432d))
### Testing
- Rename oold.py to oold_test.py so its tests are collected
([`20072a9`](https://github.com/OpenSemanticLab/osw-python/commit/20072a9249cd97126a222c62a70f84e0433343ef))
Preview via python-semantic-release and conventional commits. |
- file:// for LocalFileController, via Path.as_uri - the stored url for RemoteFileController, so s3:// and https:// follow - None for InMemoryController, a stream has no location
998e846 to
5ec4038
Compare
- returns None on the base class, so controllers outside this package that predate uri stay instantiable (ModelMetaclass extends ABCMeta) - document uri as the derived read interface for a location - state the implicit url contract on RemoteFileController
|
Changed Reason: pydantic v1's That is a breaking change for any file controller outside this package, and it was not marked as one, so it would have shipped as a minor release.
Follow-up on harmonizing |
LukasGold
left a comment
There was a problem hiding this comment.
Reasonable changes that provide a uniform access point
Closes #68.
Stacked on #148, which makes
InMemoryControllerconstructible. Merge that first, this base retargets tomainautomatically.Changes
FileController.uri: the location of the file in the URI scheme of its storage backend. Concrete, returnsNoneby default.LocalFileController.uri:file://, viaPath.absolute().as_uri(), see https://en.wikipedia.org/wiki/File_URI_scheme.RemoteFileController.uri: the storedurl.S3FileControllerandWikiFileControllerinherit it, so they reports3://...andhttps://.../wiki/File:...without an override.InMemoryController.uri:None.tests/test_file_controller_uri.py: 7 offline tests.Rationale
A caller holding a
FileControllerhad no way to ask where the file actually is. Each subclass kept that in a different shape: aPath, aurl, or nothing at all.WikiFileControlleralready builds the page url in itsurlproperty (src/osw/controller/file/wiki.py:167), andS3FileControllerparsesself.urlfor its bucket and key, so puttingurionRemoteFileControllercovers both from what they already carry.uriis a read interface: derived on every access, never stored, so it cannot go stale. Each controller keeps the handle its backend actually needs and answersuriin its own scheme. The wider harmonization ofpath/url/uri, and afrom_uri()write-side counterpart, are proposed in #68 (comment) and are out of scope here.Notes
ModelMetaclassextendsABCMeta, so@abstractmethodis enforced at instantiation and an abstracturiwould break every file controller outside this package that predates it. A concreteNonedefault keeps this afeat, not a breaking change.InMemoryControllerreturnsNonerather than raising. A stream is a legitimate file source, it just has no address.Verification
Offline suite passes (66 passed, 1 skipped). The wiki and S3 controllers need a live backend, so their
uriis covered throughRemoteFileControllerand, for the wiki page url, by calling the property directly on a stand-in.