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

--update-all and --interactive #96

Merged
merged 5 commits into from
Nov 8, 2018
Merged

Conversation

peterbe
Copy link
Owner

@peterbe peterbe commented Nov 1, 2018

Fixes #90

@peterbe
Copy link
Owner Author

peterbe commented Nov 1, 2018

@mythmon I don't need an in-depth review but can you take a look?

Basically, the way I test it is:

python hashin.py -r ~/songsearch/requirements.txt -i -u --dry-run

Do you like the interactive prompt? Is it working? Anything else obvious you see?

Copy link
Contributor

@mythmon mythmon left a comment

Choose a reason for hiding this comment

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

This seems good to me. The UI makes sense, and worked on the requirements file I tried (one of hashin's actually). The only way I could break it was by running yes | hashin ..., which repeatedly answered an invalid answer and eventually crashed Python. Not a big deal.

hashin.py Outdated
first_interactive = False
continue
first_interactive = False
except InteractiveAll:
Copy link
Contributor

Choose a reason for hiding this comment

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

My general rule is to only use exceptions for exceptional cases. "All" and "Quit" don't seem exceptional to me. I think I would make interactive_upgrade_request return a set of constants for all the cases, instead of returning a boolean in some cases and raising exception in others.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah, I tend to agree. ...in hindsight. I think I fell into the trap of doing it like this because I had originally not planned to use "all" and "quit" and when I added those it didn't match the way I called the interactive_upgrade_request function.

clear_line()
print_line(True)
return True
return ask()
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to put this in a loop instead of recursing. I think that makes the repetition easier to read.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Point taken. I can see how that could be used to achieve the same thing. But I kinda like it as a function like that. Perhaps it fits my brain better.

hashin.py Outdated
sys.stdout.write("\033[K") # Clear to the end of line

def ask():
answer = input("Update? [Y/n/a/q]: ").lower().strip()
Copy link
Contributor

Choose a reason for hiding this comment

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

As a nifty improvement, it would be cool to add "?" to the list of options, and if ? or an invalid choice is given, it prints a longer version of this prompt out, like:

y - Include this upgrade (default)
n - Skip this upgrade
a - Include this and all following upgrades
q - Skip this and all following upgrades
? - Print this help

You can see a similar UI in git add -i, which prompts you to include, skip, edit, etc chunks of files.

Copy link
Owner Author

Choose a reason for hiding this comment

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

+1

@peterbe
Copy link
Owner Author

peterbe commented Nov 2, 2018

Sigh. I've stumbled on a bug when working on that feedback.

In an old requirements.txt file I had, I had it entered as discogs_client==2.2.1 but it appears that that's been renamed all of a sudden to discogs-client.

I already had some code in place to deal with case insensitivity. E.g. if you had DjAnGo==2.1.2 in your requirements file it shouldn't barf.

What should happen in this case, if I chose to press "Y" to upgrade to that discogs* package, it should not only replace the version and the hashes but also the name.

Back to the drawingboard a bit.

@peterbe
Copy link
Owner Author

peterbe commented Nov 8, 2018

@mythmon Wanna take a last look? The recent changes are quite insignificant. In particular, I discovered a bug in my first attempt where if you had some-package=1.2.3 in your requirements file but, over time, that package has been renamed (301 in Pypi JSON lingo) to other-package then my it wouldn't work. Now it works and there are unit tests for that too.

The other thing I changed was that I add the "?" option to the prompt. Thank you. Also, I changed it so that if you do say "A" ("all") it will "keep the interactive", but not ask any more questions. That way you can clearly see which packages can be updated and what they get updated to.

Copy link
Contributor

@mythmon mythmon left a comment

Choose a reason for hiding this comment

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

This looks good to me now. The new changes look good.

@peterbe peterbe merged commit c8b10e1 into master Nov 8, 2018
@peterbe peterbe deleted the 90-update-all-and-interactive branch November 8, 2018 20:32
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.

2 participants