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

Switch config to YAML #239

Merged
merged 10 commits into from
Feb 1, 2019
Merged

Switch config to YAML #239

merged 10 commits into from
Feb 1, 2019

Conversation

artem-zinnatullin
Copy link
Contributor

@artem-zinnatullin artem-zinnatullin commented Nov 26, 2018

Closes #225, part of #213

This change switches config format that used to be some sort of .ini file to YAML as discussed in #225

Example of .mainframer/config.yml:

remote:
  host: "computer1"
  user: "user1" # Not implemented yet.
  port: 1234    # Not implemented yet.
push:
  compression: 5
pull:
  compression: 2

Code is also getting ready for config files merging #213.

  • IntermediateConfig represents one of possibly multiple config files, thus everything is optional.
  • Config represents finalized config, thus only actually optional fields are optional

Note that remote.user and remote.port are not implemented yet (we continue to rely on ~/.ssh/config read by ssh for now)


Description was updated to reflect changes after review, you can see edit history.

}

#[derive(Debug, Eq, PartialEq)]
pub struct IntermediateCompression {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t we use the same value for both channels? I’m already forgetting what is the benefit of having different ones. Yes, it can be a bit faster to send sources uncompressed, but I believe compression does not eat a lot of resources in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text is very compressible compared to compiled binaries, thus we recommend at least 3 for local compression and 1 for remote

But obviously, each project can be different — thus it's a setting

As well as different use cases, for example when you have limited connection you might prefer compression over latency

It does eat quite a lot of resources, try 9 :)

src/config.rs Outdated
#[derive(Debug, Eq, PartialEq)]
pub struct Compression {
pub local: i64,
pub remote: i64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t it be i8 though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, it's a slip of YAML impl details, I guess I should use proper type here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done yet, I'll track it separately, value is validated anyway and realistically i8 is going to still be i32 at least on actual hardware

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


let compression = match &yaml["compression"] {
Yaml::Hash(compression) => {
let local = match compression.get(&Yaml::String(String::from("local"))).cloned() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dude, YAML parsing in Rust sucks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, could have been worse lol

src/intermediate_config.rs Outdated Show resolved Hide resolved
@arturdryomov
Copy link
Contributor

After internal discussion we decided to pursue the following.

.mainframer/config.yml

remote:
  name: "name"
push:
  compression: N
  sync: "serial"
pull:
  compression: N
  sync: "parallel"

.mainframer/ignore.yml

both:
  - "path"
  - "path"
  - "path"
push:
  - "path"
  - "path"
  - "path"
pull:
  - "path"
  - "path"
  - "path"

@artem-zinnatullin
Copy link
Contributor Author

@ming13 updated PR with new YAML structure

src/config.rs Outdated
pub local: i64,
pub remote: i64,
pub struct Push {
pub compression: i64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still — i64 is too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to u8

src/config.rs Outdated
pub compression: i64,
}

#[derive(Debug, Eq, PartialEq)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need both Eq and PartialEq?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great question my friend!

I need equality for unit tests (assert_eq!())
In Rust Eq seems to be special case of PartialEq and most of things like assert_eq!() need PartialEq thus I definitely need to have PartialEq

Removed Eq 👍

pub compression: Option<IntermediateCompression>,
pub remote: Option<IntermediateRemote>,
pub push: Option<IntermediatePush>,
pub pull: Option<IntermediatePull>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really weird, but I like that both push and pull have the same horizontal space...

Some(local) => match local {
Yaml::Integer(local) => if local >= 1 && local <= 9 {
Some(local)
let push = match &yaml["push"] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is time to move push and pull reading to a single function since essentially they are the same. Maybe even replace struct Pull and struct Push with struct Sync or whatever.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're not same, Pull will support parallel mode soon, common fields can be extracted though

pub local: Option<i64>,
pub remote: Option<i64>,
pub struct IntermediatePush {
pub compression: Option<i64>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compressionLevel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why though, it's called compression in YAML, I mean we can have different name in code but I don't see much value in that atm

@artem-zinnatullin
Copy link
Contributor Author

Updated PR, @ming13 let's do YAML for ignore files in separate PR, it will be a pretty big change

@arturdryomov
Copy link
Contributor

All right, I’ll try not to leave any comments since the next time you’ll have time to make changes is approximately March 26.

use std::path::Path;

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have no idea why language has PartialEq and Eq.

@@ -9,3 +9,5 @@ version = "3.0.0-dev"
authors = ["Artem Zinnatullin <[email protected]>", "Artur Dryomov <[email protected]>", "Mainframer Developers and Contributors"]

[dependencies]
yaml-rust = "0.4.2"
linked-hash-map = "0.5.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, what? No maps in Rust?

};

file.read_to_string(&mut content)
.unwrap_or_else(|_| panic!("Could not read config file '{}'", file_path.to_string_lossy()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot?

};

let pull = match &yaml["pull"] {
Yaml::Hash(pull) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, YAML parsing is so weird...


assert_eq!(parse_config_from_str(content), Ok(IntermediateConfig {
remote: Some(IntermediateRemote {
host: Some(String::from("computer1")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t it better to define expected variables beforehand and put them into the content?

compression: yooo
";
assert_eq!(parse_config_from_str(content), Err(String::from("'pull.compression\' must be a positive integer from 1 to 9, but was String(\n \"yooo\"\n)")));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good test suite.

@artem-zinnatullin artem-zinnatullin merged commit 2cbed2d into 3.x Feb 1, 2019
@artem-zinnatullin artem-zinnatullin deleted the az/yaml-config branch February 1, 2019 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants