Skip to content

Commit f5c914d

Browse files
committed
complete
1 parent b521726 commit f5c914d

File tree

17 files changed

+790
-178
lines changed

17 files changed

+790
-178
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["main"]
7+
8+
jobs:
9+
tests:
10+
name: Tests (Python ${{ matrix.python-version }})
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.10", "3.11", "3.12", "3.13"]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install -e ".[dev]"
30+
31+
- name: Lint
32+
run: ruff check .
33+
34+
- name: Format check
35+
run: ruff format --check .
36+
37+
- name: Run tests
38+
run: pytest
39+
40+
package:
41+
name: Build package
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
47+
- name: Set up Python
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: "3.12"
51+
52+
- name: Build distributions
53+
run: |
54+
python -m pip install --upgrade pip
55+
python -m pip install build twine
56+
python -m build
57+
twine check dist/*
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Publish TestPyPI
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
build:
11+
name: Build distributions
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.12"
21+
22+
- name: Build
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install build
26+
python -m build
27+
28+
- name: Upload dist artifacts
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: dist
32+
path: dist/
33+
if-no-files-found: error
34+
35+
publish-testpypi:
36+
name: Publish to TestPyPI (Trusted Publisher)
37+
needs: build
38+
runs-on: ubuntu-latest
39+
environment:
40+
name: testpypi
41+
url: https://test.pypi.org/project/openinflation-dataclass/
42+
permissions:
43+
id-token: write
44+
45+
steps:
46+
- name: Download dist artifacts
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: dist
50+
path: dist/
51+
52+
- name: Publish package distributions to TestPyPI
53+
uses: pypa/gh-action-pypi-publish@release/v1
54+
with:
55+
repository-url: https://test.pypi.org/legacy/
56+
packages-dir: dist/

.github/workflows/publish.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
name: Build distributions
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Build
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install build
28+
python -m build
29+
30+
- name: Upload dist artifacts
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: dist
34+
path: dist/
35+
if-no-files-found: error
36+
37+
publish-pypi:
38+
name: Publish to PyPI (Trusted Publisher)
39+
needs: build
40+
runs-on: ubuntu-latest
41+
environment:
42+
name: pypi
43+
url: https://pypi.org/project/openinflation-dataclass/
44+
permissions:
45+
id-token: write
46+
47+
steps:
48+
- name: Download dist artifacts
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: dist
52+
path: dist/
53+
54+
- name: Publish package distributions to PyPI
55+
uses: pypa/gh-action-pypi-publish@release/v1
56+
with:
57+
packages-dir: dist/

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [0.1.0] - 2026-02-23
6+
7+
### Added
8+
- Initial PyPI-ready package structure with `pyproject.toml` and `src/` layout.
9+
- Pydantic models for cards, categories, and geolocation entities.
10+
- JSON transport helpers `to_json()` and `from_json()`.
11+
- CI workflow for linting, tests, and build validation.
12+
- Trusted Publisher workflow for PyPI release via GitHub OIDC.

README.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,123 @@
1-
# dataclass
1+
# openinflation-dataclass
2+
3+
Typed `pydantic` models for:
4+
- product cards (`Card`);
5+
- category trees (`Category`);
6+
- geolocation and retail entities (`AdministrativeUnit`, `RetailUnit`, `Schedule`).
7+
8+
The package also includes network serialization helpers:
9+
- `to_json(value)` to convert model data to transport JSON;
10+
- `from_json(payload, model)` to restore typed objects from JSON.
11+
12+
## Installation
13+
14+
```bash
15+
pip install openinflation-dataclass
16+
```
17+
18+
## Quick Start
19+
20+
```python
21+
from io import BytesIO
22+
23+
from openinflation_dataclass import (
24+
AdministrativeUnit,
25+
Card,
26+
Category,
27+
RetailUnit,
28+
Schedule,
29+
from_json,
30+
to_json,
31+
)
32+
33+
category = Category(uid="milk", alias="milk", title="Milk", adult=False)
34+
35+
card = Card(
36+
sku="SKU-001",
37+
plu="123456",
38+
source_page_url="https://example.com/product/sku-001",
39+
title="Milk 1L",
40+
description="Pasteurized milk",
41+
adult=False,
42+
new=True,
43+
promo=False,
44+
season=False,
45+
hit=True,
46+
data_matrix=True,
47+
brand="Example",
48+
producer_name="Example Foods",
49+
producer_country="RUS",
50+
composition="Milk",
51+
meta_data=[],
52+
expiration_date_in_days=10,
53+
rating=4.8,
54+
reviews_count=124,
55+
price=89.9,
56+
discount_price=79.9,
57+
loyal_price=75.9,
58+
wholesale_price=[],
59+
price_unit="RUB",
60+
unit="PCE",
61+
available_count=15,
62+
package_quantity=1.0,
63+
package_unit="LTR",
64+
categories_uid=[category.uid],
65+
main_image=BytesIO(b"main-image"),
66+
)
67+
68+
admin = AdministrativeUnit(
69+
settlement_type="city",
70+
name="Moscow",
71+
alias="moskva",
72+
country="RUS",
73+
region="Moscow",
74+
longitude=37.6176,
75+
latitude=55.7558,
76+
)
77+
78+
retail = RetailUnit(
79+
retail_type="store",
80+
code="STORE-001",
81+
address="Example st, 1",
82+
schedule_weekdays=Schedule(open_from="09:00", closed_from="22:00"),
83+
schedule_saturday=Schedule(open_from="09:00", closed_from="22:00"),
84+
schedule_sunday=Schedule(open_from="10:00", closed_from="21:00"),
85+
temporarily_closed=False,
86+
longitude=37.6176,
87+
latitude=55.7558,
88+
administrative_unit=admin,
89+
categories=[category],
90+
products=[card],
91+
)
92+
93+
payload = to_json(retail)
94+
restored = from_json(payload, RetailUnit)
95+
```
96+
97+
`BytesIO` fields are encoded as base64 strings in JSON and restored back to `BytesIO` on `from_json`.
98+
99+
## Development
100+
101+
```bash
102+
python -m pip install -e ".[dev]"
103+
ruff check .
104+
ruff format --check .
105+
pytest
106+
python -m build
107+
twine check dist/*
108+
```
109+
110+
## Publishing to PyPI via Trusted Publisher
111+
112+
The repository contains `.github/workflows/publish.yml` that publishes via OIDC (no API token).
113+
Optional dry-run publishing is available in `.github/workflows/publish-testpypi.yml`.
114+
115+
1. Create a `pypi` environment in GitHub repository settings.
116+
2. On PyPI, add a Trusted Publisher for this repository with:
117+
- Owner: `Open-Inflation`
118+
- Repository: `dataclass`
119+
- Workflow: `publish.yml`
120+
- Environment: `pypi`
121+
3. Create a GitHub Release (or run `workflow_dispatch`) to publish.
122+
4. (Optional) Configure a second Trusted Publisher in TestPyPI for `publish-testpypi.yml`
123+
and environment `testpypi`, then run that workflow for pre-release validation.

0 commit comments

Comments
 (0)