Skip to content

Commit b846795

Browse files
author
Niko Matsakis
committed
factor out jason crate, cargo fmt
1 parent b74e14f commit b846795

File tree

20 files changed

+115
-66
lines changed

20 files changed

+115
-66
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
[workspace]
3-
members = ["crates/mdbook-goals", "crates/rust-project-goals", "crates/rust-project-goals-cli", "crates/rust-project-goals-cli-llm", "crates/rust-project-goals-llm"]
3+
members = ["crates/mdbook-goals", "crates/rust-project-goals", "crates/rust-project-goals-cli", "crates/rust-project-goals-cli-llm", "crates/rust-project-goals-json", "crates/rust-project-goals-llm"]
44
resolver = "2"
55

66
[profile.dev]

crates/mdbook-goals/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct Opt {
1818
enum Command {
1919
/// Command used by mdbook to check if the preprocessor supports a renderer
2020
Supports { renderer: String },
21-
2221
}
2322

2423
fn main() -> anyhow::Result<()> {

crates/mdbook-goals/src/mdbook_preprocessor.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use mdbook::BookItem;
1010
use regex::{Captures, Regex};
1111
use rust_project_goals::util::GithubUserInfo;
1212

13-
use rust_project_goals::{re, team, goal::{self, format_team_asks, GoalDocument, Status, TeamAsk}};
13+
use rust_project_goals::{
14+
goal::{self, format_team_asks, GoalDocument, Status, TeamAsk},
15+
re, team,
16+
};
1417

1518
const LINKS: &str = "links";
1619
const LINKIFIERS: &str = "linkifiers";

crates/rust-project-goals-cli-llm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ serde_json = "1.0.133"
1818
comrak = "0.31.0"
1919
progress_bar = "1.0.6"
2020
tokio = { version = "1.42.0", features = ["full"] }
21+
rust-project-goals-json = { version = "0.1.0", path = "../rust-project-goals-json" }

crates/rust-project-goals-cli-llm/src/llm.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use anyhow::Context;
32
use aws_config::{
43
environment::EnvironmentVariableCredentialsProvider,

crates/rust-project-goals-cli-llm/src/main.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,37 @@ mod updates;
1212
#[derive(clap::Parser, Debug)]
1313
#[structopt(about = "Project goal preprocessor")]
1414
struct Opt {
15-
repository: Repository,
15+
repository: Repository,
1616
updates_json: String,
1717
}
1818

1919
#[tokio::main]
2020
async fn main() -> anyhow::Result<()> {
21-
let Opt { repository, updates_json } = Opt::parse();
22-
let UpdateArgs { milestone, quick, vscode, output_file, start_date, end_date, model_id, region } =
23-
&serde_json::from_str(&updates_json)?;
24-
updates::updates(&repository, milestone, output_file.as_deref(), start_date, end_date, *quick, *vscode, model_id.as_deref(), region.as_deref()).await?;
21+
let Opt {
22+
repository,
23+
updates_json,
24+
} = Opt::parse();
25+
let UpdateArgs {
26+
milestone,
27+
quick,
28+
vscode,
29+
output_file,
30+
start_date,
31+
end_date,
32+
model_id,
33+
region,
34+
} = &serde_json::from_str(&updates_json)?;
35+
updates::updates(
36+
&repository,
37+
milestone,
38+
output_file.as_deref(),
39+
start_date,
40+
end_date,
41+
*quick,
42+
*vscode,
43+
model_id.as_deref(),
44+
region.as_deref(),
45+
)
46+
.await?;
2547
Ok(())
26-
}
48+
}

crates/rust-project-goals-cli-llm/src/templates.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33
use handlebars::{DirectorySourceOptions, Handlebars};
44
use serde::Serialize;
55

6-
use rust_project_goals::json::Progress;
6+
use rust_project_goals_json::Progress;
77

88
pub struct Templates<'h> {
99
reg: Handlebars<'h>,

crates/rust-project-goals-cli-llm/src/updates.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use anyhow::Context;
22
use chrono::{Datelike, NaiveDate};
3-
use rust_project_goals::json::GithubIssueState;
3+
use rust_project_goals::util::comma;
4+
use rust_project_goals_json::GithubIssueState;
45
use std::collections::BTreeMap;
56
use std::io::Write;
67
use std::path::Path;
78
use std::process::{Command, Stdio};
8-
use rust_project_goals::util::comma;
99

10+
use crate::llm::LargeLanguageModel;
11+
use crate::templates::{self, Updates, UpdatesGoal};
12+
use rust_project_goals::gh::issues::ExistingGithubIssue;
1013
use rust_project_goals::gh::{
1114
issue_id::{IssueId, Repository},
12-
issues::{list_issue_titles_in_milestone, ExistingGithubComment, checkboxes},
15+
issues::{checkboxes, list_issue_titles_in_milestone, ExistingGithubComment},
1316
};
14-
use rust_project_goals::gh::issues::ExistingGithubIssue;
15-
use crate::llm::LargeLanguageModel;
16-
use crate::templates::{self, Updates, UpdatesGoal};
1717

1818
const QUICK_UPDATES: &[&str] = &[
1919
"Jack and Jill went up the hill",

crates/rust-project-goals-cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ serde_json = "1.0.133"
1515
chrono = "0.4.39"
1616
progress_bar = "1.0.6"
1717
clap = { version = "4.5.23", features = ["derive"] }
18+
rust-project-goals-json = { version = "0.1.0", path = "../rust-project-goals-json" }

crates/rust-project-goals-cli/src/generate_json.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use std::path::PathBuf;
22

3-
use rust_project_goals::{gh::{issue_id::Repository, issues::{checkboxes, list_issue_titles_in_milestone, ExistingGithubComment}}, json::{ TrackingIssue, TrackingIssueUpdate, TrackingIssues}};
3+
use rust_project_goals::gh::{
4+
issue_id::Repository,
5+
issues::{checkboxes, list_issue_titles_in_milestone, ExistingGithubComment},
6+
};
7+
use rust_project_goals_json::{TrackingIssue, TrackingIssueUpdate, TrackingIssues};
48

59
pub(super) fn generate_json(
610
repository: &Repository,

crates/rust-project-goals-cli/src/main.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use anyhow::{bail, Context};
22
use clap::Parser;
33
use regex::Regex;
4+
use rust_project_goals::gh::issue_id::Repository;
45
use rust_project_goals_llm::UpdateArgs;
56
use std::path::PathBuf;
67
use walkdir::WalkDir;
7-
use rust_project_goals::gh::issue_id::Repository;
88

9-
mod rfc;
109
mod generate_json;
10+
mod rfc;
1111
mod team_repo;
1212

1313
#[derive(clap::Parser, Debug)]
@@ -74,7 +74,7 @@ enum Command {
7474
/// Collects updates
7575
Updates {
7676
#[command(flatten)]
77-
updates: UpdateArgs
77+
updates: UpdateArgs,
7878
},
7979
}
8080

@@ -116,18 +116,18 @@ fn main() -> anyhow::Result<()> {
116116
} => {
117117
generate_json::generate_json(&opt.repository, &milestone, json_path)?;
118118
}
119-
Command::Updates {updates } => {
119+
Command::Updates { updates } => {
120120
// The updates command is compiled separately so that we don't have to
121121
// build all the LLM stuff if we are not using it.
122122
let status = std::process::Command::new("cargo")
123-
.arg("run")
124-
.arg("-p")
125-
.arg("rust-project-goals-cli-llm")
126-
.arg("-q")
127-
.arg("--")
128-
.arg(&opt.repository.to_string())
129-
.arg(&serde_json::to_string(updates).unwrap())
130-
.status()?;
123+
.arg("run")
124+
.arg("-p")
125+
.arg("rust-project-goals-cli-llm")
126+
.arg("-q")
127+
.arg("--")
128+
.arg(&opt.repository.to_string())
129+
.arg(&serde_json::to_string(updates).unwrap())
130+
.status()?;
131131
if !status.success() {
132132
bail!("subcommand failed");
133133
}

crates/rust-project-goals-cli/src/rfc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use regex::Regex;
1212
use rust_project_goals::{
1313
gh::{
1414
issue_id::{IssueId, Repository},
15-
issues::{create_issue, list_issue_titles_in_milestone, lock_issue, sync_assignees, FLAGSHIP_LABEL},
15+
issues::{
16+
create_issue, list_issue_titles_in_milestone, lock_issue, sync_assignees,
17+
FLAGSHIP_LABEL,
18+
},
1619
labels::GhLabel,
1720
},
1821
goal::{self, GoalDocument, ParsedOwners, PlanItem, Status},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "rust-project-goals-json"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
serde = { version = "1.0.216", features = ["derive"] }

crates/rust-project-goals/src/json.rs renamed to crates/rust-project-goals-json/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! Generate JSON summarizing the tracking issues.
2-
//!
31
//! This module contains types (e.g., [`TrackingIssues`]) that represent the
42
//! external API that is used by the website
53
//! and other tools to consume the tracking issue data. They are very similar

crates/rust-project-goals-llm/src/lib.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@
33
44
use std::path::PathBuf;
55

6-
use serde::{Serialize, Deserialize};
6+
use serde::{Deserialize, Serialize};
77

88
/// Updates struct
99
#[derive(clap::Args, Debug, Serialize, Deserialize)]
1010
pub struct UpdateArgs {
11-
/// Milestone for which we generate tracking issue data (e.g., `2024h2`).
12-
pub milestone: String,
11+
/// Milestone for which we generate tracking issue data (e.g., `2024h2`).
12+
pub milestone: String,
1313

14-
/// Quick mode does not use an LLM to generate a summary.
15-
#[arg(long)]
16-
pub quick: bool,
14+
/// Quick mode does not use an LLM to generate a summary.
15+
#[arg(long)]
16+
pub quick: bool,
1717

18-
/// Quick mode does not use an LLM to generate a summary.
19-
#[arg(long)]
20-
pub vscode: bool,
18+
/// Quick mode does not use an LLM to generate a summary.
19+
#[arg(long)]
20+
pub vscode: bool,
2121

22-
/// If specified, write the output into the given file.
23-
#[arg(long)]
24-
pub output_file: Option<PathBuf>,
22+
/// If specified, write the output into the given file.
23+
#[arg(long)]
24+
pub output_file: Option<PathBuf>,
2525

26-
/// Start date for comments.
27-
/// If not given, defaults to 1 week before the start of this month.
28-
pub start_date: Option<chrono::NaiveDate>,
26+
/// Start date for comments.
27+
/// If not given, defaults to 1 week before the start of this month.
28+
pub start_date: Option<chrono::NaiveDate>,
2929

30-
/// End date for comments.
31-
/// If not given, no end date.
32-
pub end_date: Option<chrono::NaiveDate>,
30+
/// End date for comments.
31+
/// If not given, no end date.
32+
pub end_date: Option<chrono::NaiveDate>,
3333

34-
/// Set a custom model id for the LLM.
35-
#[arg(long)]
36-
pub model_id: Option<String>,
34+
/// Set a custom model id for the LLM.
35+
#[arg(long)]
36+
pub model_id: Option<String>,
3737

38-
/// Set a custom region.
39-
#[arg(long)]
40-
pub region: Option<String>,
41-
}
38+
/// Set a custom region.
39+
#[arg(long)]
40+
pub region: Option<String>,
41+
}

crates/rust-project-goals/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ serde = "1.0.216"
1414
serde_json = "1.0.133"
1515
walkdir = "2.5.0"
1616
rust_team_data = { git = "https://github.com/rust-lang/team" }
17+
rust-project-goals-json = { version = "0.1.0", path = "../rust-project-goals-json" }

crates/rust-project-goals/src/gh/issues.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::{
22
collections::{BTreeMap, BTreeSet},
3-
process::Command, str::FromStr,
3+
process::Command,
4+
str::FromStr,
45
};
56

67
use anyhow::Context;
78
use chrono::NaiveDate;
9+
use rust_project_goals_json::{GithubIssueState, Progress};
810
use serde::{Deserialize, Serialize};
911

10-
use crate::{json::{GithubIssueState, Progress}, re, util::comma};
12+
use crate::{re, util::comma};
1113

1214
use super::{issue_id::Repository, labels::GhLabel};
1315

crates/rust-project-goals/src/goal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use anyhow::Context;
77
use regex::Regex;
88

99
use crate::gh::issue_id::{IssueId, Repository};
10+
use crate::markwaydown::{self, Section, Table};
1011
use crate::re::USERNAME;
1112
use crate::team::{self, TeamName};
1213
use crate::util::{self, commas, markdown_files, ARROW};
13-
use crate::markwaydown::{self, Section, Table};
1414

1515
/// Data parsed from a goal file in the expected format
1616
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
@@ -231,7 +231,7 @@ pub fn format_team_asks(asks_of_any_team: &[&TeamAsk]) -> anyhow::Result<String>
231231
pub fn format_goal_table(goals: &[&GoalDocument]) -> anyhow::Result<String> {
232232
// If any of the goals have tracking issues, include those in the table.
233233
let goals_are_proposed = goals.iter().any(|g| g.metadata.status == Status::Proposed);
234-
234+
235235
let mut table;
236236

237237
if !goals_are_proposed {

crates/rust-project-goals/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
pub mod util;
2-
pub mod markwaydown;
31
pub mod gh;
4-
pub mod json;
2+
pub mod goal;
3+
pub mod markwaydown;
54
pub mod re;
65
pub mod team;
7-
pub mod goal;
6+
pub mod util;

0 commit comments

Comments
 (0)