Humans-of-Julia / HoJBot.jl

Yay, our own Discord bot!
MIT License
22 stars 11 forks source link

Improves the docstrings command `j` #81

Closed rmsrosa closed 3 years ago

rmsrosa commented 3 years ago
  1. This extends the j command to show docstrings not only from Base, keywords and from the packages in use by HoJBot, but from any desired package set up in an environment separate from HoJBot's main environment.
  2. The docstrings are generated by a separate script and saved to file, so the j command simply loads the files to retrieve the information.
  3. Besides showing the docstrings and the statistics of the names queried in the server, the j command now lists all the available packages and also shows, for each given package, all the exported and nonexported names in the package.
  4. The subcommand for showing the statistics was split up into three subcommands j stats, j top, and j bottom.
  5. Concerning the script that generates the JSON files, there is now a second environment at doc_tools/, with the script and a Project.toml. The script imports every package in the environment, including their dependencies, finds all the names in each package, retrieve their docstrings, and save the relevant info to two JSON files. Details on that info and the JSON files can be found in the docstring for the main() function in the script doc_tools/generate_docstrings.jl.
  6. One way to use the script is as follows:
    • On the shell, change the directory to doc_tools/
    • Enter the julia REPL with julia
    • Activate the local environment with ]activate .
    • Add whatever package you want, e.g. ]add Plots, DataFrames, CSV, DifferentialEquations and so on.
    • Include the script with include("generate_docstrings.jl")
    • Call the main function main().
    • After the main function is done working, you can exit the REPL and that is it. You have now two new, or updated, JSON files at data/docs/ (namely all_docs.json and all_names.json), which can be read by HoJBot when the j command is run.
    • There is no need to stop and start again the HoJBot. The files are read on the fly.

I still need to add unit tests for the j command. That is in the plans.