Skip to content

Commit

Permalink
increase version and fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlue committed Feb 25, 2024
1 parent d005f36 commit 87327e9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ env/

# ignore codecov
.coverage*
coverage.xml

scratch.py
scratch.R

.env
codecov
codecov
3 changes: 1 addition & 2 deletions biobricks/brick.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .downloader import download_out
from urllib.parse import urlparse
import sys
from .checks import check_url_available, check_token, check_symlink_permission, check_safe_git_repo
from .checks import check_url_available, check_token, check_safe_git_repo

class Brick:

Expand Down Expand Up @@ -125,7 +125,6 @@ def install(self):

check_url_available(self.remote)
check_token(token())
check_symlink_permission()

cmd = functools.partial(run,shell=True,stdout=DEVNULL,stderr=DEVNULL)

Expand Down
4 changes: 2 additions & 2 deletions biobricks/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check_token(token, silent=False):
raise ValueError(f"Invalid token. Run `biobricks configure`")
return is_valid

def check_symlink_permission():
def can_symlink():
try:
src = tempfile.NamedTemporaryFile()
dst = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
Expand All @@ -38,7 +38,7 @@ def check_symlink_permission():
src.close()
return True
except Exception as e:
raise PermissionError("Need Symlink Permission. Contact administrator.")
return False

def check_configured():
"""check that biobricks is configured"""
Expand Down
9 changes: 7 additions & 2 deletions biobricks/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
import requests
import biobricks.checks
from pathlib import Path
from tqdm import tqdm # Import tqdm for the progress bar

Expand Down Expand Up @@ -44,8 +45,12 @@ def download_out(md5, dest: Path, url_prefix="https://dvc.biobricks.ai/files/md5
logger.info(f"downloading file {remote_url} to {cache_path}")
_download_outfile(remote_url, cache_path, bytes)

dest.unlink(missing_ok=True) # remove the symlink if it exists
os.symlink(cache_path, dest)
dest.unlink(missing_ok=True) # remove the symlink if it exists
if not biobricks.checks.can_symlink():
logger.warning(f"you are not able to make symlinks cache-files will be copied to bricks. This is an inefficient use of disk space.")
shutil.copy(cache_path, dest)
else:
os.symlink(cache_path, dest)



2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "biobricks"
version = "0.3.1"
version = "0.3.2"
authors = [
{ name="Thomas Luechtefeld", email="[email protected]" },
{ name="Jose A. Jaramillo", email="[email protected]" }
Expand Down
20 changes: 19 additions & 1 deletion tests/test_init.py → tests/test_bricks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import unittest
from unittest.mock import patch
from pathlib import Path
from biobricks import Brick
from biobricks.config import write_config, init_bblib
import tempfile
import pandas as pd
import sqlite3

class TestBrickResolve(unittest.TestCase):
class BrickTests(unittest.TestCase):

def setUp(self):
self.tempdir = tempfile.TemporaryDirectory()
Expand Down Expand Up @@ -61,6 +62,23 @@ def test_assets_hello_brick(self):
self.assertTrue(hasattr(assets, "mtcars_parquet"))
self.assertTrue(hasattr(assets, "rtbls_iris_parquet"))
self.assertTrue(hasattr(assets, "rtbls_mtcars_parquet"))

@patch('biobricks.checks.can_symlink', return_value=False)
def test_install_without_symlink(self, mocked_can_symlink):
brick = Brick.Resolve("hello-brick")
brick.install()

paths = [
"brick/iris.sqlite",
"brick/mtcars.parquet",
"brick/rtbls/iris.parquet",
"brick/rtbls/mtcars.parquet"
]

for path in paths:
full_path = brick.path() / path
self.assertTrue(full_path.exists())
self.assertFalse(full_path.is_symlink(), f"{path} should not be a symlink")

if __name__ == '__main__':
unittest.main()

0 comments on commit 87327e9

Please sign in to comment.