HowdenCommonObjects 0.1.0__tar.gz → 1.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.
@@ -0,0 +1,9 @@
1
+ .idea
2
+ .env
3
+ dist
4
+ uv.lock
5
+
6
+ nul
7
+ *.iml
8
+
9
+ __pycache__
@@ -7,4 +7,4 @@ T = TypeVar("T")
7
7
  @dataclass
8
8
  class HowdenResult(Generic[T]):
9
9
  result: T
10
- usage: Optional[Usage] = None
10
+ usage: Usage | list[Usage] | None = None
@@ -0,0 +1,21 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional, Literal
3
+
4
+ @dataclass
5
+ class Usage:
6
+ type: Literal["llm","parser"]
7
+ project: str = "Development"
8
+ provider: str | None = None
9
+ model: str | None = None
10
+ operation: str | None = None
11
+ input_tokens: int | None = None
12
+ cached_tokens: int | None = None
13
+ output_tokens: int | None = None
14
+ pages: int | None = None
15
+
16
+ def __repr__(self):
17
+ res = "\n"
18
+ res += f"{self.__class__.__name__}:"
19
+ for k,v in vars(self).items():
20
+ res += f"\n ├─ {k}: {v}"
21
+ return res
@@ -1,8 +1,11 @@
1
- Metadata-Version: 2.4
2
- Name: HowdenCommonObjects
3
- Version: 0.1.0
4
- Summary: A simple configuration manager with Pydantic and JSON export.
5
- Author-email: Casper Bresdahl <casper.bresdahl@howdendanmark.dk>
6
- License: MIT
7
- Requires-Python: <3.14,>=3.12
8
- Description-Content-Type: text/markdown
1
+ Metadata-Version: 2.5
2
+ Name: HowdenCommonObjects
3
+ Version: 1.1.0
4
+ Summary: A simple configuration manager with Pydantic and JSON export.
5
+ Author-email: Casper Bresdahl <casper.bresdahl@howdendanmark.dk>
6
+ License: MIT
7
+ Requires-Python: <3.14,>=3.12
8
+ Description-Content-Type: text/markdown
9
+
10
+ # Common objects and dependencies for Howden pakages
11
+
@@ -0,0 +1,2 @@
1
+ # Common objects and dependencies for Howden pakages
2
+
@@ -0,0 +1,195 @@
1
+ param (
2
+ [switch]$help
3
+ )
4
+
5
+ # --- Functions ---
6
+
7
+ function Show-Help {
8
+ Write-Host @"
9
+ HowdenParser Build Script
10
+
11
+ Usage:
12
+ .\build.ps1 [--patch|--minor|--major] [--help|-h]
13
+
14
+ Options:
15
+ --patch Bump patch version
16
+ --minor Bump minor version
17
+ --major Bump major version
18
+ --help Show this help message
19
+ -h Alias for --help
20
+ "@
21
+ exit 0
22
+ }
23
+
24
+ function Load-Token {
25
+ Write-Host "Loading PyPI token from .env..."
26
+ $token = (Get-Content .env | ForEach-Object {
27
+ if ($_ -match "^PYPI_TOKEN=(.*)$") { $matches[1] }
28
+ })
29
+
30
+ if (-not $token) {
31
+ Write-Error "No PYPI_TOKEN found in .env"
32
+ exit 1
33
+ }
34
+
35
+ $env:UV_PUBLISH_TOKEN = $token
36
+ Write-Host "Token loaded."
37
+ }
38
+
39
+ function Get-Version {
40
+ $tomlPath = "pyproject.toml"
41
+ if (-not (Test-Path $tomlPath)) {
42
+ Write-Error "pyproject.toml not found"
43
+ exit 1
44
+ }
45
+
46
+ $content = Get-Content $tomlPath -Raw
47
+ if ($content -match 'version\s*=\s*"([^"]+)"') {
48
+ return $matches[1]
49
+ } else {
50
+ Write-Error "Version not found in pyproject.toml"
51
+ exit 1
52
+ }
53
+ }
54
+
55
+ function Validate-Git {
56
+ # Check we're on main or master
57
+ $currentBranch = git rev-parse --abbrev-ref HEAD
58
+ if ($currentBranch -ne "main" -and $currentBranch -ne "master") {
59
+ Write-Error "You must be on 'main' or 'master' to publish. Current branch: $currentBranch"
60
+ exit 1
61
+ }
62
+
63
+ # Check for uncommitted changes
64
+ $status = (git status --porcelain) | Out-String
65
+ if ($status.Trim().Length -gt 0) {
66
+ Write-Error "You have uncommitted changes. Please commit or stash them before publishing."
67
+ exit 1
68
+ }
69
+
70
+ Write-Host "Git validation passed." -ForegroundColor Green
71
+ }
72
+
73
+ function Bump-Version {
74
+ param (
75
+ [string]$type
76
+ )
77
+
78
+ if (-not $type) {
79
+ Write-Error "No bump type specified. Use --patch, --minor, or --major."
80
+ exit 1
81
+ }
82
+
83
+ Write-Host "Bumping version ($type)..."
84
+ uv run bump_version.py --$type
85
+ if ($LASTEXITCODE -ne 0) {
86
+ Write-Error "Version bump failed."
87
+ exit 1
88
+ }
89
+ $newVersion = Get-Version
90
+ Write-Host "Version updated to $newVersion" -ForegroundColor Green
91
+ }
92
+
93
+ function Build {
94
+ # Clean old build artifacts
95
+ Write-Host "Cleaning old build artifacts..."
96
+ if (Test-Path "dist") {
97
+ Remove-Item -Recurse -Force "dist"
98
+ Write-Host "Cleaned dist/ folder." -ForegroundColor Green
99
+ }
100
+
101
+ Write-Host "Building package with uv..."
102
+ uv build
103
+ if ($LASTEXITCODE -ne 0) {
104
+ Write-Error "Build failed. Aborting."
105
+ exit 1
106
+ }
107
+ Write-Host "Build succeeded." -ForegroundColor Green
108
+ }
109
+
110
+ function Publish {
111
+ Load-Token
112
+ Write-Host "Publishing package with uv..."
113
+ uv publish
114
+ if ($LASTEXITCODE -ne 0) {
115
+ Write-Error "Publish failed. Aborting."
116
+ exit 1
117
+ }
118
+ Write-Host "Publish succeeded." -ForegroundColor Green
119
+ }
120
+
121
+ function GitPushAndTag {
122
+ $version = Get-Version
123
+ $currentBranch = git rev-parse --abbrev-ref HEAD
124
+
125
+ Write-Host "Committing version bump to $version..."
126
+ git add pyproject.toml
127
+ git commit -m "Release version $version"
128
+ if ($LASTEXITCODE -ne 0) {
129
+ Write-Error "Git commit failed."
130
+ exit 1
131
+ }
132
+
133
+ Write-Host "Pushing to $currentBranch..."
134
+ git push origin $currentBranch
135
+ if ($LASTEXITCODE -ne 0) {
136
+ Write-Error "Git push failed."
137
+ exit 1
138
+ }
139
+
140
+ Write-Host "Tagging version v$version..."
141
+ git tag -a "v$version" -m "Release version $version"
142
+ git push origin "v$version"
143
+ if ($LASTEXITCODE -ne 0) {
144
+ Write-Error "Git tag push failed."
145
+ exit 1
146
+ }
147
+
148
+ Write-Host "Code pushed and tagged as v$version successfully!" -ForegroundColor Green
149
+ }
150
+
151
+ # --- Parse command line arguments ---
152
+ $bump = $null
153
+ $helpFlag = $false
154
+
155
+ foreach ($arg in $args) {
156
+ switch ($arg) {
157
+ "--patch" {
158
+ if ($bump) { Write-Error "Only one of --patch, --minor, or --major is allowed."; exit 1 }
159
+ $bump = "patch"
160
+ }
161
+ "--minor" {
162
+ if ($bump) { Write-Error "Only one of --patch, --minor, or --major is allowed."; exit 1 }
163
+ $bump = "minor"
164
+ }
165
+ "--major" {
166
+ if ($bump) { Write-Error "Only one of --patch, --minor, or --major is allowed."; exit 1 }
167
+ $bump = "major"
168
+ }
169
+ "-h" { $helpFlag = $true }
170
+ "--help" { $helpFlag = $true }
171
+ default {
172
+ Write-Host "Unknown target: $arg"
173
+ Write-Host "Available targets: --patch, --minor, --major, --help, -h"
174
+ exit 1
175
+ }
176
+ }
177
+ }
178
+
179
+ if (-not $helpFlag -and -not $bump) {
180
+ Write-Host "Error: You must provide one of the following options: --patch, --minor, --major, --help, or -h"
181
+ exit 1
182
+ }
183
+
184
+ if ($helpFlag) {
185
+ Show-Help
186
+ }
187
+
188
+ # --- Main execution ---
189
+ Write-Host "Starting build process..." -ForegroundColor Cyan
190
+ Validate-Git # 1. Validate branch + clean working tree
191
+ Bump-Version $bump # 2. Bump version first
192
+ Build # 3. Clean dist/ and build with new version
193
+ Publish # 4. Publish to PyPI
194
+ GitPushAndTag # 5. Commit + push + tag the new version
195
+ Write-Host "All done!" -ForegroundColor Green
@@ -0,0 +1,44 @@
1
+ import sys
2
+ import re
3
+
4
+ pyproject = "pyproject.toml"
5
+
6
+ def bump_version(version: str, bump_type: str) -> str:
7
+ major, minor, patch = map(int, version.split("."))
8
+ if bump_type == "patch":
9
+ patch += 1
10
+ elif bump_type == "minor":
11
+ minor += 1
12
+ patch = 0
13
+ elif bump_type == "major":
14
+ major += 1
15
+ minor = 0
16
+ patch = 0
17
+ else:
18
+ print(f"Unknown argument: --{bump_type}")
19
+ return version
20
+ return f"{major}.{minor}.{patch}"
21
+
22
+ # Read the bump type from command line argument
23
+ if len(sys.argv) > 1:
24
+ arg = sys.argv[1].lstrip("-")
25
+ else:
26
+ arg = "patch"
27
+
28
+ with open(pyproject, "r", encoding="utf-8") as f:
29
+ content = f.read()
30
+
31
+ match = re.search(r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE)
32
+ if not match:
33
+ print("Could not find version in pyproject.toml")
34
+ sys.exit(1)
35
+
36
+ current_version = match.group(1)
37
+ new_version = bump_version(current_version, arg)
38
+
39
+ content = content.replace(f'version = "{current_version}"', f'version = "{new_version}"', 1)
40
+
41
+ with open(pyproject, "w", encoding="utf-8") as f:
42
+ f.write(content)
43
+
44
+ print(f"Version bumped: {current_version} → {new_version}")
@@ -1,9 +1,13 @@
1
- [project]
2
- name = "HowdenCommonObjects"
3
- version = "0.1.0"
4
- description = "A simple configuration manager with Pydantic and JSON export."
5
- authors = [{name = "Casper Bresdahl", email = "casper.bresdahl@howdendanmark.dk"}]
6
- readme = "README.md"
7
- license = {text = "MIT"}
8
- requires-python = ">=3.12,<3.14"
9
- dependencies = []
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "HowdenCommonObjects"
7
+ version = "1.1.0"
8
+ description = "A simple configuration manager with Pydantic and JSON export."
9
+ authors = [{name = "Casper Bresdahl", email = "casper.bresdahl@howdendanmark.dk"}]
10
+ readme = "README.md"
11
+ license = {text = "MIT"}
12
+ requires-python = ">=3.12,<3.14"
13
+ dependencies = []
@@ -1,38 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Optional
3
-
4
-
5
- @dataclass
6
- class Usage:
7
- llm_model: Optional[str] = None
8
- input_tokens: int = 0
9
- output_tokens: int = 0
10
- parser_model: Optional[str] = None
11
- parsing_tier: Optional[str] = None
12
- pages_parsed: int = 0
13
-
14
- def __iadd__(self, other):
15
- if not isinstance(other, Usage):
16
- raise TypeError(f"Cannot add Usage and {type(other).__name__}")
17
-
18
- for field, val in vars(self).items():
19
- other_val = getattr(other, field)
20
-
21
- if isinstance(val, int):
22
- setattr(self, field, val + other_val)
23
- elif isinstance(val, str) or val is None:
24
- if (val is None and other_val is None) or val == other_val:
25
- # Neither object has a value or equal values
26
- continue
27
- elif val is None and isinstance(other_val, str):
28
- # self is empty, so take other's value
29
- setattr(self, field, other_val)
30
- elif isinstance(val, str) and other_val is None:
31
- # self already has the value, keep it
32
- continue
33
- else:
34
- # Conflicting values
35
- raise ValueError(f"Conflicting values for {field}:{val!r} and {other_val!r}")
36
- else:
37
- raise NotImplementedError(f"Addition for type {type(val).__name__} has not been implemented.")
38
- return self
@@ -1,12 +0,0 @@
1
- pyproject.toml
2
- HowdenCommonObjects/__init__.py
3
- HowdenCommonObjects/howden_result.py
4
- HowdenCommonObjects/usage.py
5
- HowdenCommonObjects.egg-info/PKG-INFO
6
- HowdenCommonObjects.egg-info/SOURCES.txt
7
- HowdenCommonObjects.egg-info/dependency_links.txt
8
- HowdenCommonObjects.egg-info/top_level.txt
9
- howdencommonobjects.egg-info/PKG-INFO
10
- howdencommonobjects.egg-info/SOURCES.txt
11
- howdencommonobjects.egg-info/dependency_links.txt
12
- howdencommonobjects.egg-info/top_level.txt
@@ -1 +0,0 @@
1
- HowdenCommonObjects
@@ -1,8 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: HowdenCommonObjects
3
- Version: 0.1.0
4
- Summary: A simple configuration manager with Pydantic and JSON export.
5
- Author-email: Casper Bresdahl <casper.bresdahl@howdendanmark.dk>
6
- License: MIT
7
- Requires-Python: <3.14,>=3.12
8
- Description-Content-Type: text/markdown
@@ -1,4 +0,0 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-