-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: update
DirBasedPackage
to represent dist directory, not sou…
…rce directory Use Pydantic's internal JSON parser consistently. BREAKING CHANGE: Removed `manifest` from `DirBasedPackage` constructor arguments.
- Loading branch information
Showing
6 changed files
with
30 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ description = "QuestionPy application server" | |
authors = ["Technische Universität Berlin, innoCampus <[email protected]>"] | ||
license = "MIT" | ||
homepage = "https://questionpy.org" | ||
version = "0.2.5" | ||
version = "0.2.6" | ||
packages = [ | ||
{ include = "questionpy_common" }, | ||
{ include = "questionpy_server" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
# The QuestionPy Server is free software released under terms of the MIT license. See LICENSE.md. | ||
# (c) Technische Universität Berlin, innoCampus <[email protected]> | ||
import inspect | ||
import json | ||
import sys | ||
import zipfile | ||
from abc import ABC, abstractmethod | ||
|
@@ -73,8 +72,8 @@ def __init__(self, path: Path): | |
@cached_property | ||
def manifest(self) -> Manifest: | ||
"""Load QuestionPy manifest from package.""" | ||
data = json.loads(self.read(f"{DIST_DIR}/{MANIFEST_FILENAME}")) | ||
return Manifest.model_validate(data) | ||
data = self.read(f"{DIST_DIR}/{MANIFEST_FILENAME}") | ||
return Manifest.model_validate_json(data) | ||
|
||
def get_path(self, path: str) -> Traversable: | ||
# Intuitively, a path beginning with '/' should be absolute within the package, but ZipFile behaves differently. | ||
|
@@ -98,23 +97,24 @@ def __repr__(self) -> str: | |
|
||
|
||
class DirBasedPackage(ImportablePackage): | ||
"""A package's source directory to be used directly.""" | ||
"""A package's dist directory to be used directly.""" | ||
|
||
def __init__(self, path: Path, manifest: Manifest) -> None: | ||
def __init__(self, path: Path) -> None: | ||
self.path = path | ||
self._manifest = manifest | ||
|
||
@property | ||
@cached_property | ||
def manifest(self) -> Manifest: | ||
return self._manifest | ||
"""Load QuestionPy manifest from package.""" | ||
manifest_path = self.path / MANIFEST_FILENAME | ||
return Manifest.model_validate_json(manifest_path.read_bytes()) | ||
|
||
def get_path(self, path: str) -> Traversable: | ||
return self.path.joinpath(path) | ||
|
||
def setup_imports(self) -> None: | ||
for new_path in ( | ||
str(self.path / DIST_DIR / "dependencies" / "site-packages"), | ||
str(self.path / DIST_DIR / "python"), | ||
str(self.path / "dependencies" / "site-packages"), | ||
str(self.path / "python"), | ||
): | ||
if new_path not in sys.path: | ||
sys.path.insert(0, new_path) | ||
|
@@ -172,7 +172,7 @@ def load_package(location: PackageLocation) -> ImportablePackage: | |
if isinstance(location, ZipPackageLocation): | ||
return ZipBasedPackage(location.path) | ||
if isinstance(location, DirPackageLocation): | ||
return DirBasedPackage(location.path, location.manifest) | ||
return DirBasedPackage(location.path) | ||
if isinstance(location, FunctionPackageLocation): | ||
return FunctionBasedPackage(location.module_name, location.function_name, location.manifest) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,12 @@ | |
# (c) Technische Universität Berlin, innoCampus <[email protected]> | ||
|
||
import mimetypes | ||
from copy import deepcopy | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from questionpy_common.constants import DIST_DIR, MANIFEST_FILENAME, MiB | ||
from questionpy_common.manifest import PackageFile | ||
from questionpy_common.constants import MANIFEST_FILENAME, MiB | ||
from questionpy_common.manifest import Manifest, PackageFile | ||
from questionpy_server import WorkerPool | ||
from questionpy_server.worker.runtime.package_location import DirPackageLocation | ||
from questionpy_server.worker.worker.base import StaticFileSizeMismatchError | ||
|
@@ -36,15 +35,16 @@ async def test_should_get_manifest(pool: WorkerPool) -> None: | |
|
||
|
||
def _inject_static_file_into_dist(package: DirPackageLocation, name: str, content: str) -> None: | ||
full_path = package.path / DIST_DIR / name | ||
full_path = package.path / name | ||
full_path.parent.mkdir(exist_ok=True) | ||
full_path.write_text(content) | ||
|
||
|
||
def _inject_static_file_into_manifest(package: DirPackageLocation, name: str, size: int) -> None: | ||
package.manifest = deepcopy(package.manifest) | ||
package.manifest.static_files[name] = PackageFile(mime_type=mimetypes.guess_type(name)[0], size=size) | ||
(package.path / DIST_DIR / MANIFEST_FILENAME).write_text(package.manifest.model_dump_json()) | ||
manifest_path = package.path / MANIFEST_FILENAME | ||
manifest = Manifest.model_validate_json(manifest_path.read_bytes()) | ||
manifest.static_files[name] = PackageFile(mime_type=mimetypes.guess_type(name)[0], size=size) | ||
manifest_path.write_text(manifest.model_dump_json()) | ||
|
||
|
||
_STATIC_FILE_NAME = "static/test_file.txt" | ||
|