Skip to content

Commit

Permalink
🚚 Migrate to lamindb v1 (#136)
Browse files Browse the repository at this point in the history
* No longer need to catch MissingContextUI from ln.track()

* ✏️ Fix closing bracket

* πŸ‘½οΈ Update package checks when creating records

* πŸ‘½οΈ Adjust types in API tests

* πŸ‘· Add lamindb devel CI workflow

* πŸ“ Remove UID from track in vignette

* πŸ“ Update CHANGELOG and bump devel version

* 🚸 Add check for Python lamindb version

* πŸ‘· Move lamindb devel check to main workflow

* πŸ‘½οΈ Update opening TileDBSoma artifacts for v1

* πŸ“Œ Bump lamindb dependency to v1.0.2

---------

Co-authored-by: Luke Zappia <[email protected]>
  • Loading branch information
falexwolf and lazappi authored Jan 20, 2025
1 parent 5634127 commit 3ebf151
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- { os: ubuntu-latest, r: "devel", http-user-agent: "release", python: "3.x" }
- { os: ubuntu-latest, r: "release", python: "3.x" }
- { os: ubuntu-latest, r: "oldrel-1", python: "3.9" }
- { os: ubuntu-latest, r: "release", http-user-agent: "release", python: "3.x", lamin: "devel" }
- { os: ubuntu-latest, r: "devel", http-user-agent: "release", python: "3.x", lamin: "devel" }

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -76,6 +78,10 @@ jobs:
- name: Setup Python environment
run: |
laminr::install_lamindb(extra_packages = c("s3fs"))
if ("${{ matrix.config.lamin }}" == "devel") {
reticulate::use_virtualenv("r-lamindb")
reticulate::py_install("git+https://github.com/laminlabs/lamindb.git")
}
shell: Rscript {0}

- name: Log in to Lamin
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# laminr devel

## MAJOR CHANGES

- Updates for compatibility with the Python `lamindb` v1.0 release

## MINOR CHANGES

- `db$track()` can not automatically create a transform UID when not supplied

# laminr v0.3.1

This release improves the UX for setting up the Python environment and adds functions to allow access to CLI functionality from R.
Expand Down Expand Up @@ -43,7 +53,6 @@ This release contains mostly UX improvements:
- Update roadmap (PR #112).
- Simplify `README` content (PR #116).


# laminr v0.2.0

This release adds support for creating new artifacts in a LaminDB instance.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: laminr
Title: Client for 'LaminDB'
Version: 0.3.1
Version: 0.3.1.9000
Authors@R: c(
person("Robrecht", "Cannoodt", email = "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-3641-729X")),
Expand Down
3 changes: 1 addition & 2 deletions R/Artifact.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ ArtifactRecord <- R6::R6Class( # nolint object_name_linter
#' @return A [tiledbsoma::SOMACollection] or [tiledbsoma::SOMAExperiment]
#' object
open = function() {
is_tiledbsoma <- private$get_value("suffix") == ".tiledbsoma" ||
private$get_value("_accessor") == "tiledbsoma"
is_tiledbsoma <- private$get_value("otype") == "tiledbsoma"

if (!is_tiledbsoma) {
cli::cli_abort(
Expand Down
45 changes: 17 additions & 28 deletions R/Instance.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ create_instance <- function(instance_settings, is_default = FALSE) {
}
)

if (!is.null(py_lamin)) {
lamin_version <- reticulate::py_get_attr(py_lamin, "__version__")
lamin_version_clean <- sub("([a-zA-Z].*)", "", lamin_version) # Remove pre-release versions, e.g. 1.0a5 -> 1.0
if (compareVersion("1.0.2", lamin_version_clean) == 1) {
cli::cli_abort(
c(
paste(
"This version of {.pkg laminr} requires Python {.pkg lamindb} >= 1.0.",
"You have {.pkg lamindb} v{lamin_version}."
),
"i" = "Run {.run laminr::install_lamindb()} to update."
)
)
}
}

# create the instance
RichInstance$new(
settings = instance_settings,
Expand Down Expand Up @@ -229,34 +245,7 @@ Instance <- R6::R6Class( # nolint object_name_linter
}
}

if (is.null(transform)) {
transform <- tryCatch(
py_lamin$track(path = path),
error = function(err) {
py_err <- reticulate::py_last_error()
# please don't change the below without changing it in lamindb
if (py_err$type != "MissingContextUID") {
cli::cli_abort(c(
"Python {py_err$message}",
"i" = "Run {.run reticulate::py_last_error()} for details"
))
}

uid <- gsub(".*\\(\"(.*?)\"\\).*", "\\1", py_err$value)
cli::cli_inform(paste(
"To track this notebook, run: db$track(\"{uid}\")"
))
}
)
} else {
if (is.character(transform) && nchar(transform) != 16) {
cli::cli_abort(
"The transform UID must be exactly 16 characters, got {nchar(transform)}"
)
}

py_lamin$track(transform = transform, path = path)
}
py_lamin$track(transform = transform, path = path)
},
#' @description Finish a tracked run
finish = function() {
Expand Down
4 changes: 2 additions & 2 deletions R/Registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ create_record_from_python <- function(py_record, instance) {

class_split <- strsplit(py_classes[1], "\\.")[[1]]
module_name <- class_split[1]
if (module_name == "lnschema_core") {
if (module_name == "lamindb") {
module_name <- "core"
}
registry_name <- tolower(class_split[3])
Expand All @@ -534,7 +534,7 @@ create_record_from_python <- function(py_record, instance) {
NULL
}
)
if (inherits(value, "lnschema_core.models.Record")) {
if (inherits(value, "lamindb.models.Record")) {
value <- create_record_from_python(value, instance)
}
value
Expand Down
2 changes: 1 addition & 1 deletion R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_lamindb <- function(..., envname = "r-lamindb", extra_packages = NULL,
reticulate::virtualenv_remove(envname)
}

packages <- unique(c("lamindb", "ipython", extra_packages))
packages <- unique(c("lamindb>=1.0.2", "ipython", extra_packages))

reticulate::py_install(packages = packages, envname = envname, ...)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-instance_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_that("get_record works", {
# try to get a record
artifact <- api$get_record("core", "artifact", "mePviem4DGM4SFzvLXf3")

expect_true(all(c("uid", "size", "hash", "description", "type") %in% names(artifact)))
expect_true(all(c("uid", "size", "hash", "description") %in% names(artifact)))
})

test_that("test get_record fails gracefully with incorrect host", {
Expand All @@ -78,7 +78,7 @@ test_that("get_record with select works", {
# try to get a record
artifact <- api$get_record("core", "artifact", "mePviem4DGM4SFzvLXf3", select = "storage")

expect_true(all(c("uid", "size", "hash", "description", "type") %in% names(artifact)))
expect_true(all(c("uid", "size", "hash", "description") %in% names(artifact)))

expect_true(all(c("uid", "type", "region", "root") %in% names(artifact$storage)))
})
Expand Down
8 changes: 1 addition & 7 deletions vignettes/laminr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,9 @@ LaminDB tracks which code is used to create data.
To track the current source code, run:

```{r track, eval = submit_eval}
db$track("I8BlHXFXqZOG0000")
db$track()
```

<div class="alert alert-info" role="alert">
**Tip**

The UID (here `"I8BlHXFXqZOG0000"`) is obtained by running `db$track()` and copying the UID from the output.
</div>

# Connect to other instances

It is possible to connect to any LaminDB instance for reading data.
Expand Down

0 comments on commit 3ebf151

Please sign in to comment.