Skip to content

Be a XDG-friendly tool#344

Merged
Tonkpils merged 1 commit intoexercism:masterfrom
narqo:fix-test-paths
Sep 19, 2016
Merged

Be a XDG-friendly tool#344
Tonkpils merged 1 commit intoexercism:masterfrom
narqo:fix-test-paths

Conversation

@narqo
Copy link
Copy Markdown

@narqo narqo commented Aug 21, 2016

Search for config in common paths (e.g. ~/.config/exercism.json, ~/.exercism.json`).

In case $XDG_CONFIG_HOME is set, tests of paths package fail as config home was not mocked properly.

The patch simplifies paths' internals and introduces a more flexible way to mock globals of paths package.

@kytrinyx
Copy link
Copy Markdown
Member

Nice catch, thanks @narqo!

@Tonkpils @lcowell Would one of you give this a second look?

paths/paths.go Outdated
panic(err)
}
// Recalculate sets exercism paths
func Recalculate(home, configHome string) {
Copy link
Copy Markdown
Contributor

@Tonkpils Tonkpils Aug 23, 2016

Choose a reason for hiding this comment

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

It seems this functions whole purpose now is to setup the Home and ConfigHome and only used within init. What about just dropping the function all together and setting the variables directly on the tests and doing this same logic from init?

Copy link
Copy Markdown
Contributor

@lcowell lcowell Aug 23, 2016

Choose a reason for hiding this comment

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

I agree, this function doesn't have a lot of value right now, especially given that we now have other inputs for doing the testing. I think we could justify keeping it if we gave it a better name. Maybe assignConfigHome or resolveConfigHome (if we assign paths.ConfigHome outside the function). if we don't fold it in to init, I don't think it needs to be exported.

Edit: I think I'd vote for keeping this method as it encapsulates a nuanced piece of logic and gives us a simple way to test things.

@lcowell
Copy link
Copy Markdown
Contributor

lcowell commented Aug 23, 2016

Tests pass. Looks great!

@narqo
Copy link
Copy Markdown
Author

narqo commented Aug 23, 2016

Thank you for the feedback, I'll fix the PR anytime soon.

But, to be honest, I'm not very happy about the logic of the paths module, which I'd like to discuss.

To my taste, it feels unnatural, that $XDG_CONFIG_HOME is considered as an exclusive option for ConfigHome path. IMHO, the way "XDG-friendly" tool should operate, is to check if the config is within the possible directories. E.g., a tool should check

  • $XDG_CONFIG_HOME/exercism.json
  • $HOME/.config/exercism.json
  • $HOME/.exercism.json

during the initialization process. At least, tools like git and others do it this way.

@Tonkpils
Copy link
Copy Markdown
Contributor

@narqo we are always open for discussion and thanks for bringing up your concern.

If I understand you correctly, you mean we should be checking for the existence of the exercism.json file under those paths based on priority rather than just assigning the ConfigHome altogether and assuming the file will be there?

That sounds reasonable to me, would you be open to making those changes?

@lcowell @kytrinyx what are your thoughts on that?

@narqo
Copy link
Copy Markdown
Author

narqo commented Aug 23, 2016

That sounds reasonable to me, would you be open to making those changes?

Sure, it'd be nice brain training.

@kytrinyx
Copy link
Copy Markdown
Member

That sounds reasonable to me

Yeah, same here.

- respect `$XDG_CONFIG_HOME` environment variable
- search for config in common paths on initialisation

fix tests for exercism.paths on systems with `$XDG_CONFIG_HOME`

In case `$XDG_CONFIG_HOME` is set, tests of `paths` package fail as
config home was not mocked properly.
@narqo narqo changed the title Fix tests for exercism.paths on systems with $XDG_CONFIG_HOME Be a XDG-friendly tool Aug 25, 2016
@narqo
Copy link
Copy Markdown
Author

narqo commented Aug 25, 2016

🆙

I've updated the logic of paths and config modules. Since now on path.Config() returns a path based on ConfigHome, which is set to $XDG_CONFIG_HOME or ~/.config if the former isn't set. If the path doesn't exist, config module uses paths.DefaultConfig as a value for config.File.

I believe the changes match to the current behaviour of the CLI.

@kytrinyx
Copy link
Copy Markdown
Member

I believe the current behavior has three possibilities in this order of priority:

  1. EXERCISM_CONFIG_FILE
  2. XDG_CONFIG_HOME
  3. ~/.exercism.json (I think, though ~/.config/exercism.json would be friendlier)

}
}

func TestXDGConfig(t *testing.T) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This test is useless now, as the behaviour of the paths.Config() only depends on ConfigHome, which was tested above.

@narqo
Copy link
Copy Markdown
Author

narqo commented Aug 25, 2016

I believe the current behavior has three possibilities in this order of priority:

Yeah, thank you, I've forgotten to mention this. $EXERCISM_CONFIG_FILE would always be the most preferable (and exclusive) option if it was set (because github.com/urfave/cli is used this way).

So now the priority paths are:

  • $EXERCISM_CONFIG_FILE or $XDG_CONFIG_HOME
  • ~/.config/exercism.json
  • ~/.exercism.json

@Tonkpils
Copy link
Copy Markdown
Contributor

Thanks for the work on this @narqo, I'm going to go ahead and merge this and update the CHANGELOG!

@Tonkpils Tonkpils merged commit 0ad8206 into exercism:master Sep 19, 2016
@kytrinyx
Copy link
Copy Markdown
Member

Thank you @narqo!

@narqo
Copy link
Copy Markdown
Author

narqo commented Sep 19, 2016

I'm totally glad I was helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants