Skip to content

Commit

Permalink
chore: use taplo to format Cargo.toml manifests (apache#9263)
Browse files Browse the repository at this point in the history
* add taplo.toml configuration

Signed-off-by: Ruihang Xia <[email protected]>

* run taplo format

Signed-off-by: Ruihang Xia <[email protected]>

* update CI and script

Signed-off-by: Ruihang Xia <[email protected]>

* update doc

Signed-off-by: Ruihang Xia <[email protected]>

* add license header

Signed-off-by: Ruihang Xia <[email protected]>

* Revert "run taplo format"

This reverts commit 1819daa.

* skip reorder package table

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Feb 20, 2024
1 parent 779689a commit cf92f3b
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 25 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,11 @@ jobs:
uses: ./.github/actions/setup-builder
with:
rust-version: stable
- name: Install cargo-tomlfmt
run: which cargo-tomlfmt || cargo install cargo-tomlfmt

- name: Install taplo
run: cargo +stable install taplo-cli --version ^0.9 --locked
# if you encounter an error, try running 'taplo format' to fix the formatting automatically.
- name: Check Cargo.toml formatting
run: |
# if you encounter an error, try running 'cargo tomlfmt -p path/to/Cargo.toml' to fix the formatting automatically.
# If the error still persists, you need to manually edit the Cargo.toml file, which introduces formatting violation.
#
# ignore ./Cargo.toml because putting workspaces in multi-line lists make it easy to read
ci/scripts/rust_toml_fmt.sh
run: taplo format --check

config-docs-check:
name: check configs.md is up-to-date
Expand Down
21 changes: 20 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,26 @@

[workspace]
exclude = ["datafusion-cli"]
members = ["datafusion/common", "datafusion/core", "datafusion/expr", "datafusion/execution", "datafusion/functions", "datafusion/functions-array", "datafusion/optimizer", "datafusion/physical-expr", "datafusion/physical-plan", "datafusion/proto", "datafusion/proto/gen", "datafusion/sql", "datafusion/sqllogictest", "datafusion/substrait", "datafusion/wasmtest", "datafusion-examples", "docs", "test-utils", "benchmarks",
members = [
"datafusion/common",
"datafusion/core",
"datafusion/expr",
"datafusion/execution",
"datafusion/functions",
"datafusion/functions-array",
"datafusion/optimizer",
"datafusion/physical-expr",
"datafusion/physical-plan",
"datafusion/proto",
"datafusion/proto/gen",
"datafusion/sql",
"datafusion/sqllogictest",
"datafusion/substrait",
"datafusion/wasmtest",
"datafusion-examples",
"docs",
"test-utils",
"benchmarks",
]
resolver = "2"

Expand Down
8 changes: 3 additions & 5 deletions ci/scripts/rust_toml_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
# specific language governing permissions and limitations
# under the License.

# Run cargo-tomlfmt with flag `-d` in dry run to check formatting
# Run `taplo format` with flag `--check` in dry run to check formatting
# without overwritng the file. If any error occur, you may want to
# rerun 'cargo tomlfmt -p path/to/Cargo.toml' without '-d' to fix
# the formatting automatically.
# rerun `taplo format` to fix the formatting automatically.
set -ex
for toml in $(find . -mindepth 2 -name 'Cargo.toml'); do
cargo tomlfmt -d -p $toml
taplo format
done
10 changes: 9 additions & 1 deletion datafusion-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ async-trait = "0.1.41"
aws-config = "0.55"
aws-credential-types = "0.55"
clap = { version = "3", features = ["derive", "cargo"] }
datafusion = { path = "../datafusion/core", version = "36.0.0", features = ["avro", "crypto_expressions", "encoding_expressions", "parquet", "regex_expressions", "unicode_expressions", "compression"] }
datafusion = { path = "../datafusion/core", version = "36.0.0", features = [
"avro",
"crypto_expressions",
"encoding_expressions",
"parquet",
"regex_expressions",
"unicode_expressions",
"compression",
] }
datafusion-common = { path = "../datafusion/common" }
dirs = "4.0.0"
env_logger = "0.9"
Expand Down
25 changes: 22 additions & 3 deletions datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ avro = ["apache-avro", "num-traits", "datafusion-common/avro"]
backtrace = ["datafusion-common/backtrace"]
compression = ["xz2", "bzip2", "flate2", "zstd", "async-compression", "tokio-util"]
crypto_expressions = ["datafusion-physical-expr/crypto_expressions", "datafusion-optimizer/crypto_expressions"]
default = ["array_expressions", "crypto_expressions", "encoding_expressions", "regex_expressions", "unicode_expressions", "compression", "parquet"]
default = [
"array_expressions",
"crypto_expressions",
"encoding_expressions",
"regex_expressions",
"unicode_expressions",
"compression",
"parquet",
]
encoding_expressions = ["datafusion-functions/encoding_expressions"]
# Used for testing ONLY: causes all values to hash to the same value (test for collisions)
force_hash_collisions = []
Expand All @@ -52,7 +60,11 @@ parquet = ["datafusion-common/parquet", "dep:parquet"]
pyarrow = ["datafusion-common/pyarrow", "parquet"]
regex_expressions = ["datafusion-physical-expr/regex_expressions", "datafusion-optimizer/regex_expressions"]
serde = ["arrow-schema/serde"]
unicode_expressions = ["datafusion-physical-expr/unicode_expressions", "datafusion-optimizer/unicode_expressions", "datafusion-sql/unicode_expressions"]
unicode_expressions = [
"datafusion-physical-expr/unicode_expressions",
"datafusion-optimizer/unicode_expressions",
"datafusion-sql/unicode_expressions",
]

[dependencies]
ahash = { version = "0.8", default-features = false, features = ["runtime-rng"] }
Expand All @@ -61,7 +73,14 @@ arrow = { workspace = true }
arrow-array = { workspace = true }
arrow-ipc = { workspace = true }
arrow-schema = { workspace = true }
async-compression = { version = "0.4.0", features = ["bzip2", "gzip", "xz", "zstd", "futures-io", "tokio"], optional = true }
async-compression = { version = "0.4.0", features = [
"bzip2",
"gzip",
"xz",
"zstd",
"futures-io",
"tokio",
], optional = true }
async-trait = { workspace = true }
bytes = { workspace = true }
bzip2 = { version = "0.4.3", optional = true }
Expand Down
1 change: 0 additions & 1 deletion datafusion/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ encoding_expressions = ["base64", "hex"]
# enable math functions
math_expressions = []


[lib]
name = "datafusion_functions"
path = "src/lib.rs"
Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[package]
name = "datafusion-optimizer"
description = "DataFusion Query Optimizer"
keywords = [ "datafusion", "query", "optimizer" ]
keywords = ["datafusion", "query", "optimizer"]
readme = "README.md"
version = { workspace = true }
edition = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion datafusion/physical-expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ path = "src/lib.rs"

[features]
crypto_expressions = ["md-5", "sha2", "blake2", "blake3"]
default = ["crypto_expressions", "regex_expressions", "unicode_expressions", "encoding_expressions",
default = [
"crypto_expressions",
"regex_expressions",
"unicode_expressions",
"encoding_expressions",
]
encoding_expressions = ["base64", "hex"]
regex_expressions = ["regex"]
Expand Down
6 changes: 3 additions & 3 deletions dev/rust_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# DataFusion CI does

set -e
if ! command -v cargo-tomlfmt &> /dev/null; then
echo "Installing cargo-tomlfmt using cargo"
cargo install cargo-tomlfmt
if ! command -v taplo &> /dev/null; then
echo "Installing taplo using cargo"
cargo install taplo-cli
fi

ci/scripts/rust_fmt.sh
Expand Down
62 changes: 62 additions & 0 deletions taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

## https://taplo.tamasfe.dev/configuration/file.html

include = ["**/Cargo.toml"]

[formatting]
# Align consecutive entries vertically.
align_entries = false
# Append trailing commas for multi-line arrays.
array_trailing_comma = true
# Expand arrays to multiple lines that exceed the maximum column width.
array_auto_expand = true
# Collapse arrays that don't exceed the maximum column width and don't contain comments.
array_auto_collapse = false
# Omit white space padding from single-line arrays
compact_arrays = true
# Omit white space padding from the start and end of inline tables.
compact_inline_tables = false
# Maximum column width in characters, affects array expansion and collapse, this doesn't take whitespace into account.
# Note that this is not set in stone, and works on a best-effort basis.
column_width = 120
# Indent based on tables and arrays of tables and their subtables, subtables out of order are not indented.
indent_tables = false
# The substring that is used for indentation, should be tabs or spaces (but technically can be anything).
indent_string = ' '
# Add trailing newline at the end of the file if not present.
trailing_newline = true
# Alphabetically reorder keys that are not separated by empty lines.
reorder_keys = false
# Maximum amount of allowed consecutive blank lines. This does not affect the whitespace at the end of the document, as it is always stripped.
allowed_blank_lines = 1
# Use CRLF for line endings.
crlf = false

[[rule]]
keys = [
"build-dependencies",
"dependencies",
"dev-dependencies",
"workspace.dependencies",
]
formatting = { reorder_keys = true }

[[rule]]
keys = ["package"]
formatting = { reorder_keys = false }

0 comments on commit cf92f3b

Please sign in to comment.