Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format in ci.yml #287

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: rustfmt
override: true

- name: Check formatting
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check

build:
needs: lint
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-cli/src/commands/build/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub struct BuildContractCommand {
/// Path for the contract project [default: current directory]
#[arg(long)]
pub(crate) path: Option<PathBuf>,
/// The default compilation includes debug functionality, increasing contract size and gas usage.
/// For production, always build in release mode to exclude debug features.
/// The default compilation includes debug functionality, increasing contract size and gas
/// usage. For production, always build in release mode to exclude debug features.
#[clap(short, long)]
pub(crate) release: bool,
// Deprecation flag, used to specify whether the deprecation warning is shown.
Expand Down
3 changes: 2 additions & 1 deletion crates/pop-cli/src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ pub(crate) enum Command {
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(BuildParachainCommand),
/// [DEPRECATED] Build a contract, generate metadata, bundle together in a `<name>.contract` file
/// [DEPRECATED] Build a contract, generate metadata, bundle together in a `<name>.contract`
/// file
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(BuildContractCommand),
Expand Down
28 changes: 15 additions & 13 deletions crates/pop-cli/src/commands/build/spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: GPL-3.0

use crate::{cli, cli::traits::Cli as _, cli::Cli, style::style};
use crate::{
cli,
cli::{traits::Cli as _, Cli},
style::style,
};
use clap::{Args, ValueEnum};
use cliclack::{confirm, input};
use pop_common::Profile;
Expand Down Expand Up @@ -366,13 +370,13 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
}
// Prompt relays chains based on the chain type
match chain_type {
ChainType::Live => {
ChainType::Live =>
for relay in RelayChain::VARIANTS {
if !matches!(
relay,
RelayChain::Westend
| RelayChain::Paseo | RelayChain::Kusama
| RelayChain::Polkadot
RelayChain::Westend |
RelayChain::Paseo | RelayChain::Kusama |
RelayChain::Polkadot
) {
continue;
} else {
Expand All @@ -382,15 +386,14 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
relay.get_detailed_message().unwrap_or_default(),
);
}
}
},
_ => {
},
_ =>
for relay in RelayChain::VARIANTS {
if matches!(
relay,
RelayChain::Westend
| RelayChain::Paseo | RelayChain::Kusama
| RelayChain::Polkadot
RelayChain::Westend |
RelayChain::Paseo | RelayChain::Kusama |
RelayChain::Polkadot
) {
continue;
} else {
Expand All @@ -400,8 +403,7 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
relay.get_detailed_message().unwrap_or_default(),
);
}
}
},
},
}

