Skip to content

Commit 21fa269

Browse files
authored
[rust/rqd] Add clippy check to rust project (#1767)
Clippy provides additional safety checks to rust projects and having it as part of the CICD is a good practice. All suggestions have been applied
1 parent d98b879 commit 21fa269

File tree

23 files changed

+713
-432
lines changed

23 files changed

+713
-432
lines changed

.github/workflows/rust.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@ jobs:
2828
run: |
2929
cd rust
3030
cargo test --verbose
31+
32+
clippy:
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Install X11 dev libs
38+
run: |
39+
sudo apt-get update && sudo apt-get install -y libx11-dev
40+
- name: Install Protoc
41+
uses: arduino/setup-protoc@v3
42+
- name: Run Clippy
43+
run: |
44+
cd rust
45+
cargo clippy --verbose

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ cuebot/.project
2626
/proto/opencue_proto/
2727
/pycue/opencue/compiled_proto/
2828
/rqd/rqd/compiled_proto/
29+
docker-compose-local.yml

rust/crates/dummy-cuebot/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ impl DummyCuebotCli {
100100
pub async fn run(&self) -> Result<()> {
101101
match &self.subcommands {
102102
SubCommands::ReportServer(report_server_cmd) => {
103-
DummyCuebotServer::start_server(report_server_cmd.port.clone()).await
103+
DummyCuebotServer::start_server(report_server_cmd.port).await
104104
}
105105
SubCommands::RqdClient(cmd) => {
106106
let client = DummyRqdClient::build(cmd.hostname.clone(), cmd.port).await?;
107107
match &cmd.api_method {
108108
ApiMethod::LaunchFrame(cmd) => {
109-
let uid = cmd.run_as_user.then(|| users::get_current_uid());
109+
let uid = cmd.run_as_user.then(users::get_current_uid);
110110
client
111111
.launch_frame(
112112
cmd.cmd.clone(),

rust/crates/dummy-cuebot/src/rqd_client.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ impl DummyRqdClient {
5252
attributes: HashMap::new(),
5353
num_gpus: 0,
5454
children: None,
55-
uid_optional: match uid {
56-
Some(uid) => Some(UidOptional::Uid(uid as i32)),
57-
None => None,
58-
},
55+
uid_optional: uid.map(|uid| UidOptional::Uid(uid as i32)),
5956
os: "macos".to_string(),
6057
soft_memory_limit: 0,
6158
hard_memory_limit: 0,
@@ -76,8 +73,9 @@ impl DummyRqdClient {
7673
};
7774

7875
let mut client = self.client.lock().await;
79-
let mut request = pb::RqdStaticLaunchFrameRequest::default();
80-
request.run_frame = Some(run_frame);
76+
let request = pb::RqdStaticLaunchFrameRequest {
77+
run_frame: Some(run_frame),
78+
};
8179
client
8280
.launch_frame(request)
8381
.await
@@ -87,8 +85,10 @@ impl DummyRqdClient {
8785

8886
pub async fn kill_frame(&self, frame_id: String, reason: Option<String>) -> Result<()> {
8987
let mut client = self.client.lock().await;
90-
let mut request = pb::RqdStaticKillRunningFrameRequest::default();
91-
request.frame_id = frame_id;
88+
let mut request = pb::RqdStaticKillRunningFrameRequest {
89+
frame_id,
90+
..Default::default()
91+
};
9292
request.message = reason.unwrap_or("No reason".to_string());
9393
client
9494
.kill_running_frame(request)

rust/crates/opencue-proto/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn build_protobuf() -> Result<(), Box<dyn std::error::Error>> {
1111

1212
let subdir_proto_files: Vec<String> = std::fs::read_dir(&protos_dir)?
1313
.map(|dir| protos_dir.join(dir.unwrap().file_name()))
14-
.filter(|entry| entry.is_file() && entry.extension().map_or(false, |ext| ext == "proto"))
14+
.filter(|entry| entry.is_file() && entry.extension().is_some_and(|ext| ext == "proto"))
1515
.map(|path| path.to_string_lossy().to_string())
1616
.collect();
1717
proto_files.extend(subdir_proto_files);

rust/crates/opencue-proto/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ mod cue;
1212
mod department;
1313
mod depend;
1414
pub mod facility;
15+
#[allow(clippy::all, clippy::pedantic, clippy::nursery)]
1516
mod filter;
1617
pub mod host;
18+
#[allow(clippy::all, clippy::pedantic, clippy::nursery)]
1719
pub mod job;
1820
mod limit;
21+
#[allow(clippy::all, clippy::pedantic, clippy::nursery)]
1922
mod render_partition;
2023
pub mod report;
2124
pub mod rqd;
@@ -74,21 +77,17 @@ impl WithUuid for rqd::RunningFrameKillRequest {
7477
fn uuid(&self) -> Uuid {
7578
self.run_frame
7679
.as_ref()
77-
.map(|run_frame| to_uuid(&run_frame.frame_id))
78-
.flatten()
80+
.and_then(|run_frame| to_uuid(&run_frame.frame_id))
7981
.unwrap_or(Uuid::nil())
80-
.clone()
8182
}
8283
}
8384

8485
impl WithUuid for rqd::RunningFrameStatusRequest {
8586
fn uuid(&self) -> Uuid {
8687
self.run_frame
8788
.as_ref()
88-
.map(|run_frame| to_uuid(&run_frame.frame_id))
89-
.flatten()
89+
.and_then(|run_frame| to_uuid(&run_frame.frame_id))
9090
.unwrap_or(Uuid::nil())
91-
.clone()
9291
}
9392
}
9493

rust/crates/rqd/src/config/config.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl RunnerConfig {
184184

185185
#[derive(Debug, Deserialize, Clone)]
186186
#[serde(default)]
187+
#[derive(Default)]
187188
pub struct OverrideConfig {
188189
pub cores: Option<u64>,
189190
pub procs: Option<u64>,
@@ -193,18 +194,6 @@ pub struct OverrideConfig {
193194
pub os: Option<String>,
194195
}
195196

196-
impl Default for OverrideConfig {
197-
fn default() -> OverrideConfig {
198-
OverrideConfig {
199-
cores: None,
200-
procs: None,
201-
memory_size: None,
202-
workstation_mode: None,
203-
hostname: None,
204-
os: None,
205-
}
206-
}
207-
}
208197

209198
//===Config Loader===
210199

@@ -232,7 +221,7 @@ impl Config {
232221
println!(" INFO Config::load: using config file: {:?}", config_file);
233222

234223
let config = ConfigBase::builder()
235-
.add_source(File::with_name(&*config_file).required(required))
224+
.add_source(File::with_name(&config_file).required(required))
236225
.add_source(Environment::with_prefix("OPENRQD").separator("_"))
237226
.build()
238227
.map_err(|err| {

0 commit comments

Comments
 (0)