Skip to content

Commit

Permalink
chore: forbid wildcard imports + additional rustfmt (#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
tychoish committed Feb 1, 2024
1 parent 06343ff commit b29f59b
Show file tree
Hide file tree
Showing 298 changed files with 3,001 additions and 1,734 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: just build

static-analysis:
name: Lint and Format
name: Lint (clippy)
runs-on: ubuntu-latest-8-cores
needs: ["build"]
steps:
Expand All @@ -74,8 +74,25 @@ jobs:
- name: clippy
run: just clippy

- name: format
run: just fmt-check
fmt:
name: Format (rustfmt +nightly)
runs-on: ubuntu-latest-8-cores
needs: ["build"]
steps:
- name: checkout
uses: actions/checkout@v4
- uses: extractions/setup-just@v1
with:
just-version: "1.23.0"
- uses: actions/cache@v3
name: nightly toolchain cache
with:
path: |
~/.rustup/toolchains/
key: ${{ runner.os }}-toolchain-${{ hashFiles('**/rustfmt.toml') }}
- run: rustup install nightly
- run: rustup component add rustfmt --toolchain nightly
- run: just fmt-check

unit-tests:
name: Unit Tests
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ opt-level = 3
codegen-units = 1
strip = true

[workspace.lints.clippy]
wildcard_imports = "deny"

[workspace.dependencies]
clap = { version = "4.4.18", features = ["derive"] }
datafusion = { version = "34.0", features = ["avro"] }
Expand Down
3 changes: 3 additions & 0 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ version = "0.0.0"
[lib]
crate-type = ["cdylib"]

[lints]
workspace = true

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
ioutil = { path = "../../crates/ioutil" }
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! User's will call `connect` which returns a session for executing sql
//! queries.

use crate::connection::Connection;

use std::collections::HashMap;

use crate::connection::Connection;

#[napi(object)]
#[derive(Default)]
pub struct ConnectOptions {
Expand Down
12 changes: 7 additions & 5 deletions bindings/nodejs/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::error::JsGlareDbError;
use crate::logical_plan::JsLogicalPlan;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;

use datafusion::logical_expr::LogicalPlan as DFLogicalPlan;
use datafusion_ext::vars::SessionVars;
use futures::lock::Mutex;
use ioutil::ensure_dir;
use sqlexec::engine::{Engine, SessionStorageConfig, TrackedSession};
use sqlexec::remote::client::{RemoteClient, RemoteClientType};
use sqlexec::{LogicalPlan, OperationInfo};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use url::Url;

use crate::error::JsGlareDbError;
use crate::logical_plan::JsLogicalPlan;

pub(super) type JsTrackedSession = Arc<Mutex<TrackedSession>>;

/// A connected session to a GlareDB database.
Expand Down
2 changes: 0 additions & 2 deletions bindings/nodejs/src/execution_result.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use arrow_util::pretty;

use datafusion::arrow::ipc::writer::FileWriter;
use datafusion::arrow::record_batch::RecordBatch;
use futures::StreamExt;

use sqlexec::session::ExecutionResult;

use crate::error::JsGlareDbError;
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/src/logical_plan.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use sqlexec::{LogicalPlan, OperationInfo};

use crate::{
connection::JsTrackedSession, error::JsGlareDbError, execution_result::JsExecutionResult,
};
use crate::connection::JsTrackedSession;
use crate::error::JsGlareDbError;
use crate::execution_result::JsExecutionResult;

#[napi]
#[derive(Clone, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ name = "py-glaredb"
version.workspace = true
edition = "2021"

[lints]
workspace = true

# [workspace]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "glaredb"
crate-type = ["cdylib"]
Expand Down
23 changes: 11 additions & 12 deletions bindings/python/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
//! User's will call `connect` which returns a session for executing sql
//! queries.

use crate::connection::Connection;
use crate::environment::PyEnvironmentReader;
use crate::error::PyGlareDbError;
use crate::runtime::wait_for_future;
use futures::lock::Mutex;
use std::collections::HashMap;
use std::{path::PathBuf, sync::Arc};
use url::Url;
use std::path::PathBuf;
use std::sync::Arc;

use datafusion_ext::vars::SessionVars;
use futures::lock::Mutex;
use ioutil::ensure_dir;
use pyo3::prelude::*;
use sqlexec::{
engine::{Engine, SessionStorageConfig},
remote::client::{RemoteClient, RemoteClientType},
};
use sqlexec::engine::{Engine, SessionStorageConfig};
use sqlexec::remote::client::{RemoteClient, RemoteClientType};
use url::Url;

use ioutil::ensure_dir;
use crate::connection::Connection;
use crate::environment::PyEnvironmentReader;
use crate::error::PyGlareDbError;
use crate::runtime::wait_for_future;

#[derive(Debug, Clone)]
struct PythonSessionConf {
Expand Down
13 changes: 9 additions & 4 deletions bindings/python/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use crate::execution_result::PyExecutionResult;
use std::sync::Arc;

use datafusion::logical_expr::LogicalPlan as DFLogicalPlan;
use datafusion_ext::vars::SessionVars;
use futures::lock::Mutex;
use once_cell::sync::OnceCell;
use pyo3::{prelude::*, types::PyType};
use pyo3::prelude::*;
use pyo3::types::PyType;
use sqlexec::engine::{Engine, SessionStorageConfig, TrackedSession};
use sqlexec::{LogicalPlan, OperationInfo};
use std::sync::Arc;

use crate::execution_result::PyExecutionResult;

pub(super) type PyTrackedSession = Arc<Mutex<TrackedSession>>;

use crate::{error::PyGlareDbError, logical_plan::PyLogicalPlan, runtime::wait_for_future};
use crate::error::PyGlareDbError;
use crate::logical_plan::PyLogicalPlan;
use crate::runtime::wait_for_future;

/// A connected session to a GlareDB database.
#[pyclass]
Expand Down
16 changes: 7 additions & 9 deletions bindings/python/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use datafusion::datasource::MemTable;
use datafusion::{
arrow::{pyarrow::PyArrowType, record_batch::RecordBatch},
datasource::TableProvider,
};
use pyo3::types::IntoPyDict;
use pyo3::types::PyTuple;
use pyo3::{prelude::*, types::PyType};
use sqlexec::environment::EnvironmentReader;
use std::sync::Arc;

use datafusion::arrow::pyarrow::PyArrowType;
use datafusion::arrow::record_batch::RecordBatch;
use datafusion::datasource::{MemTable, TableProvider};
use pyo3::prelude::*;
use pyo3::types::{IntoPyDict, PyTuple, PyType};
use sqlexec::environment::EnvironmentReader;

use crate::logical_plan::PyLogicalPlan;

/// Read polars dataframes from the python environment.
Expand Down
7 changes: 2 additions & 5 deletions bindings/python/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ use std::fmt::Display;

use datafusion::arrow::error::ArrowError;
use metastore::errors::MetastoreError;
use pyo3::create_exception;
use pyo3::{
exceptions::{PyException, PyRuntimeError},
PyErr,
};
use pyo3::exceptions::{PyException, PyRuntimeError};
use pyo3::{create_exception, PyErr};
use sqlexec::errors::ExecError;

#[derive(Debug, thiserror::Error)]
Expand Down
9 changes: 6 additions & 3 deletions bindings/python/src/execution_result.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use crate::util::pyprint;
use std::sync::Arc;

use anyhow::Result;
use arrow_util::pretty;
use datafusion::arrow::datatypes::Schema;
use datafusion::arrow::pyarrow::ToPyArrow;
use datafusion::arrow::record_batch::RecordBatch;
use futures::StreamExt;
use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyTuple};
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::PyTuple;
use sqlexec::session::ExecutionResult;
use std::sync::Arc;

use crate::runtime::wait_for_future;
use crate::util::pyprint;

/// The result of an executed query.
#[pyclass]
Expand Down
3 changes: 2 additions & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ mod logical_plan;
mod runtime;
mod util;

use std::sync::atomic::{AtomicU64, Ordering};

use connection::Connection;
use execution_result::PyExecutionResult;
use logical_plan::PyLogicalPlan;
use pyo3::prelude::*;
use runtime::TokioRuntime;
use std::sync::atomic::{AtomicU64, Ordering};
use tokio::runtime::Builder;

/// A Python module implemented in Rust.
Expand Down
29 changes: 14 additions & 15 deletions bindings/python/src/logical_plan.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use std::{any::Any, sync::Arc};

use datafusion::{
arrow::datatypes::SchemaRef,
datasource::TableProvider,
execution::context::SessionState,
logical_expr::{LogicalPlanBuilder, TableProviderFilterPushDown, TableType},
physical_plan::ExecutionPlan,
prelude::Expr,
};
use std::any::Any;
use std::sync::Arc;

use datafusion::arrow::datatypes::SchemaRef;
use datafusion::datasource::TableProvider;
use datafusion::error::Result as DatafusionResult;
use datafusion::execution::context::SessionState;
use datafusion::logical_expr::{LogicalPlanBuilder, TableProviderFilterPushDown, TableType};
use datafusion::physical_plan::ExecutionPlan;
use datafusion::prelude::Expr;
use pyo3::prelude::*;
use sqlexec::{LogicalPlan, OperationInfo};

use crate::{
connection::PyTrackedSession, error::PyGlareDbError, execution_result::PyExecutionResult,
runtime::wait_for_future,
};
use datafusion::error::Result as DatafusionResult;
use crate::connection::PyTrackedSession;
use crate::error::PyGlareDbError;
use crate::execution_result::PyExecutionResult;
use crate::runtime::wait_for_future;

#[pyclass]
#[derive(Clone, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion bindings/python/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::future::Future;

use pyo3::{prelude::*, PyRef, Python};
use pyo3::prelude::*;
use pyo3::{PyRef, Python};
use tokio::runtime::Runtime;

#[pyclass]
Expand Down
3 changes: 2 additions & 1 deletion bindings/python/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use pyo3::prelude::*;
use pyo3::types::PyDict;
use std::fmt::Display;

/// Use python's builtin `print` to display an item.
pub fn pyprint(item: impl Display, py: Python) -> PyResult<()> {
Expand Down
3 changes: 2 additions & 1 deletion crates/arrow_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "arrow_util"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
datafusion = { workspace = true }
Expand Down
10 changes: 6 additions & 4 deletions crates/arrow_util/src/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::fmt;
use std::ops::Range;
use std::sync::Arc;

use comfy_table::{Cell, CellAlignment, ColumnConstraint, ContentArrangement, Table};
use datafusion::arrow::array::{Array, Float64Array};
use datafusion::arrow::datatypes::{DataType, Field, Schema, TimeUnit};
use datafusion::arrow::error::ArrowError;
use datafusion::arrow::record_batch::RecordBatch;
use datafusion::arrow::util::display::{ArrayFormatter, FormatOptions};
use once_cell::sync::Lazy;
use std::fmt;
use std::ops::Range;
use std::sync::Arc;
use textwrap::{core::display_width, fill_inplace, wrap};
use textwrap::core::display_width;
use textwrap::{fill_inplace, wrap};

const DEFAULT_PRESET: &str = "││──╞═╪╡│ ┬┴┌┐└┘";
const DEFAULT_MAX_ROWS: usize = 20;
Expand Down
3 changes: 2 additions & 1 deletion crates/bench_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "bench_runner"
version = { workspace = true }
edition = { workspace = true }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
logutil = {path = "../logutil"}
Expand Down
7 changes: 4 additions & 3 deletions crates/bench_runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::{Duration, SystemTime};

use anyhow::Result;
use clap::Parser;
use glaredb::server::ComputeServer;
use glob::glob;
use pgsrv::auth::SingleUserAuthenticator;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::{Duration, SystemTime};
use tokio::net::TcpListener;
use tokio::runtime::Builder;
use tokio::sync::oneshot;
Expand Down
3 changes: 2 additions & 1 deletion crates/bytesutil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "bytesutil"
version = {workspace = true}
edition = {workspace = true}

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
bytes = "1.4.0"
Loading

0 comments on commit b29f59b

Please sign in to comment.