Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

🎨 Order artifact collections #333

Merged
merged 8 commits into from
Jan 7, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
python-version: ['3.10']
timeout-minutes: 15

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: ".github/workflows/build.yml" # See dependencies below
cache: 'pip'
cache-dependency-path: '.github/workflows/build.yml' # See dependencies below
- name: cache pre-commit
uses: actions/cache@v3
with:
Expand Down
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ repos:
rev: v2.6.2
hooks:
- id: prettier
exclude: |
(?x)(
build.yml|
.pre-commit-config.yaml
)
- repo: https://github.com/kynan/nbstripout
rev: 0.3.9
hooks:
Expand All @@ -53,7 +58,7 @@ repos:
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
args: ['--profile', 'black']
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.940
hooks:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.1 on 2024-01-07 19:08

import django.db.models.deletion
from django.db import migrations, models

import lnschema_core.models


class Migration(migrations.Migration):
dependencies = [
("lnschema_core", "0038_alter_collection_artifact_alter_collection_artifacts_and_more"),
]

operations = [
migrations.CreateModel(
name="CollectionArtifact",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("collection", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.collection")),
("artifact", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.artifact")),
],
options={
"unique_together": {("collection", "artifact")},
},
bases=(models.Model, lnschema_core.models.LinkORM),
),
migrations.AddField(
model_name="collection",
name="unordered_artifacts",
field=models.ManyToManyField(related_name="collections", through="lnschema_core.CollectionArtifact", to="lnschema_core.artifact"),
),
migrations.RunSQL(
"INSERT INTO lnschema_core_collectionartifact (id, collection_id, artifact_id) SELECT id, collection_id, artifact_id FROM lnschema_core_collection_artifacts"
),
migrations.RemoveField(
model_name="collection",
name="artifacts",
),
]
18 changes: 16 additions & 2 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ class Collection(Registry, Data, IsVersioned):
"""Runs that use this collection as an input."""
artifact = models.OneToOneField("Artifact", on_delete=PROTECT, null=True, unique=True, related_name="collection")
"""Storage of collection as a one artifact."""
artifacts = models.ManyToManyField("Artifact", related_name="collections")
unordered_artifacts = models.ManyToManyField("Artifact", related_name="collections", through="CollectionArtifact")
"""Storage of collection as multiple artifacts."""
visibility = models.SmallIntegerField(db_index=True, choices=VisibilityChoice.choices, default=1)
"""Visibility of record, 0-default, 1-hidden, 2-trash."""
Expand All @@ -1924,6 +1924,11 @@ class Collection(Registry, Data, IsVersioned):
created_by = models.ForeignKey(User, PROTECT, default=current_user_id, related_name="created_collections")
"""Creator of record, a :class:`~lamindb.User`."""

@property
def artifacts(self) -> "QuerySet":
"""Ordered QuerySet of artifacts."""
pass

@overload
def __init__(
self,
Expand Down Expand Up @@ -2046,7 +2051,7 @@ def from_anndata(
def mapped(
self,
label_keys: Optional[Union[str, List[str]]] = None,
join: Optional[Literal["inner", "outer"]] = "outer",
join: Optional[Literal["inner", "outer"]] = "inner",
encode_labels: bool = True,
cache_categories: bool = True,
parallel: bool = False,
Expand Down Expand Up @@ -2160,6 +2165,15 @@ class Meta:
unique_together = ("collection", "feature_set")


class CollectionArtifact(Registry, LinkORM):
id = models.BigAutoField(primary_key=True)
collection = models.ForeignKey(Collection, on_delete=models.CASCADE)
artifact = models.ForeignKey(Artifact, on_delete=models.CASCADE)

class Meta:
unique_together = ("collection", "artifact")


class ArtifactULabel(Registry, LinkORM):
id = models.BigAutoField(primary_key=True)
artifact = models.ForeignKey(Artifact, on_delete=models.CASCADE)
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ def lint(session: nox.Session) -> None:
@nox.session
def test(session: nox.Session) -> None:
session.run(*"pip install -e .[dev]".split())
login_testuser1(session)
run_pytest(session, coverage=False)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Home = "https://github.com/laminlabs/lnschema-core"

[project.optional-dependencies]
dev = [
"lamindb_setup>=0.55.0", # not possible on PyPI: @ git+https://github.com/laminlabs/lamindb-setup
"lamindb_setup@git+https://github.com/laminlabs/lamindb-setup",
"pre-commit",
"nox",
"laminci",
Expand Down
Loading