meter-lib 0.0.2__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.
Potentially problematic release.
This version of meter-lib might be problematic. Click here for more details.
- meter_lib-0.0.2/.github/workflows/publish.yml +156 -0
- meter_lib-0.0.2/.gitignore +9 -0
- meter_lib-0.0.2/PKG-INFO +19 -0
- meter_lib-0.0.2/README.md +1 -0
- meter_lib-0.0.2/meter_lib/__init__.py +1 -0
- meter_lib-0.0.2/meter_lib/core.py +56 -0
- meter_lib-0.0.2/pyproject.toml +29 -0
- meter_lib-0.0.2/requirements.txt +1 -0
- meter_lib-0.0.2/setup.py +44 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
name: Publish Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
uses: actions/setup-python@v4
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: |
|
|
25
|
+
python -m pip install --upgrade pip
|
|
26
|
+
pip install -r requirements.txt
|
|
27
|
+
pip install pytest pytest-cov flake8
|
|
28
|
+
|
|
29
|
+
- name: Lint with flake8
|
|
30
|
+
run: |
|
|
31
|
+
# Stop the build if there are Python syntax errors or undefined names
|
|
32
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
33
|
+
# Exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
|
34
|
+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
|
35
|
+
|
|
36
|
+
- name: Test with pytest (if tests exist)
|
|
37
|
+
run: |
|
|
38
|
+
if [ -d "tests" ] || [ -f "test_*.py" ]; then
|
|
39
|
+
pytest
|
|
40
|
+
else
|
|
41
|
+
echo "No tests found, skipping test step"
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
publish:
|
|
45
|
+
needs: test
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
with:
|
|
52
|
+
fetch-depth: 0 # Fetch all history for tags
|
|
53
|
+
token: ${{ secrets.PAT_TOKEN }}
|
|
54
|
+
ref: main
|
|
55
|
+
|
|
56
|
+
- name: Set up Python
|
|
57
|
+
uses: actions/setup-python@v4
|
|
58
|
+
with:
|
|
59
|
+
python-version: "3.9"
|
|
60
|
+
|
|
61
|
+
- name: Extract version from release
|
|
62
|
+
id: get_version
|
|
63
|
+
run: |
|
|
64
|
+
if [ "${{ github.event_name }}" = "release" ]; then
|
|
65
|
+
VERSION="${{ github.event.release.tag_name }}"
|
|
66
|
+
echo "Version from release: $VERSION"
|
|
67
|
+
else
|
|
68
|
+
# For manual workflow dispatch, use latest tag
|
|
69
|
+
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.1.0")
|
|
70
|
+
echo "Version from git tag: $VERSION"
|
|
71
|
+
fi
|
|
72
|
+
# Remove 'v' prefix if present
|
|
73
|
+
VERSION=$(echo "$VERSION" | sed 's/^v//')
|
|
74
|
+
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
|
|
75
|
+
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
76
|
+
echo "Clean version: $VERSION"
|
|
77
|
+
|
|
78
|
+
- name: Update version in setup.py and pyproject.toml
|
|
79
|
+
run: |
|
|
80
|
+
echo "Updating versions to: ${{ env.PACKAGE_VERSION }}"
|
|
81
|
+
|
|
82
|
+
# Update setup.py version
|
|
83
|
+
sed -i 's/version="[^"]*"/version="${{ env.PACKAGE_VERSION }}"/' setup.py
|
|
84
|
+
|
|
85
|
+
# Update pyproject.toml version
|
|
86
|
+
sed -i 's/version = "[^"]*"/version = "${{ env.PACKAGE_VERSION }}"/' pyproject.toml
|
|
87
|
+
|
|
88
|
+
# Verify the changes
|
|
89
|
+
echo "Updated setup.py version line:"
|
|
90
|
+
grep 'version=' setup.py
|
|
91
|
+
echo "Updated pyproject.toml version line:"
|
|
92
|
+
grep 'version =' pyproject.toml
|
|
93
|
+
|
|
94
|
+
- name: Commit version update to main branch
|
|
95
|
+
if: github.event_name == 'release'
|
|
96
|
+
run: |
|
|
97
|
+
# Configure git
|
|
98
|
+
git config --global user.name "github-actions[bot]"
|
|
99
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
100
|
+
|
|
101
|
+
# Configure git to use the PAT token
|
|
102
|
+
# git remote set-url origin https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git
|
|
103
|
+
|
|
104
|
+
# Check if there are changes to commit
|
|
105
|
+
if git diff --quiet setup.py pyproject.toml; then
|
|
106
|
+
echo "No changes to version files, skipping commit"
|
|
107
|
+
else
|
|
108
|
+
echo "Committing version update to main branch"
|
|
109
|
+
git add setup.py pyproject.toml
|
|
110
|
+
git commit -m "chore: update version to ${{ env.PACKAGE_VERSION }} [skip ci]"
|
|
111
|
+
|
|
112
|
+
# Push to main branch
|
|
113
|
+
git push origin HEAD:main
|
|
114
|
+
echo "Successfully pushed version update to main branch"
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
- name: Install build dependencies
|
|
118
|
+
run: |
|
|
119
|
+
python -m pip install --upgrade pip
|
|
120
|
+
pip install build twine
|
|
121
|
+
|
|
122
|
+
- name: Display version info
|
|
123
|
+
run: |
|
|
124
|
+
echo "Building package with version: ${{ env.PACKAGE_VERSION }}"
|
|
125
|
+
python setup.py --version
|
|
126
|
+
|
|
127
|
+
- name: Build package
|
|
128
|
+
run: python -m build
|
|
129
|
+
|
|
130
|
+
- name: Check built package
|
|
131
|
+
run: twine check dist/*
|
|
132
|
+
|
|
133
|
+
- name: Publish to Test PyPI
|
|
134
|
+
if: github.event_name == 'workflow_dispatch'
|
|
135
|
+
env:
|
|
136
|
+
TWINE_USERNAME: __token__
|
|
137
|
+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
|
138
|
+
run: |
|
|
139
|
+
twine upload --repository testpypi dist/*
|
|
140
|
+
|
|
141
|
+
- name: Publish to PyPI
|
|
142
|
+
if: github.event_name == 'release'
|
|
143
|
+
env:
|
|
144
|
+
TWINE_USERNAME: __token__
|
|
145
|
+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
|
|
146
|
+
run: |
|
|
147
|
+
echo "Checking if PYPI_API_TOKEN is set..."
|
|
148
|
+
if [ -z "$TWINE_PASSWORD" ]; then
|
|
149
|
+
echo "ERROR: PYPI_API_TOKEN secret is not set!"
|
|
150
|
+
exit 1
|
|
151
|
+
else
|
|
152
|
+
echo "PYPI_API_TOKEN is set (length: ${#TWINE_PASSWORD})"
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
echo "Uploading to PyPI..."
|
|
156
|
+
twine upload dist/* --verbose
|
meter_lib-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meter-lib
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A litewave library to collect the customer credit usage
|
|
5
|
+
Project-URL: Homepage, https://github.com/aiorch/meter-lib
|
|
6
|
+
Project-URL: Repository, https://github.com/aiorch/meter-lib
|
|
7
|
+
Project-URL: Issues, https://github.com/aiorch/meter-lib/issues
|
|
8
|
+
Author-email: Sruthi <sruthi@litewave.ai>
|
|
9
|
+
License: MIT
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: requests>=2.28
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# meter-lib
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# meter-lib
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import fetch_customer_id, post_meter_usage
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
def fetch_customer_id(tenant_id: str):
|
|
4
|
+
"""
|
|
5
|
+
Fetch the customer account for a given tenant_id.
|
|
6
|
+
Returns a dict with customer info, or None if not found/error.
|
|
7
|
+
"""
|
|
8
|
+
url = f"http://metering.metering.svc.cluster.local:8000/api/v1/customer-accounts/tenant/{tenant_id}"
|
|
9
|
+
try:
|
|
10
|
+
response = requests.get(url, timeout=10)
|
|
11
|
+
response.raise_for_status()
|
|
12
|
+
data = response.json()
|
|
13
|
+
|
|
14
|
+
# Handle list response
|
|
15
|
+
if isinstance(data, list) and len(data) > 0:
|
|
16
|
+
return data[0]
|
|
17
|
+
elif isinstance(data, dict):
|
|
18
|
+
return data
|
|
19
|
+
else:
|
|
20
|
+
print(f"No customer account found for tenant {tenant_id}")
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
except requests.RequestException as e:
|
|
24
|
+
print(f"Error fetching {url}: {e}")
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def post_meter_usage(tenant_id: str, device_id: str, meter_id: str, total_usage: int) :
|
|
29
|
+
"""
|
|
30
|
+
Posts meter usage to the events API.
|
|
31
|
+
Uses tenant_id + device_id in headers and includes customer_id in payload.
|
|
32
|
+
"""
|
|
33
|
+
customer_account = fetch_customer_id(tenant_id)
|
|
34
|
+
if not customer_account:
|
|
35
|
+
print("No customer account available, skipping meter usage post")
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
url = "http://metering.metering.svc.cluster.local:8000/api/v1/events"
|
|
39
|
+
headers = {
|
|
40
|
+
"x-tenant-id": tenant_id,
|
|
41
|
+
"x-device-id": device_id,
|
|
42
|
+
"Content-Type": "application/json"
|
|
43
|
+
}
|
|
44
|
+
payload = {
|
|
45
|
+
"meter_id": meter_id,
|
|
46
|
+
"total_usage": total_usage,
|
|
47
|
+
"customer_id": customer_account["id"]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
response = requests.post(url, headers=headers, json=payload, timeout=10)
|
|
52
|
+
response.raise_for_status()
|
|
53
|
+
return response.json()
|
|
54
|
+
except requests.RequestException as e:
|
|
55
|
+
print(f" Error posting to {url}: {e}")
|
|
56
|
+
return None
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "meter-lib"
|
|
7
|
+
version = "0.0.2"
|
|
8
|
+
description = "A litewave library to collect the customer credit usage"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Sruthi", email = "sruthi@litewave.ai" }
|
|
13
|
+
]
|
|
14
|
+
license = { text = "MIT" }
|
|
15
|
+
dependencies = [
|
|
16
|
+
"requests>=2.28"
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/aiorch/meter-lib"
|
|
28
|
+
Repository = "https://github.com/aiorch/meter-lib"
|
|
29
|
+
Issues = "https://github.com/aiorch/meter-lib/issues"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28
|
meter_lib-0.0.2/setup.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
# Read the README file for the long description
|
|
4
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
5
|
+
long_description = fh.read()
|
|
6
|
+
|
|
7
|
+
# Read the requirements file
|
|
8
|
+
with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|
9
|
+
requirements = [line.strip() for line in fh.readlines() if line.strip() and not line.startswith("#")]
|
|
10
|
+
|
|
11
|
+
setup(
|
|
12
|
+
name="meter-lib",
|
|
13
|
+
version="0.0.2",
|
|
14
|
+
author="Sruthi R",
|
|
15
|
+
author_email="sruthi@litewave.ai",
|
|
16
|
+
description="A litewave library to collect the customer credit usage",
|
|
17
|
+
long_description=long_description,
|
|
18
|
+
long_description_content_type="text/markdown",
|
|
19
|
+
url="https://github.com/aiorch/meter-lib",
|
|
20
|
+
packages=find_packages(),
|
|
21
|
+
classifiers=[
|
|
22
|
+
"Development Status :: 3 - Alpha",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Topic :: System :: Logging",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"Operating System :: OS Independent",
|
|
33
|
+
],
|
|
34
|
+
python_requires=">=3.7",
|
|
35
|
+
install_requires=requirements,
|
|
36
|
+
keywords="customer credit usage ",
|
|
37
|
+
project_urls={
|
|
38
|
+
"Bug Reports": "https://github.com/aiorch/meter-lib/issues",
|
|
39
|
+
"Source": "https://github.com/aiorch/meter-lib",
|
|
40
|
+
"Documentation": "https://github.com/aiorch/meter-lib#readme",
|
|
41
|
+
},
|
|
42
|
+
include_package_data=True,
|
|
43
|
+
zip_safe=False,
|
|
44
|
+
)
|