Understanding a large code base?

78 views
Skip to first unread message

The Living Cosmos

unread,
Oct 16, 2019, 6:04:07 PM10/16/19
to leo-editor
There was a comment somewhere on the Leo website about Ed's methodology to understand a large codebase. It said something like:

"I create a new git repo and import all the files using @clean" or something like that.

If anyone could point me to this information, I would appreciate it.

Matt Wilkie

unread,
Oct 17, 2019, 12:33:08 AM10/17/19
to leo-editor
Edward will likely chime in soon, but an intermediate method is enable the active_path plugin.

After restarting Leo, create and select a node with "@path some/place"  and see 'Plugins >> Active path' menu.
Recognized file types will open with @auto or @asis when double-clicked.

(@clean is better and safer in my opinion, so before diving too deep wait for the time and battle tested method.)

-matt

Edward K. Ream

unread,
Oct 17, 2019, 6:48:24 AM10/17/19
to leo-editor
On Wed, Oct 16, 2019 at 5:04 PM The Living Cosmos <thequie...@gmail.com> wrote:

There was a comment somewhere on the Leo website about Ed's methodology to understand a large code​ ​base. It said something like:

"I create a new git repo and import all the files using @clean" or something like that.

If anyone could point me to this information, I would appreciate it.

​The general ideas are as you remember:

1. Use git to manage the code you want to study.  This is optional, but highly recommended if you want to change the code.  That way you sure what changes you made.

2. Use a recursive import script to import the files of interest into Leo.  This will simply call c.recursiveImport.  The docstring is:

"""
Recursively import all python files in a directory and clean the results.

Parameters::
    dir_              The root directory or file to import.
    kind              One of ('@clean','@edit','@file','@nosent').
    add_path=True     True: add a full @path directive to @<file> nodes.
    recursive=True    True: recurse into subdirectories.
    safe_at_file=True True: produce @@file nodes instead of @file nodes.
    theTypes=None     A list of file extensions to import.
                      None is equivalent to ['.py']

This method cleans imported files as follows:

- Replace backslashes with forward slashes in headlines.
- Remove empty nodes.
- Add @path directives that reduce the needed path specifiers in descendant nodes.
- Add @file to nodes or replace @file with @@file.
"""

An example script is:

'''Recursively import all python files in a directory and clean the result.'''
@tabwidth -4 # For a better match.
dir_
= r'path-to-a-folder'
g
.cls()
c
.recursiveImport(
    dir_
=dir_,
    kind
= '@clean', # '@auto', '@clean', '@nosent','@file',
    add_path
= True,
    recursive
= False,
    safe_at_file
= False,
    theTypes
= ['.py',] #
)

If you set safe_at_file to True, the script will general @@clean instead of @clean, so you won't have to worry about changing the original sources.  Having said that, it's very useful to be able to change the code you want to study!

HTH.

Edward
Reply all
Reply to author
Forward
0 new messages