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

Generate hotkey using script #926

Closed
wants to merge 3 commits into from

Conversation

mkp6781
Copy link
Contributor

@mkp6781 mkp6781 commented Feb 17, 2021

Fixes #126

@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] area: documentation Requires changes in documentation area: hotkeys area: infrastructure Project infrastructure high priority should be done as soon as possible PR needs review PR requires feedback to proceed labels Feb 17, 2021
@zulipbot
Copy link
Member

Hello @zulip/server-hotkeys members, this pull request was labeled with the "area: hotkeys" label, so you may want to check it out!

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@mkp6781 This looks like a good start - I left a few comments 👍

@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Feb 17, 2021
@mkp6781 mkp6781 force-pushed the generate_hotkey_using_script branch 2 times, most recently from eb072a3 to 5901013 Compare February 18, 2021 07:20
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@mkp6781 Just had another quick look - the order of sections appears to have changed? This may change as you finalize the data structures from keys.py in any case.

@mkp6781 mkp6781 force-pushed the generate_hotkey_using_script branch 2 times, most recently from 79de909 to 0c8ed4b Compare February 23, 2021 11:00
@mkp6781
Copy link
Contributor Author

mkp6781 commented Feb 23, 2021

To generate the hotkey section exactly as before, a few minor adjustments may be needed in the keys.py file.

}
for category in HELP_CATEGORIES.keys()
}
OUTPUT_FILE = "docs/hotkey.md"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This fails if not run as tools/... - you can get the absolute path of this __file__ and look at the relative path from there. I'd suggest using pathlib in python 3.

@neiljp
Copy link
Collaborator

neiljp commented Feb 24, 2021

@mkp6781 I'm excited to have this done! 👍

We should perhaps adjust the generated file to be plural (...keys.md), and I'm not sure why we have the title capitalized; I'm not sure we do in other documentation?

Regarding your point about the difference between the files, I'd suggest adding an intermediate commit with the extra/adjusted entries.

@neiljp neiljp added this to the Next Release milestone Feb 24, 2021
Updated links to hot keys section in setup.py and README.
Removed repeated navigation tips at the end of hot keys section.
@mkp6781 mkp6781 force-pushed the generate_hotkey_using_script branch from 0c8ed4b to 040f97c Compare February 25, 2021 18:53
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@mkp6781 I hope you can already see the readability improvements from the last few iterations?

There are a few more updates we need based on the extra commit, and there are some changes to the generation script which could simplify that even further which you may be able to identify from the previous iterations. The plural form looks better, but let's change the script name to match too?

@@ -22,7 +22,7 @@ class KeyBinding(TypedDict, total=False):
'key_category': 'general',
}),
('ABOUT', {
'keys': ['meta ?'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

These changes break the application - while these are used by the help docs, urwid requires them to be in a certain format too. So, if you plan to capitalize them (do modifiers need that?) then that'll be necessary in the script instead.

I'd suggest you leave them as they are for now - I think the keys.py text is likely more up to date for the keys it has, but is missing those extra keys you've identified below.

Note that we don't support ctrl d, as it's currently the sending key. We've gone back and forth on this issue previously in the stream.

Comment on lines 26 to 35
various_key_combinations = []
for key_combination in key_combinations_list:
new_key_list = key_combination.split()
new_key_list = [
"<kbd>" + key + "</kbd>"
for key in new_key_list
]
new_key_list = " + ".join(new_key_list)
various_key_combinations.append(new_key_list)
various_key_combinations = " / ".join(various_key_combinations)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is already a lot clearer, but you may be able to see how we can simplify this even further.

}
for category in HELP_CATEGORIES.keys()
}
OUTPUT_FILE = Path(__file__).parent.parent.joinpath('docs', 'hotkeys.md')
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a good first step to use pathlib 👍

However, this doesn't also work from the tools directory (tools/generate_hotkey.py vs ./generate_hotkey.py vs zulipterminal/tools/generate_hotkey.py vs...) - you need the absolute path. Pathlib also allows clever use of / to join paths, which you might enjoy too, instead of joinpath.

Comment on lines 18 to 20
mdFile.write("<!--- Generated automatically by tools/generate_hotkey.py -->\n"
+ "<!--- Do not modify -->\n"
+ "\n# Hot Keys\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consecutive strings this can be even tidier by skipping the + :)

for key_combination in key_combinations_list:
new_key_list = key_combination.split()
new_key_list = [
"<kbd>" + key + "</kbd>"
Copy link
Collaborator

Choose a reason for hiding this comment

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

fstring?

OUTPUT_FILE = Path(__file__).parent.parent.joinpath('docs', 'hotkeys.md')

with open(OUTPUT_FILE,"w") as mdFile:
mdFile.write("<!--- Generated automatically by tools/generate_hotkey.py -->\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

fstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are not using any variables here, do we need an fstring?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The filename itself is a variable, so we can avoid adjusting this text (or part of it) when the script runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not quite follow you here. Isn't the filename a constant with the root directory as zulipterminal. A similar case can be seen in convert-unicode-emoji-data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed the change in convert-unicode-emoji-data, I've made the same change 👍🏼

Made minor changes to key_combinations and help_text in `KEY_BINDINGS`
and `HELP_CATEGORIES`. When automating generation of this section in
a later commit, this refactor enables exact matching of output keys
with current Hot Keys section in hotkeys.md.
@mkp6781 mkp6781 force-pushed the generate_hotkey_using_script branch from 040f97c to 17394b9 Compare February 26, 2021 07:31
@mkp6781
Copy link
Contributor Author

mkp6781 commented Feb 28, 2021

@zulipbot add "PR needs review"

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Feb 28, 2021
Generates markdown file hotkeys.md using `KEY_BINDINGS` and
`HELP_CATEGORIES` from `keys.py`. This ensures that changes to
command keys are reflected automatically in the documentation
when the user runs the `generate_hotkeys.py` script.

Fixes zulip#126.
@mkp6781 mkp6781 force-pushed the generate_hotkey_using_script branch from 17394b9 to b55adac Compare March 1, 2021 14:54
@zulipbot
Copy link
Member

zulipbot commented Mar 2, 2021

Heads up @mkp6781, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

@neiljp
Copy link
Collaborator

neiljp commented Mar 2, 2021

@mkp6781 Thanks for this - this exposes various cases where we weren't keeping the documents synchronized, and will make updating categories and text much easier 👍 I've just merged this with a few adjustments to the first commit due to broken links, chose to exclude/update various key data from the second, and merged the third as it was 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation Requires changes in documentation area: hotkeys area: infrastructure Project infrastructure has conflicts high priority should be done as soon as possible PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback PR needs review PR requires feedback to proceed size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate hotkeys section/doc using script and check with CI
4 participants