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

cli: look harder for $PWD/cfg, don't automatically start config wizard #2093

Closed
wants to merge 1 commit into from

Conversation

half-duplex
Copy link
Member

@half-duplex half-duplex commented Jun 8, 2021

Description

This fixes two annoyances:

  • Sopel automatically adds .cfg when searching the config dir, but it doesn't when searching the current working directory
  • If the config file is not found, it currently automatically starts the configuration wizard.

Combining these two, a user (me) will (does, regularly) cd to their non-default Sopel config dir, run sopel -c mybot expecting it to load mybot.cfg and run, but instead have Sopel create ~/.sopel/ and ~/.sopel/mybot.cfg and start the config wizard.

Searching $PWD/{config}.{ext} is straightforward, but not automatically running the wizard is probably subject to opinions. I changed it to the below output, but I would also be content with "Do you want to run the configuration wizard? y/n", or at least not creating the folder/file until the end of the wizard so the user has an opportunity to ^C without having to then rm -rf ~/.sopel

Amended "couldn't find config":

$ sopel -c foobar
Welcome to Sopel!
I can't seem to find the configuration file.
To start the configuration wizard, run `sopel configure`
Unable to find the configuration file /home/user/.sopel/foobar
$

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

This kind of behavior change isn't appropriate for our upcoming patch release series (7.1.x), so I'll have to tag it for 8.0. It will fit right in with some other CLI changes I remember Exi talking about wanting to do.

Just one idea in notes below.

sopel/cli/run.py Outdated Show resolved Hide resolved
@dgw dgw added this to the 8.0.0 milestone Jun 9, 2021
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Works for me.

@dgw dgw requested a review from Exirel June 10, 2021 06:28
sopel/cli/run.py Outdated
"To start the configuration wizard, run `sopel configure`",
sep="\n",
)
sys.exit(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

That will be a hard no for me: sys.exit shouldn't appear here, and left to the caller to decide when to exit.

Copy link
Member

@dgw dgw Jun 10, 2021

Choose a reason for hiding this comment

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

Problem is the caller needs the exception re-raised to know that it should exit, and re-raising the exception will print the error text again in both places where this func is called—exactly the redundancy I asked mal to eliminate.

sopel/sopel/cli/run.py

Lines 410 to 414 in a174d18

try:
settings = get_configuration(opts)
except config.ConfigurationError as e:
tools.stderr(e)
return ERR_CODE_NO_RESTART

sopel/sopel/cli/run.py

Lines 608 to 612 in a174d18

try:
settings = get_configuration(opts)
except config.ConfigurationError as e:
tools.stderr(e)
return ERR_CODE_NO_RESTART

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes? There is nothing that prevent that code to raise a new exception with a different error message, it looks like it'll work properly and do exactly what is expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thoughts? Not redundant, no exit(), doesn't rely on context in a way that rubs me weird but exi says is fine.

$ sopel -c foobar
Welcome to Sopel! To start the configuration wizard, run `sopel configure`
Unable to find the configuration file /home/user/.sopel/foobar

Copy link
Member

Choose a reason for hiding this comment

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

Outputting the solution before stating the problem is a bit weird, but tolerable. There's no rule saying this can't be changed again later, after all.

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 don't get why raising a fresh new exception is bad, but I guess it can be changed again later, after all.

Copy link
Member Author

Choose a reason for hiding this comment

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

See latest - Add ConfNotFound.hint for preferred order?

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Nitpicking the spelling and style. I'll let Exi come back and be Opinionated™ about the new exception approach.

sopel/config/__init__.py Outdated Show resolved Hide resolved
sopel/config/__init__.py Outdated Show resolved Hide resolved
sopel/cli/run.py Outdated Show resolved Hide resolved
@dgw dgw requested a review from Exirel July 2, 2021 05:18
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

Alright, I've take time to read the code from sopel/cli/run.py and how get_configuration is used: in both case, it catches the generic configuration error to print it and exit.

Now, why does get_configuration exists? It does because it was a way to always get a configuration file and always run the wizard. Now, that's gone. Moreover, in #2118 I plan to simply remove the legacy mode.

So, I think adding the hint property is not the right solution here, and it's making thing more complicated than they should be. There are 3 options:

  • remove the try/except and put a comment in cli: remove legacy mode for run script #2118 to deal with a friendlier error message somehow
  • raise a new configuration error (a generic one) with the proper message (I think I already suggested that)
  • remove the try/except and catch the ConfigurationNotFound in command start (and forget about legacy, which is going down) to print a nice message (and also comment in cli: remove legacy mode for run script #2118 to say good luck with the merge conflict)

In any case, I don't see the point of adding a hint attribute.

@dgw dgw added the Stale Mostly used for PRs that no longer work and need updating before re-review/merge. label Oct 21, 2021
@dgw
Copy link
Member

dgw commented Dec 23, 2021

I recommend taking another look at the behavior on master now that the legacy CLI is gone. If the reason for creating this patch is still present, please do look at @Exirel's suggested alternative solution in the above comment.

@dgw
Copy link
Member

dgw commented Feb 24, 2022

Ping @half-duplex for reevaluation of master and/or responses to Exi's comments.

@dgw
Copy link
Member

dgw commented Mar 10, 2022

Removing from release plans due to lack of attention over a period of months. Can be reopened if a second wind hits, as always.

@dgw dgw closed this Mar 10, 2022
@dgw dgw removed this from the 8.0.0 milestone Mar 10, 2022
@dgw dgw added the Replaced Superseded by a newer PR label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Replaced Superseded by a newer PR Stale Mostly used for PRs that no longer work and need updating before re-review/merge. Tweak
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants