Skip to content

Commit

Permalink
Distinguish library and CLI log messages (#666)
Browse files Browse the repository at this point in the history
* filter log messages from the library separately

* Revert "filter log messages from the library separately"

This reverts commit 23a8ddd.

See discussion at #666 (review)

* Rename library to "topiary-core", to distinguish log output

Also moved to short-form directory structure to make it easier (for lazy
people such as myself) to navigate ;)

Resolves #604

* Fix tests (mostly ../queries -> ../queries/queries)

Also pinned to tree-sitter-bash 1b0321ee; looks like it's moved on in
the last few months and our queries don't work with the latest version

* Stragglers...

* Update to toml 0.8

* Fix Nix stuff

* Correct symlink to languages.toml

* More stragglers

* Revert to `topiary-*` top-level directories

* Fix formatting

* Fix issues introduced by merge

---------

Co-authored-by: Christopher Harrison <christopher.harrison@tweag.io>
  • Loading branch information
evertedsphere and Xophmeister authored Jan 29, 2024
1 parent a30cd32 commit 3eaf0c5
Show file tree
Hide file tree
Showing 37 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Hide our tests from language detection so GitHub correctly detects Topiary as a Rust project
topiary/tests/samples/** linguist-vendored
topiary-core/tests/samples/** linguist-vendored
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you do `cargo install flamegraph`, you can generate a performance flamegraph
like this:

```bash
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph -- -l ocaml < topiary/tests/samples/input/ocaml.ml > formatted.ml
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph -- -l ocaml < topiary-cli/tests/samples/input/ocaml.ml > formatted.ml
```

## Code Coverage
Expand Down
56 changes: 28 additions & 28 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ readme = "README.md"
license = "MIT"

[workspace]
members = ["topiary", "topiary-cli", "topiary-queries", "topiary-playground", "topiary-config", "topiary-web-tree-sitter-sys", "topiary-tree-sitter-facade"]
default-members = [ "topiary", "topiary-cli" ]
members = ["topiary-core", "topiary-cli", "topiary-queries", "topiary-playground", "topiary-config", "topiary-web-tree-sitter-sys", "topiary-tree-sitter-facade"]
default-members = [ "topiary-core", "topiary-cli" ]
exclude = ["samples"]
resolver = "2"

Expand Down Expand Up @@ -59,7 +59,7 @@ tempfile = "3.5"
test-log = "0.2"
tokio = "1.32"
tokio-test = "0.4"
toml = "0.7"
toml = "0.8"
tree-sitter = "0.20"
tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "1b0321ee85701d5036c334a6f04761cdc672e64c" }
tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json.git" }
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Topiary's language query files (`.scm`) are located**. By default, you should
set it to `<local path of the topiary repository>/queries`, for example:

```sh
export TOPIARY_LANGUAGE_DIR=/home/me/tools/topiary/queries
export TOPIARY_LANGUAGE_DIR=/home/me/tools/topiary/topiary-queries/queries
topiary fmt ./projects/helloworld/hello.ml
```

Expand Down Expand Up @@ -1324,9 +1324,9 @@ containing the matched nodes are is single-line (resp. multi-line).
In order to work productively on query files, the following is one
suggested way to work:

1. Add a sample file to `topiary/tests/samples/input`.
1. Add a sample file to `topiary-cli/tests/samples/input`.

2. Copy the same file to `topiary/tests/samples/expected`, and make any changes
2. Copy the same file to `topiary-cli/tests/samples/expected`, and make any changes
to how you want the output to be formatted.

3. If this is a new language, add its Tree-sitter grammar, extend
Expand All @@ -1337,7 +1337,7 @@ suggested way to work:

```
RUST_LOG=debug \
cargo test -p topiary \
cargo test -p topiary-cli \
input_output_tester \
-- --nocapture
```
Expand Down
13 changes: 6 additions & 7 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ let
"Cargo.lock"
"Cargo.toml"
"languages.toml"
"queries"
"tests"
"topiary"
"topiary-core"
"topiary-cli"
"topiary-config"
"topiary-playground"
Expand Down Expand Up @@ -84,11 +83,11 @@ in
cargoTestCommand = "cargo bench --profile release";
});

topiary-lib = craneLib.buildPackage (commonArgs
topiary-core = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
pname = "topiary-lib";
cargoExtraArgs = "-p topiary";
pname = "topiary-core";
cargoExtraArgs = "-p topiary-core";
});

topiary-cli = craneLib.buildPackage (commonArgs
Expand All @@ -97,7 +96,7 @@ in
pname = "topiary";
cargoExtraArgs = "-p topiary-cli";
postInstall = ''
install -Dm444 queries/* -t $out/share/queries
install -Dm444 topiary-queries/queries/* -t $out/share/queries
'';

# Set TOPIARY_LANGUAGE_DIR to the Nix store
Expand All @@ -116,7 +115,7 @@ in
pname = "topiary-queries";
cargoExtraArgs = "-p topiary-queries";
postInstall = ''
install -Dm444 queries/* -t $out/share/queries
install -Dm444 topiary-queries/queries/* -t $out/share/queries
'';
});

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
};

checks = {
inherit (code) clippy clippy-wasm fmt topiary-lib topiary-cli topiary-playground audit benchmark;
inherit (code) clippy clippy-wasm fmt topiary-core topiary-cli topiary-playground audit benchmark;

## Check that the `lib.pre-commit-hook` output builds/evaluates
## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before
Expand Down
2 changes: 1 addition & 1 deletion languages.toml
2 changes: 1 addition & 1 deletion playground.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ get_sample_input() {
local language="$1"

# Only return the first result, presuming there is one
find topiary/tests/samples/input -name "${language}.*" \
find topiary-core/tests/samples/input -name "${language}.*" \
| head -1
}

Expand Down
1 change: 0 additions & 1 deletion queries

This file was deleted.

2 changes: 1 addition & 1 deletion samples/client-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ edition = "2021"

[dependencies]
tokio = { version = "^1.28.1", features = ["rt-multi-thread", "macros"] }
topiary = { path = "../../topiary" }
topiary = { path = "../../topiary-core" }
5 changes: 3 additions & 2 deletions samples/client-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use topiary::{formatter, Configuration, Operation, TopiaryQuery};
use topiary_core::{formatter, Configuration, Operation, TopiaryQuery};

#[tokio::main]
async fn main() {
let mut input =
"{\"name\":\"John Doe\",\"age\":43,\n\"phones\":[\"+44 1234567\",\"+44 2345678\"]}".as_bytes();
"{\"name\":\"John Doe\",\"age\":43,\n\"phones\":[\"+44 1234567\",\"+44 2345678\"]}"
.as_bytes();

let mut output = Vec::new();
let query = TopiaryQuery::json();
Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ serde = { workspace = true, features = ["derive"] }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "sync", "macros"] }
toml = { workspace = true }
topiary = { path = "../topiary" }
topiary-core = { path = "../topiary-core" }
topiary-config = { path = "../topiary-config" }
topiary-queries = { path = "../topiary-queries" }
topiary-tree-sitter-facade = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{error, fmt, io, path::PathBuf, process::ExitCode, result};
use topiary::FormatterError;
use topiary_config::error::TopiaryConfigError;
use topiary_core::FormatterError;

/// A convenience wrapper around `std::result::Result<T, TopiaryError>`.
pub type CLIResult<T> = result::Result<T, TopiaryError>;
Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::{
};

use tempfile::NamedTempFile;
use topiary::{Language, TopiaryQuery};
use topiary_config::Configuration;
use topiary_core::{Language, TopiaryQuery};

use crate::{
cli::{AtLeastOneInput, ExactlyOneInput, FromStdin},
Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use tokio::sync::Mutex;
use topiary::Language;
use topiary_core::Language;

use crate::{error::CLIResult, io::InputFile};

Expand Down
2 changes: 1 addition & 1 deletion topiary-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
process::ExitCode,
};

use topiary::{formatter, Operation};
use topiary_core::{formatter, Operation};

use crate::{
cli::Commands,
Expand Down
6 changes: 3 additions & 3 deletions topiary-cli/src/visualisation.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use clap::ValueEnum;
use topiary::Visualisation;
use topiary_core::Visualisation;

/// Visualisation output formats for Tree-sitter parse trees
// NOTE While redundant, we cannot implement clap::ValueEnum for topiary::Visualisation without
// breaking the orphan rules. So we have to maintain a local copy for the sake of the CLI.
// NOTE While redundant, we cannot implement clap::ValueEnum for topiary_core::Visualisation
// without breaking the orphan rules. So we have to maintain a local copy for the sake of the CLI.
#[derive(Clone, Debug, ValueEnum)]
pub enum Format {
/// GraphViz DOT serialisation
Expand Down
Loading

0 comments on commit 3eaf0c5

Please sign in to comment.