truthcheck2 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- truthcheck2-0.1.0/.github/workflows/ci.yml +33 -0
- truthcheck2-0.1.0/.gitignore +0 -0
- truthcheck2-0.1.0/LICENSE +21 -0
- truthcheck2-0.1.0/PKG-INFO +20 -0
- truthcheck2-0.1.0/README.md +2 -0
- truthcheck2-0.1.0/pyproject.toml +42 -0
- truthcheck2-0.1.0/src/truthcheck2/__init__.py +8 -0
- truthcheck2-0.1.0/src/truthcheck2/core.py +6 -0
- truthcheck2-0.1.0/src/truthcheck2/tokenizer.py +25 -0
- truthcheck2-0.1.0/tests/__init__.py +0 -0
- truthcheck2-0.1.0/tests/test_core.py +25 -0
- truthcheck2-0.1.0/tests/test_tokenizer.py +20 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
quality:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: ${{ matrix.python-version }}
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: |
|
|
22
|
+
python -m pip install --upgrade pip
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
- name: Format & Lint
|
|
25
|
+
run: |
|
|
26
|
+
ruff format --check .
|
|
27
|
+
ruff check .
|
|
28
|
+
- name: Type check
|
|
29
|
+
run: mypy src/truthcheck
|
|
30
|
+
- name: Test
|
|
31
|
+
run: pytest
|
|
32
|
+
- name: Build
|
|
33
|
+
run: python -m build
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: truthcheck2
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A minimal utility to evaluate truthiness and count tokens.
|
|
5
|
+
Author-email: buckethq <onebucket@proton.me>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: tiktoken>=0.7.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
12
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# truthcheck
|
|
20
|
+
PyPI package structure focused on modern Python packaging standards
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "truthcheck2"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A minimal utility to evaluate truthiness and count tokens."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "buckethq", email = "onebucket@proton.me"}
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"tiktoken>=0.7.0",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
dev = [
|
|
21
|
+
"pytest>=8.0",
|
|
22
|
+
"pytest-cov>=5.0",
|
|
23
|
+
"ruff>=0.5.0",
|
|
24
|
+
"mypy>=1.10",
|
|
25
|
+
"build>=1.2",
|
|
26
|
+
"twine>=5.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[tool.ruff]
|
|
30
|
+
target-version = "py310"
|
|
31
|
+
line-length = 100
|
|
32
|
+
lint.select = ["E", "F", "I", "N", "UP", "B", "SIM", "TCH"]
|
|
33
|
+
|
|
34
|
+
[tool.mypy]
|
|
35
|
+
python_version = "3.10"
|
|
36
|
+
strict = true
|
|
37
|
+
warn_return_any = true
|
|
38
|
+
warn_unused_configs = true
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
testpaths = ["tests"]
|
|
42
|
+
addopts = "--cov=src/truthcheck --cov-report=term-missing"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import tiktoken
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def count_tokens(value: Any, model: str = "cl100k_base") -> int:
|
|
7
|
+
"""Count tokens in the string representation of any object."""
|
|
8
|
+
try:
|
|
9
|
+
encoding = tiktoken.get_encoding(model)
|
|
10
|
+
except Exception as e:
|
|
11
|
+
raise ValueError(f"Failed to load tiktoken model '{model}': {e}") from e
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
text = str(value)
|
|
15
|
+
except Exception as e:
|
|
16
|
+
raise TypeError(f"Cannot convert {type(value).__name__} to string: {e}") from e
|
|
17
|
+
|
|
18
|
+
return len(encoding.encode(text))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def print_token_count(value: Any, model: str = "cl100k_base") -> int:
|
|
22
|
+
"""Print and return the token count for any object."""
|
|
23
|
+
count = count_tokens(value, model)
|
|
24
|
+
print(f"🔢 Token count ({model}): {count}")
|
|
25
|
+
return count
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from truthcheck2.core import is_truthy
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize(
|
|
7
|
+
"value,expected",
|
|
8
|
+
[
|
|
9
|
+
(0, False),
|
|
10
|
+
(1, True),
|
|
11
|
+
("", False),
|
|
12
|
+
("hello", True),
|
|
13
|
+
([], False),
|
|
14
|
+
([1], True),
|
|
15
|
+
({}, False),
|
|
16
|
+
({"a": 1}, True),
|
|
17
|
+
(None, False),
|
|
18
|
+
(False, False),
|
|
19
|
+
(True, True),
|
|
20
|
+
(0.0, False),
|
|
21
|
+
(0.1, True),
|
|
22
|
+
],
|
|
23
|
+
)
|
|
24
|
+
def test_is_truthy(value: object, expected: bool) -> None:
|
|
25
|
+
assert is_truthy(value) is expected
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from truthcheck2.tokenizer import count_tokens, print_token_count
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_count_tokens_basic() -> None:
|
|
7
|
+
assert count_tokens("hello world") > 0
|
|
8
|
+
assert count_tokens("") == 0
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_count_tokens_non_string() -> None:
|
|
12
|
+
assert count_tokens(42) >= 1
|
|
13
|
+
assert count_tokens([1, 2, 3]) >= 1
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_print_token_count(capsys: pytest.CaptureFixture) -> None:
|
|
17
|
+
count = print_token_count("test")
|
|
18
|
+
captured = capsys.readouterr()
|
|
19
|
+
assert "🔢 Token count (cl100k_base):" in captured.out
|
|
20
|
+
assert isinstance(count, int)
|