massa icon indicating copy to clipboard operation
massa copied to clipboard

Define a standard for our scripts

Open AurelienFT opened this issue 2 years ago • 12 comments

Following a discussion with @sydhds on https://github.com/massalabs/massa/pull/3367 . We thought that we should unify and setup a policy to write our scripts.

I checked how other repositories managed it :

  • Rust use shell scripts : https://github.com/rust-lang/rust/blob/master/.github/workflows/ci.yml
  • Solana use shell scripts : https://github.com/solana-labs/solana/tree/master/ci
  • Near use mainly python scripts : https://github.com/near/nearcore/tree/master/scripts

We used cargo-script one time but they are not used by anyone else because the package isn't maintained since 2017.

@sydhds thinks that Python is a good way to go to keep our scripts cross platform. What do you think @massalabs/core-team ?

AurelienFT avatar Jan 05 '23 14:01 AurelienFT

I never used it but i think we can replace cargo-script by rust-script (https://crates.io/crates/rust-script). Python is a good way too

modship avatar Jan 05 '23 15:01 modship

If you wanna rustify the scripts, we have rhai.

aoudiamoncef avatar Jan 05 '23 15:01 aoudiamoncef

I never used it but i think we can replace cargo-script by rust-script (https://crates.io/crates/rust-script). Python is a good way too

I don't find any article that make a comparison with pros and cons about rust scripting and usage in CI. Hard to make a choice

AurelienFT avatar Jan 05 '23 15:01 AurelienFT

If you wanna rustify the scripts, we have rhai.

It's a new scripting language that can be integrated with Rust ? But does it support cloning git repository launching dockers etc ? And why it's better then Rust/Python ?

AurelienFT avatar Jan 05 '23 15:01 AurelienFT

Problem with rust script is that you need to import some dependencies in order to perform simple task.

As an example in https://github.com/massalabs/massa/blob/main/tools/setup_test.rs, we need:

  • clap (argument parsing)
  • glob crate (for directory parsing)
  • http crate (to download file)

This script could be rewritten in python using only the std lib so I'm in favor of python script here :)

sydhds avatar Jan 06 '23 08:01 sydhds

Problem with rust script is that you need to import some dependencies in order to perform simple task.

As an example in https://github.com/massalabs/massa/blob/main/tools/setup_test.rs, we need:

  • clap (argument parsing)
  • glob crate (for directory parsing)
  • http crate (to download file)

This script could be rewritten in python using only the std lib so I'm in favor of python script here :)

@sydhds You can parse arg in rust with standard lib too std::env::args() clap is more friendly user. For glob and http on the other hand i don’t know a solution with the std library.

Python would be more appropriate for scripting where performance is not needed

modship avatar Jan 06 '23 08:01 modship

@massalabs/core-team last week to share your thoughts before deciding.

AurelienFT avatar Jan 15 '23 17:01 AurelienFT

In general, I'm leaning towards python scripting if it is suitable for most of our scripts (regarding e.g. performance).

Leo-Besancon avatar Jan 17 '23 15:01 Leo-Besancon

With the caveat that I don't have much history with scripting, here are my two cents :

Whichever way we go, I advocate for having some sort of strongly enforced typing. E.g. what the mypy library promises.

If we go with python, but not with mypy I would at least like to see usage of type-hints enforced by CI.

With that said, a rust-oriented solution would get my vote, if that's on the table.

Ben-PH avatar Jan 17 '23 15:01 Ben-PH

I hate to say this but I also believe Python scripts are probably our best option, writing them in Rust is way more fun but only brings inconveniences imo.

Eitu33 avatar Jan 17 '23 15:01 Eitu33

That said, there will still be a minority of cases where we have no choice but to write them in Rust, for a DB dump script for example, or really anything that would require an object or a behaviour from the node that is too complex or impossible to reproduce in a Python script.

Eitu33 avatar Jan 17 '23 15:01 Eitu33

The decision is to write our scripts in Python except for the ones that need to interact with direct modules of our codes and don't have bindings that need to be wrote in Rust.

I let this issue open to remember to change our current script in Rust (unit test) and bash (gas-calibration check) to python.

AurelienFT avatar Jan 23 '23 01:01 AurelienFT

Discussion is over. Closing.

AurelienFT avatar Mar 28 '24 14:03 AurelienFT