Skip to content

Commit d60cfbb

Browse files
committed
Minor tweaks
1 parent a4a82ab commit d60cfbb

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

AICONTEXT.md renamed to AICONTEXT-PYLIB.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Additional context on this repository for AI tools & coding agents
1+
Additional context on this project for AI tools & coding agents
22

33
- Python 3.12+ code, unless otherwise specified
44
- Python code uses single outer quotes, including triple single quotes for e.g. docstrings
@@ -10,12 +10,13 @@ Additional context on this repository for AI tools & coding agents
1010
- Try to stick to 120 characters per line
1111
- if one of those comments would break this guideline, just put that comment above the line instead, as is standard convention
1212
- If there is a pyproject.toml in place, use it as a reference for builds, installs, etc. The basic packaging and dev preference, including if you have to supply your own pyproject.toml, is as follows:
13-
- Use pyproject.toml with hatchling, not e.g. setup.py
13+
- Prefer hatchling build system over setuptools, poetry, etc. Avoid setuptools as much as possible. No setup.py.
1414
- Reusable Python code modules are developed in the `pylib` folder, and installed using e.g. `uv pip install -U .`, which includes proper mapping to Python library package namespace via `tool.hatch.build.sources`. The `__init__.py` and other modules in the top-level package go directly in `pylib`, though submodules can use subdirectories, e.g. `pylib/a/b` becomes `installed_library_name.a.b`. Ultimately this will mean the installed package is importable as `from installed_library_name.etc import …`
15-
- Yes this means editable and "dev mode" environments are NOT desirable, nor are shenanigans adding pylib to `sys.path`. Layer-efficient dockerization is an option if that's needed.
16-
- The ethos is to always develop keeping things properly installable. No dev mode shortcuts
17-
- Prefer hatchling build system over setuptools, poetry, etc. Avoid setuptools as much as possible. Use `[tool.hatch.build.sources]` to map source directories to package namespaces (e.g., `"pylib" = "installed_library_name"`).
1815
- Use `[tool.hatch.build.targets.wheel]` with `only-include = ["pylib"]` to ensure the pylib directory structure gets included properly in the wheel, avoiding the duplication issue that can occur with sources mapping
16+
- Yes this means editable and "dev mode" environments are NOT desirable, nor are shenanigans adding pylib to `sys.path`. Layer-efficient dockerization is an option if that's needed.
17+
- The ethos is to always develop keeping things properly installable. No dev mode shortcuts. Substantive modification to libray code requires e.g. `uv pip install -U .` each time.
18+
- Note: This avoidance of editable installs can be relaxed for non-library code, such as demos or main app launch scripts (e.g. webapp back ends)
19+
- If it's a CLI provided as part of a library, though, it should still use proper installation via `[project.scripts]` entry points (e.g., `ooriscout = 'ooriscout.cli.scout:main'`), which creates console scripts that work correctly after `uv pip install -U .`. The CLI module lives in `pylib/cli/` and exposes a `main()` function that uses fire to handle command-line arguments.
1920
- **Debugging package issues**: When modules aren't importing correctly after installation, check:
2021
- That you are in the correct virtualenv (you may have to ask the developer)
2122
- Package structure in site-packages (e.g., `ls -la /path/to/site-packages/package_name/`)

demo/kgraph/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ Basic `.onya` format example:
4545
* occupation: Data Scientist
4646
```
4747

48-
Key elements:
49-
- **Document header**: Declares namespaces and base URI
50-
- **Nodes**: Marked with `# NodeName [Type]`
48+
There is a document header which declares namespaces and base IRIs (URIs). Node definitions are marked with `# NodeID [Type]`. The node ID is resolved against `@document` and the type against
5149
- **Properties**: Listed with `* property: value`
5250
- **Types**: Entities can have one or more types
5351

@@ -175,7 +173,7 @@ print(response.first_choice_text)
175173
## Read-Only by Design
176174
177175
`OnyaKB` is intentionally read-only:
178-
- **insert()** and **delete()** raise `NotImplementedError`
176+
- `insert()` and `delete()` raise `NotImplementedError`
179177
- Edit `.onya` files directly using your text editor
180178
- Reload by calling `cleanup()` then `setup()` again
181179
- This design encourages human curation and version control

pylib/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020

2121
class attr_dict(dict):
22+
'''
23+
Dictionary with attribute access
24+
'''
2225
# XXX: Should unknown attr access return None rather than raise?
2326
# If so, can just do: __getattr__ = dict.get
2427
# __getattr__ = dict.__getitem__

pylib/text/html.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@
99
import re
1010
import warnings
1111

12-
# Just use tiktoken, even though it's OpenAI specific
13-
import tiktoken
14-
1512
try:
1613
import cssutils # pip install cssutils
1714
except ImportError:
1815
cssutils = None
1916
warnings.warn(
20-
'Using html_helper without cssutils, which will limit features. May want to do e.g. `pip install cssutils`')
17+
'Using html_helper without cssutils, which will limit features. Recommend e.g. `pip install cssutils`')
2118

2219
# selectolax install is optional for OgbujiPT, but mandatory for html_helper
2320
try:
2421
from selectolax.parser import HTMLParser # pip install selectolax
2522
except ImportError:
2623
HTMLParser = None
2724
warnings.warn(
28-
'Cannot use html_helper without selectolax. May want to do e.g. `pip install selectolax`')
29-
25+
'Cannot use html_helper without selectolax. Recommend e.g. `pip install selectolax`')
3026

3127

3228
HTML_SAMPLE1 = '''\
@@ -124,6 +120,8 @@ def html_split(text: str, chunk_size: int, separator: str='\n\n', joiner=None, l
124120

125121

126122
def count_tokens(text: str) -> int:
123+
# Just use tiktoken, even though it's OpenAI specific
124+
import tiktoken
127125
encoder = tiktoken.encoding_for_model('gpt-3.5-turbo')
128126
tokens = encoder.encode(text)
129127
return len(tokens)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ mega = [
8484
"docx2python",
8585
"PyPDF2",
8686
"PyCryptodome",
87+
"tiktoken",
88+
"cssutils",
89+
"selectolax",
90+
"fire",
8791
"qdrant-client",
8892
"streamlit",
8993
"watchdog",

0 commit comments

Comments
 (0)