Skip to content

Commit

Permalink
Added links to cargo source code that was copied + lint
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Richard <jwric@users.noreply.github.com>
  • Loading branch information
ThierryCantin-Demers and jwric committed Sep 6, 2024
1 parent 0cd24ef commit 0c41184
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 1,148 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions crates/heat-sdk-cli/src/cli_commands/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ pub(crate) fn handle_command(args: PackageArgs, context: HeatCliContext) -> anyh
let mut registered_functions = Vec::<RegisteredHeatFunction>::new();
for flag in flags {
// function token stream to readable string
let itemfn = syn_serde::json::from_slice::<syn::ItemFn>(flag.token_stream).expect("Should be able to parse token stream.");
let syn_tree: syn::File = syn::parse2(itemfn.into_token_stream()).expect("Should be able to parse token stream.");
let itemfn = syn_serde::json::from_slice::<syn::ItemFn>(flag.token_stream)
.expect("Should be able to parse token stream.");
let syn_tree: syn::File =
syn::parse2(itemfn.into_token_stream()).expect("Should be able to parse token stream.");
let code_str = prettyplease::unparse(&syn_tree);
registered_functions.push(RegisteredHeatFunction {
mod_path: flag.mod_path.to_string(),
Expand Down
11 changes: 7 additions & 4 deletions crates/heat-sdk-cli/src/cli_commands/run/remote/training.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct RemoteTrainingRunArgs {
short = 'r',
long = "runner",
help = "The runner group name.",
required = true,
required = true
)]
pub runner: String,
}
Expand Down Expand Up @@ -84,8 +84,10 @@ pub(crate) fn handle_command(
let mut registered_functions = Vec::<RegisteredHeatFunction>::new();
for flag in flags {
// function token stream to readable string
let itemfn = syn_serde::json::from_slice::<syn::ItemFn>(flag.token_stream).expect("Should be able to parse token stream.");
let syn_tree: syn::File = syn::parse2(itemfn.into_token_stream()).expect("Should be able to parse token stream.");
let itemfn = syn_serde::json::from_slice::<syn::ItemFn>(flag.token_stream)
.expect("Should be able to parse token stream.");
let syn_tree: syn::File =
syn::parse2(itemfn.into_token_stream()).expect("Should be able to parse token stream.");
let code_str = prettyplease::unparse(&syn_tree);
registered_functions.push(RegisteredHeatFunction {
mod_path: flag.mod_path.to_string(),
Expand All @@ -99,7 +101,8 @@ pub(crate) fn handle_command(
functions: registered_functions,
};

let project_version = heat_client.upload_new_project_version(context.package_name(), heat_metadata, crates)?;
let project_version =
heat_client.upload_new_project_version(context.package_name(), heat_metadata, crates)?;

heat_client.start_remote_job(
args.runner,
Expand Down
7 changes: 7 additions & 0 deletions crates/heat-sdk-cli/src/util/cargo/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use serde::ser;

use super::interning::InternedString;

/// From cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/dependency.rs#L102
#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug, Copy)]
pub enum DepKind {
Normal,
Development,
Build,
}

/// From cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/dependency.rs#L108
impl DepKind {
pub fn kind_table(&self) -> &'static str {
match self {
Expand All @@ -23,6 +25,7 @@ impl DepKind {
}
}

//From cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/dependency.rs#L118
impl ser::Serialize for DepKind {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -37,6 +40,8 @@ impl ser::Serialize for DepKind {
}
}

/// From cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/summary.rs#L355
///
/// FeatureValue represents the types of dependencies a feature can have.
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum FeatureValue {
Expand All @@ -55,6 +60,7 @@ pub enum FeatureValue {
},
}

/// From cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/summary.rs#L371
impl FeatureValue {
pub fn new(feature: InternedString) -> FeatureValue {
match feature.split_once('/') {
Expand Down Expand Up @@ -95,6 +101,7 @@ impl FeatureValue {
}
}

/// From cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/summary.rs#L411
impl fmt::Display for FeatureValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::FeatureValue::*;
Expand Down
8 changes: 7 additions & 1 deletion crates/heat-sdk-cli/src/util/cargo/features.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#![allow(dead_code)]
#![allow(unused)]

use std::{fmt, str::FromStr};

use cargo_metadata::semver;
use serde::{Deserialize, Serialize};

/// From Cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/features.rs#L186
///
/// The edition of the compiler ([RFC 2052])
///
/// The following sections will guide you how to add and stabilize an edition.
Expand Down Expand Up @@ -61,6 +63,8 @@ pub enum Edition {
Edition2024,
}

/// From Cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/features.rs#L198
/// Some unused impls were removed.
impl Edition {
/// The latest edition that is unstable.
///
Expand Down Expand Up @@ -157,6 +161,7 @@ impl Edition {
}
}

/// From Cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/features.rs#L313
impl fmt::Display for Edition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Expand All @@ -168,6 +173,7 @@ impl fmt::Display for Edition {
}
}

/// From Cargo: https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/core/features.rs#L324
impl FromStr for Edition {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, anyhow::Error> {
Expand Down
4 changes: 4 additions & 0 deletions crates/heat-sdk-cli/src/util/cargo/interning.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This file is copied 1 for 1 from Cargo's source code.
// The original file can be found at:
// https://github.com/rust-lang/cargo/blob/57622d793935a662b5f14ca728a2989c14833d37/src/cargo/util/interning.rs

use serde::{Serialize, Serializer};
use serde_untagged::UntaggedEnumVisitor;
use std::borrow::Borrow;
Expand Down
5 changes: 5 additions & 0 deletions crates/heat-sdk-cli/src/util/cargo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! All of the code in this directory is heavily inspired by the [Cargo source code](https://github.com/rust-lang/cargo)
//! and modified to fit the needs of the heat-sdk-cli project.
//!
//! In files that are entirely copied from Cargo, a link to the original source code is included in the top of the file as a comment.
//! In files that are partially copied from Cargo or include functions/definitons from multiple different files in Cargo, a link to the source code of the original functions/definitions is included in the comments above the copied code.
//!
//! Definitions and functions that are not copied from Cargo do not have a link to the original source code.
mod dependency;
mod features;
Expand Down
Loading

0 comments on commit 0c41184

Please sign in to comment.