Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
refactor: rename modules (I hope this is the last time)
Browse files Browse the repository at this point in the history
  • Loading branch information
doomspec committed Oct 10, 2023
1 parent d83c807 commit 8f6eda1
Show file tree
Hide file tree
Showing 62 changed files with 382 additions and 333 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- main
paths:
- evonote/**
- doc_in_py/**
- docinpy/**

env:
OPENAI_API_KEY: NAN
Expand Down
11 changes: 11 additions & 0 deletions docinpy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

See [DocInPy](https://evonote.org/docinpy) for a project overview.

## Project todos

- Extract variables from module and classes
- Extract comments for class variables (What should be the format of the comments?)
- Process code of function and extract comments
- TODO decorator for functions

- Serialization from structs to Python code
File renamed without changes.
2 changes: 1 addition & 1 deletion doc_in_py/comment_parser.py → docinpy/comment_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from typing import List

from doc_in_py import Struct
from docinpy import Struct

"""
This module is for parse and extract comments
Expand Down
4 changes: 2 additions & 2 deletions doc_in_py/core.py → docinpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import yaml

from doc_in_py import Struct
from doc_in_py.comment_parser import prepare_raw_comment_struct, parse_raw_comments
from docinpy import Struct
from docinpy.comment_parser import prepare_raw_comment_struct, parse_raw_comments


def get_module_members(module) -> Struct:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doc_in_py.core import get_module_members
from docinpy.core import get_module_members
from utils import to_dict


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doc_in_py.core import get_module_members
from docinpy.core import get_module_members
from utils import to_dict


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doc_in_py.core import get_module_members
from docinpy.core import get_module_members
from utils import to_dict


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doc_in_py.decorator import todo, example
from docinpy.decorator import todo, example

"""
# Todo for the function
Expand Down
2 changes: 1 addition & 1 deletion doc_in_py/test/utils.py → docinpy/test/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doc_in_py import Struct
from docinpy import Struct


def to_dict(struct: Struct):
Expand Down
4 changes: 4 additions & 0 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default defineUserConfig({
text: 'Development',
link: '/development',
},
{
text: 'DocInPy',
link: '/docinpy',
},
{
text: 'Project tree',
link: 'https://evonote.org/html/project_tree.html',
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
--c-border-dark: #dfe2e5;

// custom container colors
--c-tip: #4a8ee5;
--c-tip: #5d98e1;
--c-tip-bg: var(--c-bg-light);
--c-tip-title: var(--c-text);
--c-tip-text: var(--c-text);
Expand Down Expand Up @@ -171,7 +171,7 @@ html.dark {
--c-border-dark: #34404c;

// custom container colors
--c-tip: #318a62;
--c-tip: #5d83a8;
--c-warning: #e0ad15;
--c-warning-bg: #2d2f2d;
--c-warning-bg-light: #423e2a;
Expand Down
18 changes: 17 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
## Website development setup

Install pnpm
```shell
curl -fsSL https://get.pnpm.io/install.sh | sh -
```

Install dependencies
```shell
pnpm i
```

Dev mode for the docs
```shell
pnpm docs:dev
```

If you want to edit the sidebars: See `.vuepress/config.ts`.
## Website content development

Edit sidebars

- See `.vuepress/config.ts`.
2 changes: 1 addition & 1 deletion docs/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Docstring style: rst

## DocInPy

Please use the [DocInPy](https://github.com/EvoEvolver/EvoNote/tree/main/doc_in_py) style for adding sections in the codes.
Please use the [DocInPy](https://github.com/EvoEvolver/EvoNote/tree/main/docinpy) style for adding sections in the codes.

## Installation

Expand Down
35 changes: 23 additions & 12 deletions doc_in_py/README.md → docs/docinpy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ codebase. It is also important for AI-based agents to understand the codebase an
## EvoNote

EvoNote is using DocInPy to document its codebase. You can have a good visualization of EvoNote's codebase by
running [EvoNote visualization](https://github.com/EvoEvolver/EvoNote/blob/main/playground/visualize_paper.py).
running [EvoNote visualization](/html/project_tree.html).

## How to use

Expand Down Expand Up @@ -82,12 +82,31 @@ def baz():
pass
```

### Section in folder

You add `.tree.yml` file in a folder to add sections in it. For example, in the following folder
```
a_folder
- __init__.py
- a.py
- b.py
- c.py
- .tree.yml
```
You can put `a`,`b` in a section by putting
```yaml
sections
```




### Mark examples

You can also add examples to your functions and classes. Just use the `@example` decorator. For example,

```python
from doc_in_py.decorator import example
from docinpy.decorator import example


@example
Expand All @@ -104,7 +123,7 @@ def how_to_use_foo():
In a similar way, you can also mark todos in your code. Just use the `@todo` decorator. For example,

```python
from doc_in_py.decorator import todo
from docinpy.decorator import todo

@todo
def todo_foo():
Expand All @@ -119,14 +138,6 @@ def buggy_foo():
foo(a=b)
```

## Project todos

- Extract variables from module and classes
- Extract comments for class variables (What should be the format of the comments?)
- Process code of function and extract comments
- TODO decorator for functions

- Serialization from structs to Python code

## Philosophy behind DocInPy

Expand All @@ -143,4 +154,4 @@ structure.

DocInPy helps this by adding a zero-cost way to add sections to your functions and classes. It makes another step
towards a more tree-like structure of the codebase. We believe this will help the programmers to understand the codebase
better. See [Method of Loci](docs/introduction/2.1 Method of Loci.md) for more details.
better. See [Method of Loci](/writings/2.1%20Method%20of%20Loci%20and%20sparsity.html) for more details.
13 changes: 10 additions & 3 deletions evonote/.tree.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
sections:
core:
- notetree
Core:
- mindtree
- indexing
Auxiliary:
- file_helper
- model
- model
- gui
- testing
Applications:
- agent
- transform
- data_cleaning
6 changes: 3 additions & 3 deletions evonote/agent/general.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from evonote.notetree import Tree
from evonote.mindtree import Tree


class AgentState:
def __init__(self):
self.root_notetree = Tree(
"root notetree that indexes all available notetrees")
self.root_tree = Tree(
"root tree that indexes all available trees")
self.objective_stack = []
self.logs = []
14 changes: 7 additions & 7 deletions evonote/gui/notetree.py → evonote/gui/mindtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from evonote.gui.utlis import hypenate_texts

if TYPE_CHECKING:
from evonote.notetree import Note, Tree
from evonote.mindtree import Note, Tree

h_en = Hyphenator('en_US')

Expand Down Expand Up @@ -52,12 +52,12 @@ def get_json_for_treemap(root: Note):


def prepare_tree_parameters(root):
notetree = root.notetree
mindtree = root.tree
labels = []
parents = []
texts = []
ids = []
add_note_to_list(labels, parents, texts, ids, root, notetree)
add_note_to_list(labels, parents, texts, ids, root, mindtree)
line_width = 40
for i in range(len(texts)):
if len(texts[i].strip()) == 0:
Expand All @@ -67,15 +67,15 @@ def prepare_tree_parameters(root):
return ids, labels, parents, texts


def add_note_to_list(labels, parents, values, ids, note: Note, notetree: Tree):
def add_note_to_list(labels, parents, values, ids, note: Note, mindtree: Tree):
i = 1
children = notetree.get_children_dict(note)
children = mindtree.get_children_dict(note)
for key, child in children.items():
notepath = notetree.get_note_path(child)
notepath = mindtree.get_note_path(child)
label = str(i) + ". " + key if len(children) > 1 else key
labels.append(label)
parents.append("/".join(notepath[:-1]))
values.append(child.content)
ids.append("/".join(notepath))
add_note_to_list(labels, parents, values, ids, child, notetree)
add_note_to_list(labels, parents, values, ids, child, mindtree)
i += 1
2 changes: 1 addition & 1 deletion evonote/indexing/code_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from evonote.indexing.core import AbsEmbeddingIndexer, Indexing
from evonote.notetree import Note
from evonote.mindtree import Note


class CodeParameterIndexer(AbsEmbeddingIndexer):
Expand Down
18 changes: 9 additions & 9 deletions evonote/indexing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from evonote.model.chat import Chat

if TYPE_CHECKING:
from evonote.notetree import Note
from evonote.notetree import Tree
from evonote.mindtree import Note
from evonote.mindtree import Tree

from evonote.file_helper.cache_manage import save_cache, cached_function
from evonote.model.openai import get_embeddings
Expand Down Expand Up @@ -41,11 +41,11 @@ def remove_note(cls, note: Note):

class Indexing:
def __init__(self, notes: List[Note], indexer: Type[Indexer],
notetree: Tree):
tree: Tree):
self.notes_without_indexer: List[Note] = notes[:]
self.indexer: Type[Indexer] = indexer
self.data: Any = None
self.notetree = notetree
self.tree = tree

def add_new_note(self, note: Note):
self.notes_without_indexer.append(note)
Expand Down Expand Up @@ -223,7 +223,7 @@ class FragmentedEmbeddingIndexer(AbsEmbeddingIndexer):
def process_note_with_content(cls, notes: List[Note], indexing: Indexing,
):
notes_content = [note.content for note in notes]
notetree = indexing.notetree
tree = indexing.tree

new_src_list = []
new_weights = []
Expand All @@ -233,9 +233,9 @@ def process_note_with_content(cls, notes: List[Note], indexing: Indexing,
executor.map(process_sent_into_frags, notes_content)):
new_src = []
new_src.extend(frags)
note_path = notetree.get_note_path(note)
note_path = tree.get_note_path(note)
if len(note_path) > 0:
new_src.append(notetree.get_note_path(note)[-1])
new_src.append(tree.get_note_path(note)[-1])
new_src.append(note.content)

new_src_list.append(new_src)
Expand Down Expand Up @@ -274,13 +274,13 @@ def process_note_without_content(cls, notes: List[Note], indexing: Indexing,
def prepare_src_weight_list(cls, new_notes: List[Note], indexing: Indexing,
):

notetree = indexing.notetree
tree = indexing.tree
notes_with_content = []
notes_content = []
notes_without_content = []
for note in new_notes:
if len(note.content) == 0:
keywords_on_path = notetree.get_note_path(note)
keywords_on_path = tree.get_note_path(note)
if len(keywords_on_path) != 0:
notes_without_content.append(note)
continue
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions evonote/notetree/analysis.py → evonote/mindtree/analysis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from evonote.notetree import Tree
from evonote.mindtree import Tree


def analyze_notetree_sparsity(notetree: Tree):
def analyze_tree_sparsity(tree: Tree):
"""
Return the average number of children per note.
"""
notes = notetree.get_note_list()
notes = tree.get_note_list()
max_children = -1
total_children = 0
n_non_leaf_notes = 0
Expand All @@ -16,7 +16,7 @@ def analyze_notetree_sparsity(notetree: Tree):
total_children += n_children
max_children = max(max_children, n_children)
average_children = total_children / n_non_leaf_notes
heavy_notes = get_children_heavy_notes(notetree)
heavy_notes = get_children_heavy_notes(tree)
print("Total_notes:", len(notes))
print("Average children per non-leaf note:", average_children)
print("Max children per note:", max_children)
Expand All @@ -27,11 +27,11 @@ def analyze_notetree_sparsity(notetree: Tree):
print("Content:", note.content)
print("")

def get_children_heavy_notes(notetree: Tree, min_children=8):
def get_children_heavy_notes(tree: Tree, min_children=8):
"""
Return a list of notes with at least min_children children.
"""
notes = notetree.get_note_list()
notes = tree.get_note_list()
heavy_notes = []
for note in notes:
n_children = len(note.children())
Expand Down
Loading

0 comments on commit 8f6eda1

Please sign in to comment.