-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
Conversation
Hello @zulip/server-hotkeys members, this pull request was labeled with the "area: hotkeys" label, so you may want to check it out! |
There was a problem hiding this 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 👍
eb072a3
to
5901013
Compare
There was a problem hiding this 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.
79de909
to
0c8ed4b
Compare
To generate the hotkey section exactly as before, a few minor adjustments may be needed in the keys.py file. |
tools/generate_hotkey.py
Outdated
} | ||
for category in HELP_CATEGORIES.keys() | ||
} | ||
OUTPUT_FILE = "docs/hotkey.md" |
There was a problem hiding this comment.
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.
@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. |
Updated links to hot keys section in setup.py and README. Removed repeated navigation tips at the end of hot keys section.
0c8ed4b
to
040f97c
Compare
There was a problem hiding this 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?
zulipterminal/config/keys.py
Outdated
@@ -22,7 +22,7 @@ class KeyBinding(TypedDict, total=False): | |||
'key_category': 'general', | |||
}), | |||
('ABOUT', { | |||
'keys': ['meta ?'], |
There was a problem hiding this comment.
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.
tools/generate_hotkey.py
Outdated
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) |
There was a problem hiding this comment.
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.
tools/generate_hotkey.py
Outdated
} | ||
for category in HELP_CATEGORIES.keys() | ||
} | ||
OUTPUT_FILE = Path(__file__).parent.parent.joinpath('docs', 'hotkeys.md') |
There was a problem hiding this comment.
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
.
tools/generate_hotkey.py
Outdated
mdFile.write("<!--- Generated automatically by tools/generate_hotkey.py -->\n" | ||
+ "<!--- Do not modify -->\n" | ||
+ "\n# Hot Keys\n") |
There was a problem hiding this comment.
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 +
:)
tools/generate_hotkey.py
Outdated
for key_combination in key_combinations_list: | ||
new_key_list = key_combination.split() | ||
new_key_list = [ | ||
"<kbd>" + key + "</kbd>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fstring?
tools/generate_hotkey.py
Outdated
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fstring?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
040f97c
to
17394b9
Compare
@zulipbot add "PR needs review" |
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.
17394b9
to
b55adac
Compare
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 |
@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 🎉 |
Fixes #126