From 145a71361c51b779b3c5b520c918ba60ca1d0ddc Mon Sep 17 00:00:00 2001 From: Binh Vu Date: Sat, 13 Apr 2024 11:27:15 -0700 Subject: [PATCH] - SAND CLI can import dataset returned from a python function - SAND CLI create project command does not require project's description (default to use dataset name) --- CHANGELOG.md | 12 +++++++++++- pyproject.toml | 4 ++-- sand/__main__.py | 6 +++--- sand/commands/load.py | 13 +++++++++++-- sand_scripts/__init__.py | 0 sand_scripts/predefined_datasets.py | 5 +++++ 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 sand_scripts/__init__.py create mode 100644 sand_scripts/predefined_datasets.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fc3ec57..7f4e672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,20 @@ # Changelog +## [4.1.0] - 2024-04-13 + +### Added + +- SAND CLI can import dataset returned from a python function + +### Changed + +- SAND CLI create project command does not require project's description (default to use dataset name) + ## [Unreleased](https://github.com/usc-isi-i2/sand/tree/HEAD) [Full Changelog](https://github.com/usc-isi-i2/sand/compare/2.1.5...HEAD) -**Changed** +### Changed - Update dependency: `d-repr` version constraint to `^2.10.0` from prerelease version. - Update dockerfile and add docker-compose example. diff --git a/pyproject.toml b/pyproject.toml index cebdd04..8882f9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,13 @@ [tool.poetry] name = "web-sand" -version = "4.0.2" +version = "4.1.0" description = "UI for browsing/editing semantic descriptions" authors = ["Binh Vu "] repository = "https://github.com/usc-isi-i2/sand" license = "MIT" packages = [{ include = "sand" }] readme = "README.md" -include = ["sand/www/**/*"] +# include = ["sand/www/**/*"] [tool.poetry.scripts] sand = 'sand.__main__:cli' diff --git a/sand/__main__.py b/sand/__main__.py index 7b25ef0..0bea495 100644 --- a/sand/__main__.py +++ b/sand/__main__.py @@ -72,12 +72,12 @@ def start( @click.command() @click.option("-d", "--db", required=True, help="sand database file") -@click.option("--description", required=True, help="Description of the project") +@click.option("--description", help="Description of the project") @click.argument("name") -def create(db, description: str, name: str): +def create(db, description: Optional[str], name: str): """Create project if not exist""" init_db(db) - Project(name=name, description=description).save() + Project(name=name, description=description or name).save() @click.command(help="Remove a project") diff --git a/sand/commands/load.py b/sand/commands/load.py index a41ebb9..6a8f038 100644 --- a/sand/commands/load.py +++ b/sand/commands/load.py @@ -3,6 +3,7 @@ import click from sm.dataset import Dataset, Example, FullTable +from sm.misc.funcs import import_func from sm.outputs.semantic_model import DataNode from tqdm.auto import tqdm @@ -22,7 +23,11 @@ @click.command(name="load") @click.option("-d", "--db", required=True, help="smc database file") @click.option("-p", "--project", default="default", help="Project name") -@click.option("--dataset", required=True, help="Path to tables") +@click.option( + "--dataset", + required=True, + help="Path to tables or a python function that returns the dataset in the following format: ::", +) @click.option( "-n", "--n-tables", @@ -34,7 +39,11 @@ def load_dataset(db: str, project: str, dataset: str, n_tables: int): """Load a dataset into a project""" init_db(db) - examples = Dataset(Path(dataset)).load() + if dataset.find("::") != -1: + func, dsquery = dataset.split("::") + examples = import_func(func)(dsquery).load() + else: + examples = Dataset(Path(dataset)).load() if n_tables > 0: examples = examples[:n_tables] diff --git a/sand_scripts/__init__.py b/sand_scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sand_scripts/predefined_datasets.py b/sand_scripts/predefined_datasets.py new file mode 100644 index 0000000..fd1dd2f --- /dev/null +++ b/sand_scripts/predefined_datasets.py @@ -0,0 +1,5 @@ +from sm_datasets.datasets import Datasets + + +def load(dataset: str): + return Datasets().get_dataset(dataset)