Skip to content

Commit

Permalink
Use the Mojo package manager Magic for the project
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunk committed Oct 5, 2024
1 parent 280ec8b commit 1f60bf5
Show file tree
Hide file tree
Showing 6 changed files with 859 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
magic.lock linguist-language=YAML linguist-generated=true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,8 @@ cython_debug/
.pixi
*.egg-info
# magic environments
.magic/

.vscode/
# magic environments
.magic
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ from duckdb import *
var con = DuckDB.connect(":memory:")
_ = con.execute(
"""
_ = con.execute("""
SET autoinstall_known_extensions=1;
SET autoload_known_extensions=1;
CREATE TABLE train_services AS
FROM 's3://duckdb-blobs/train_services.parquet';
"""
)
var result = con.execute(
"""
var result = con.execute("""
-- Get the top-3 busiest train stations
SELECT station_name, count(*) AS num_services
FROM train_services
Expand All @@ -45,21 +46,15 @@ for row in range(len(result)):

## Installation

1. [Install Mojo](https://docs.modular.com/mojo/manual/get-started#1-install-mojo). Currently nightly >= `2024.7.1105` is required, so install or update the nightly version: `modular install nightly/mojo`
2. Download the DuckDB C/C++ library from the [installation](https://duckdb.org/docs/installation/?version=stable&environment=cplusplus) page.
3. Extract `libduckdb.so` (Linux) or `libduckdb.dylib` (macOS) to the project directory.
4. Set library path:
```shell
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(realpath .) # Linux
export DYLD_FALLBACK_LIBRARY_PATH=$(realpath .) # macOS
```
5. Run
``` shell
mojo example.mojo
```
Currently, you'll need to checkout the source. We'll publish a Conda package soon to make it easier to use from another Mojo project.

1. [Install the Magic package manager for Mojo](https://docs.modular.com/mojo/manual/get-started#1-install-mojo).
2. Checkout this repo
3. Run `magic shell`
4. Run `mojo example.mojo`

### Run Tests

```shell
mojo test -I .
magic run test
```
6 changes: 4 additions & 2 deletions example.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ from duckdb import *
def main():
var con = DuckDB.connect(":memory:")

_ = con.execute(
"""
_ = con.execute("""
SET autoinstall_known_extensions=1;
SET autoload_known_extensions=1;
CREATE TABLE train_services AS
FROM 's3://duckdb-blobs/train_services.parquet';
"""
Expand Down
Loading

0 comments on commit 1f60bf5

Please sign in to comment.