lsms-worldbank / adodown

Tools for building Stata package documentation websites
https://lsms-worldbank.github.io/adodown/
5 stars 0 forks source link

(Re)load all function definitions in package #31

Open arthur-shaw opened 3 months ago

arthur-shaw commented 3 months ago

Problem

When developing, one's workflow is:

To my knowledge, there's no way reload all command definitions

Ideas for implementation

Inspiration

In R, there's a function in the devtools package that does exactly this: load_all(). While it actually does more, one can basically understand it as running all of the script files that compose a package so that the function definitions contained inside are loaded in memory (and overwrite old definitions). See more in the cheatsheet here, this section of the package dev overview here, and the function docs here.

As an R user/developer, this is a function I use constantly while developing. Both because of muscle memory and some first-principles need to reload my project, I feel myself yearning for this function during Stata-based development.

Implementation

Since adodown packages have a strongly opinionated structure, couldn't we just run all ado files found in src/ado/?

If necessary or desired, perhaps one could attempt to unload definitions in memory by:

To load the definitions of commands from disk, one could probably do something like this:

* let's imagine the package root is given
local pkg_root_dir "pkg/is/here"

* construct the path to package ado directory
local pkg_ado_dir "`pkg_root_dir'/src/ado"

* collect the files in that directory
local ado_files : dir "`pkg_ado_dir'" files "*.ado"
local ado_files : list ado_files clean

* load contents of ado files into memory
foreach ado_file of local ado_files {
  include "`pkg_ado_dir'/`ado_file'"
}

Some issues