let relay_chain = prompt.interact()?.clone();
Expand Down
5 changes: 2 additions & 3 deletions crates/pop-cli/src/commands/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,11 @@ async fn install_rustup() -> anyhow::Result<()> {
async fn install_homebrew() -> anyhow::Result<()> {
match cmd("which", vec!["brew"]).read() {
Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?,
Err(_) => {
Err(_) =>
run_external_script(
"https://raw.githubusercontent.com/Homebrew/install/master/install.sh",
)
.await?
},
.await?,
}
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions crates/pop-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ impl Command {
},
#[cfg(feature = "parachain")]
new::Command::Pallet(cmd) => {
// When more contract selections are added the tel data will likely need to go deeper in the stack
// When more contract selections are added the tel data will likely need to go
// deeper in the stack
cmd.execute().await.map(|_| json!("template"))
},
#[cfg(feature = "contract")]
new::Command::Contract(cmd) => {
// When more contract selections are added, the tel data will likely need to go deeper in the stack
// When more contract selections are added, the tel data will likely need to go
// deeper in the stack
cmd.execute().await.map(|_| json!("default"))
},
},
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-cli/src/commands/new/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl NewContractCommand {
let contract_type = &contract_config.contract_type.clone().unwrap_or_default();
let template = match &contract_config.template {
Some(template) => template.clone(),
None => contract_type.default_template().expect("contract types have defaults; qed."), // Default contract type
None => contract_type.default_template().expect("contract types have defaults; qed."), /* Default contract type */
};

is_template_supported(contract_type, &template)?;
Expand Down
12 changes: 7 additions & 5 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-3.0

use crate::cli::{traits::Cli as _, Cli};
use crate::style::style;
use crate::{
cli::{traits::Cli as _, Cli},
style::style,
};
use anyhow::Result;
use clap::{
builder::{PossibleValue, PossibleValuesParser, TypedValueParser},
Expand Down Expand Up @@ -78,7 +80,7 @@ impl NewParachainCommand {
let provider = &parachain_config.provider.clone().unwrap_or_default();
let template = match &parachain_config.template {
Some(template) => template.clone(),
None => provider.default_template().expect("parachain templates have defaults; qed."), // Each provider has a template by default
None => provider.default_template().expect("parachain templates have defaults; qed."), /* Each provider has a template by default */
};

is_template_supported(provider, &template)?;
Expand Down Expand Up @@ -239,8 +241,8 @@ fn get_customization_value(
decimals: Option<u8>,
initial_endowment: Option<String>,
) -> Result<Config> {
if !matches!(template, Parachain::Standard)
&& (symbol.is_some() || decimals.is_some() || initial_endowment.is_some())
if !matches!(template, Parachain::Standard) &&
(symbol.is_some() || decimals.is_some() || initial_endowment.is_some())
{
log::warning("Customization options are not available for this template")?;
sleep(Duration::from_secs(3))
Expand Down
16 changes: 9 additions & 7 deletions crates/pop-cli/src/commands/up/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use pop_contracts::{
};
use sp_core::Bytes;
use sp_weights::Weight;
use std::process::Child;
use std::{
path::{Path, PathBuf},
process::Command,
process::{Child, Command},
};
use tempfile::NamedTempFile;
use url::Url;
Expand Down Expand Up @@ -71,7 +70,8 @@ pub struct UpContractCommand {
/// Uploads the contract only, without instantiation.
#[clap(short('u'), long)]
upload_only: bool,
/// Automatically source or update the needed binary required without prompting for confirmation.
/// Automatically source or update the needed binary required without prompting for
/// confirmation.
#[clap(short('y'), long)]
skip_confirm: bool,
}
Expand Down Expand Up @@ -313,19 +313,21 @@ impl From<UpContractCommand> for UpOpts {
}
}

/// Checks if a contract has been built by verifying the existence of the build directory and the <name>.contract file.
/// Checks if a contract has been built by verifying the existence of the build directory and the
/// <name>.contract file.
///
/// # Arguments
/// * `path` - An optional path to the project directory. If no path is provided, the current directory is used.
/// * `path` - An optional path to the project directory. If no path is provided, the current
/// directory is used.
pub fn has_contract_been_built(path: Option<&Path>) -> bool {
let project_path = path.unwrap_or_else(|| Path::new("./"));
let manifest = match from_path(Some(project_path)) {
Ok(manifest) => manifest,
Err(_) => return false,
};
let contract_name = manifest.package().name();
project_path.join("target/ink").exists()
&& project_path.join(format!("target/ink/{}.contract", contract_name)).exists()
project_path.join("target/ink").exists() &&
project_path.join(format!("target/ink/{}.contract", contract_name)).exists()
}

#[cfg(test)]
Expand Down
21 changes: 10 additions & 11 deletions crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ pub(crate) struct ZombienetCommand {
/// The Zombienet network configuration file to be used.
#[arg(short, long)]
file: String,
/// The version of the binary to be used for the relay chain, as per the release tag (e.g. "v1.13.0").
/// See https://github.com/paritytech/polkadot-sdk/releases for more details.
/// The version of the binary to be used for the relay chain, as per the release tag (e.g.
/// "v1.13.0"). See https://github.com/paritytech/polkadot-sdk/releases for more details.
#[arg(short, long)]
relay_chain: Option<String>,
/// The version of the runtime to be used for the relay chain, as per the release tag (e.g. "v1.2.7").
/// See https://github.com/polkadot-fellows/runtimes/releases for more details.
/// The version of the runtime to be used for the relay chain, as per the release tag (e.g.
/// "v1.2.7"). See https://github.com/polkadot-fellows/runtimes/releases for more details.
#[arg(short = 'R', long)]
relay_chain_runtime: Option<String>,
/// The version of the binary to be used for system parachains, as per the release tag (e.g. "v1.13.0").
/// Defaults to the relay chain version if not specified.
/// The version of the binary to be used for system parachains, as per the release tag (e.g.
/// "v1.13.0"). Defaults to the relay chain version if not specified.
/// See https://github.com/paritytech/polkadot-sdk/releases for more details.
#[arg(short, long)]
system_parachain: Option<String>,
/// The version of the runtime to be used for system parachains, as per the release tag (e.g. "v1.2.7").
/// See https://github.com/polkadot-fellows/runtimes/releases for more details.
/// The version of the runtime to be used for system parachains, as per the release tag (e.g.
/// "v1.2.7"). See https://github.com/polkadot-fellows/runtimes/releases for more details.
#[arg(short = 'S', long)]
system_parachain_runtime: Option<String>,
/// The url of the git repository of a parachain to be used, with branch/release tag/commit specified as #fragment (e.g. 'https://github.com/org/repository#ref').
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ZombienetCommand {
.await
{
Ok(n) => n,
Err(e) => {
Err(e) =>
return match e {
Error::Config(message) => {
outro_cancel(format!("🚫 A configuration error occurred: `{message}`"))?;
Expand All @@ -82,8 +82,7 @@ impl ZombienetCommand {
Ok(())
},
_ => Err(e.into()),
}
},
},
};

// Source any missing/stale binaries
Expand Down
3 changes: 2 additions & 1 deletion crates/pop-cli/src/common/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use cliclack::{confirm, log::warning, spinner};
use pop_contracts::contracts_node_generator;
use std::path::PathBuf;

/// Checks the status of the `substrate-contracts-node` binary, sources it if necessary, and prompts the user to update it if the existing binary is not the latest version.
/// Checks the status of the `substrate-contracts-node` binary, sources it if necessary, and
/// prompts the user to update it if the existing binary is not the latest version.
///
/// # Arguments
/// * `skip_confirm`: A boolean indicating whether to skip confirmation prompts.
Expand Down
3 changes: 2 additions & 1 deletion crates/pop-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async fn main() -> Result<()> {

#[cfg(feature = "telemetry")]
if let Some(tel) = maybe_tel.clone() {
// `args` is guaranteed to have at least 3 elements as clap will display help message if not set.
// `args` is guaranteed to have at least 3 elements as clap will display help message if not
// set.
let (command, subcommand) = parse_args(args().collect());

if let Ok(sub_data) = &res {
Expand Down
3 changes: 2 additions & 1 deletion crates/pop-cli/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ async fn contract_lifecycle() -> Result<()> {
])
.assert()
.success();
// Using methods from the pop_contracts crate to instantiate it to get the Contract Address for the call
// Using methods from the pop_contracts crate to instantiate it to get the Contract Address for
// the call
let instantiate_exec = set_up_deployment(UpOpts {
path: Some(temp_dir.join("test_contract")),
constructor: "new".to_string(),
Expand Down
3 changes: 2 additions & 1 deletion crates/pop-cli/tests/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ async fn parachain_lifecycle() -> Result<()> {
assert!(temp_dir.join("test_parachain/target").exists());

let temp_parachain_dir = temp_dir.join("test_parachain");
// pop build spec --output ./target/pop/test-spec.json --id 2222 --type development --relay paseo-local --protocol-id pop-protocol"
// pop build spec --output ./target/pop/test-spec.json --id 2222 --type development --relay
// paseo-local --protocol-id pop-protocol"
Command::cargo_bin("pop")
.unwrap()
.current_dir(&temp_parachain_dir)
Expand Down
8 changes: 4 additions & 4 deletions crates/pop-common/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use std::{
/// # Arguments
///
/// * `file_path` - A `PathBuf` specifying the path to the file to be modified.
/// * `replacements` - A `HashMap` where each key-value pair represents
/// a target string and its corresponding replacement string.
///
/// * `replacements` - A `HashMap` where each key-value pair represents a target string and its
/// corresponding replacement string.
pub fn replace_in_file(file_path: PathBuf, replacements: HashMap<&str, &str>) -> Result<(), Error> {
// Read the file content
let mut file_content = String::new();
Expand All @@ -31,7 +30,8 @@ pub fn replace_in_file(file_path: PathBuf, replacements: HashMap<&str, &str>) ->
Ok(())
}

/// Gets the last component (name of a project) of a path or returns a default value if the path has no valid last component.
/// Gets the last component (name of a project) of a path or returns a default value if the path has
/// no valid last component.
///
/// # Arguments
/// * `path` - Location path of the project.
Expand Down
10 changes: 4 additions & 6 deletions crates/pop-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ pub fn target() -> Result<&'static str, Error> {
}

match ARCH {
"aarch64" => {
"aarch64" =>
return match OS {
"macos" => Ok("aarch64-apple-darwin"),
_ => Ok("aarch64-unknown-linux-gnu"),
}
},
"x86_64" | "x86" => {
},
"x86_64" | "x86" =>
return match OS {
"macos" => Ok("x86_64-apple-darwin"),
_ => Ok("x86_64-unknown-linux-gnu"),
}
},
},
&_ => {},
}
Err(Error::UnsupportedPlatform { arch: ARCH, os: OS })
Expand Down
6 changes: 4 additions & 2 deletions crates/pop-common/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use toml_edit::{value, DocumentMut, Item, Value};
/// Parses the contents of a `Cargo.toml` manifest.
///
/// # Arguments
/// * `path` - The optional path to the manifest, defaulting to the current directory if not specified.
/// * `path` - The optional path to the manifest, defaulting to the current directory if not
/// specified.
pub fn from_path(path: Option<&Path>) -> Result<Manifest, Error> {
// Resolve manifest path
let path = match path {
Expand All @@ -28,7 +29,8 @@ pub fn from_path(path: Option<&Path>) -> Result<Manifest, Error> {
Ok(Manifest::from_path(path.canonicalize()?)?)
}

/// This function is used to determine if a Path is contained inside a workspace, and returns a PathBuf to the workspace Cargo.toml if found
/// This function is used to determine if a Path is contained inside a workspace, and returns a
/// PathBuf to the workspace Cargo.toml if found
///
/// # Arguments
/// * `target_dir` - A directory that may be contained inside a workspace
Expand Down
Loading
Loading