Skip to content

Commit

Permalink
build: prqlc crate (PRQL#1549)
Browse files Browse the repository at this point in the history
* build: prqlc crate

* docs

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* Update .gitignore

Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>

* Enable compiling with wasm (but compile basically nothing)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* revert test-rust

* Disable test linking in prqlc

* changelog

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
Co-authored-by: Maximilian Roos <m@maxroos.com>
  • Loading branch information
4 people authored Jan 19, 2023
1 parent 9cc853f commit acf9b42
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target
**/.idea

/*.prql
*/*.prql
_*.prql

# Appears when using Docker container
.Trash-0
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- Quoted identifiers such as `dir/*.parquet` are passed through to SQL.
(@max-sixty, #1516).

- The CLI is installed with `cargo install prqlc`. The binary was renamed in
0.4.0 but required an additional `--features` flag, which has been removed in
favor of this new crate (@max-sixty & @aljazerzen, #1549).

**Fixes**:

**Documentation**:
Expand Down
24 changes: 18 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"prql-compiler",
"prql-compiler/examples/compile-files",
"prql-compiler/prql-compiler-macros",
"prql-compiler/prqlc",
"prql-java",
"prql-lib",
"prql-js",
Expand Down
14 changes: 0 additions & 14 deletions prql-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,12 @@ version.workspace = true
# https://github.com/foresterre/cargo-msrv/issues/590 is resolved.
metadata.msrv = "1.65.0"

[features]
cli = ["clio", "atty", "clap", "color-eyre"]

[[bin]]
name = "prqlc"
path = "src/cli.rs"
required-features = ["cli"]

[dependencies]
anyhow = {version = "1.0.57", features = ["backtrace"]}
ariadne = "0.1.5"
atty = {version = "0.2.14", optional = true}
chumsky = "0.8.0"
clap = {version = "4.1.1", optional = true, features = ["derive"]}
clio = {version = "0.2.4", features = ['clap-parse'], optional = true}
color-eyre = {version = "0.6.1", optional = true}
csv = "1.1.6"
enum-as-inner = "0.5.0"
env_logger = {version = "0.9.1", features = ["termcolor"]}
itertools = "0.10.3"
lazy_static = "1.4.0"
log = "0.4.17"
Expand All @@ -41,7 +28,6 @@ regex = "1.7.0"
semver = {version = "1.0.14", features = ["serde"]}
serde = {version = "1.0.137", features = ["derive"]}
serde_json = "1.0.81"
serde_yaml = "0.9.1"
sqlformat = "0.2.0"
sqlparser = {version = "0.30.0", features = ["serde"]}
strum = {version = "0.24.0", features = ["std", "derive"]}# for converting enum variants to string
Expand Down
29 changes: 29 additions & 0 deletions prql-compiler/prqlc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
description = "CLI interface for the PRQL compiler"
name = "prqlc"

edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[lib]
doctest = false
test = false

[target.'cfg(not(target_family="wasm"))'.dependencies]
anyhow = {version = "1.0.57"}
ariadne = "0.1.5"
atty = "0.2.14"
clap = {version = "4.1.1", features = ["derive"]}
clio = {version = "0.2.4", features = ['clap-parse']}
color-eyre = "0.6.1"
env_logger = {version = "0.9.1", features = ["termcolor"]}
itertools = "0.10.3"
prql-compiler = {path = '..'}
serde_json = "1.0.81"
serde_yaml = "0.9.1"

[target.'cfg(not(target_family="wasm"))'.dev-dependencies]
insta = {version = "1.26", features = ["colors", "glob", "yaml"]}
15 changes: 8 additions & 7 deletions prql-compiler/src/cli.rs → prql-compiler/prqlc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(target_family = "wasm"))]
use anyhow::{anyhow, Result};
use ariadne::Source;
use clap::Parser;
Expand All @@ -13,7 +14,7 @@ use prql_compiler::downcast;
use prql_compiler::{ast::pl::Frame, pl_to_prql};
use prql_compiler::{compile, prql_to_pl, Span};

fn main() -> color_eyre::eyre::Result<()> {
pub fn main() -> color_eyre::eyre::Result<()> {
env_logger::builder().format_timestamp(None).init();
color_eyre::install()?;
let mut cli = Cli::parse();
Expand Down Expand Up @@ -89,7 +90,7 @@ impl Cli {
serde_yaml::to_string(&ast)?.into_bytes()
}
Cli::Format(_) => prql_to_pl(source)
.and_then(|x| pl_to_prql(x))
.and_then(pl_to_prql)
.map_err(|x| anyhow!(x))?
.as_bytes()
.to_vec(),
Expand Down Expand Up @@ -214,11 +215,11 @@ sort full
assert_snapshot!(String::from_utf8(output).unwrap().trim(),
@r###"
from initial_table
select [f = first_name, l = last_name, gender] # [f, l, gender]
derive full_name = f + " " + l # [f, l, gender, full_name]
take 23 # [f, l, gender, full_name]
select [l + " " + f, full = full_name, gender] # [?, full, gender]
sort full # [?, full, gender]
select [f = first_name, l = last_name, gender] # [f, l, initial_table.gender]
derive full_name = f + " " + l # [f, l, initial_table.gender, full_name]
take 23 # [f, l, initial_table.gender, full_name]
select [l + " " + f, full = full_name, gender] # [?, full, initial_table.gender]
sort full # [?, full, initial_table.gender]
"###);
}

Expand Down
15 changes: 15 additions & 0 deletions prql-compiler/prqlc/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// We put all the code apart from a facade in `lib.rs` so we can easily disable
// its compilation for wasm targets.
//
// We still want to allow compilation for wasm, because we compile the whole
// workspace for wasm in our tests.

#[cfg(not(target_family = "wasm"))]
fn main() -> color_eyre::eyre::Result<()> {
prqlc::main()
}

#[cfg(target_family = "wasm")]
fn main() {
panic!("WASM not supported by `prqlc`. `prql-compiler` is the library.");
}
2 changes: 1 addition & 1 deletion prql-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//! - ... compile, format & debug PRQL from command line.
//!
//! ```sh
//! $ cargo install prql-compiler --features=cli
//! $ cargo install prqlc
//! $ prqlc compile query.prql
//! ```
//!
Expand Down

0 comments on commit acf9b42

Please sign in to comment.