Skip to content

Commit

Permalink
Merge pull request #9 from maxfordham/configure-pixi
Browse files Browse the repository at this point in the history
Configure pixi
  • Loading branch information
jgunstone authored Sep 30, 2024
2 parents d84f946 + fb82d19 commit b60cd58
Show file tree
Hide file tree
Showing 30 changed files with 5,517 additions and 1,239 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
10 changes: 10 additions & 0 deletions .github/.dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
groups:
dependencies:
patterns:
- "*"
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# TODO: setup auto-update pixi.lock https://pixi.sh/latest/advanced/updates_github_actions/#how-to-use

name: Test and Lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-latest
label: linux-64

name: ${{ matrix.label }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected]
with:
manifest-path: pyproject.toml
pixi-version: v0.30.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
- run: pixi run test
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ cython_debug/

src/xlsxdatagrid/__about__.py
reference/example*
*.xlsx
tests/xlsxwriter-examples/*

.virtual_documents/*
.pixi
*.egg-info
44 changes: 24 additions & 20 deletions docs/codegen-issue-1624.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
}
],
"source": [
"import typing as ty\n",
"import importlib\n",
"import json\n",
"import sys\n",
"import typing as ty\n",
"from pathlib import Path\n",
"from tempfile import TemporaryDirectory\n",
"from datamodel_code_generator import InputFileType, generate, DataModelType\n",
"\n",
"from datamodel_code_generator import DataModelType, InputFileType, generate\n",
"from pydantic import BaseModel\n",
"import sys\n",
"\n",
"\n",
"def pydantic_model_from_json_schema(json_schema: str) -> ty.Type[BaseModel]:\n",
" load = json_schema[\"title\"] if \"title\" in json_schema else \"Model\"\n",
Expand All @@ -57,23 +59,20 @@
" spec.loader.exec_module(module)\n",
" return getattr(module, load)\n",
"\n",
"\n",
"schema = {\n",
" \"title\": \"Test\",\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"a_int\": {\n",
" \"default\": 1,\n",
" \"title\": \"A Int\",\n",
" \"type\": \"integer\"\n",
" },\n",
" \"i_duration\": {\n",
" \"default\": \"PT2H33M3S\",\n",
" \"format\": \"duration\",\n",
" \"title\": \"I Duration\",\n",
" \"type\": \"string\"\n",
" }\n",
" \"title\": \"Test\",\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"a_int\": {\"default\": 1, \"title\": \"A Int\", \"type\": \"integer\"},\n",
" \"i_duration\": {\n",
" \"default\": \"PT2H33M3S\",\n",
" \"format\": \"duration\",\n",
" \"title\": \"I Duration\",\n",
" \"type\": \"string\",\n",
" },\n",
" }\n",
" },\n",
"}\n",
"\n",
"Model = pydantic_model_from_json_schema(schema)\n",
"Model.model_fields"
Expand All @@ -99,17 +98,22 @@
],
"source": [
"from datetime import timedelta\n",
"\n",
"from pydantic import create_model\n",
"\n",
"\n",
"def get_timedelta_fields(schema: dict) -> list[str]:\n",
" pr = schema[\"properties\"]\n",
" return [k for k, v in pr.items() if \"format\" in v and v[\"format\"] == \"duration\"]\n",
" \n",
"\n",
"\n",
"def update_timedelta_field(model: BaseModel, timedelta_fields: list[str]) -> BaseModel:\n",
" \"\"\"returns a new pydantic model where serialization validators have been added to dates,\n",
" datetimes and durations for compatibility with excel\"\"\"\n",
" get_default = lambda obj: obj.default if hasattr(obj, \"default\") else ...\n",
"\n",
" def get_default(obj):\n",
" return obj.default if hasattr(obj, \"default\") else ...\n",
"\n",
" deltas = {\n",
" k: (timedelta, get_default(v))\n",
" for k, v in model.model_fields.items()\n",
Expand Down
103 changes: 103 additions & 0 deletions docs/dateteime-checks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"id": "4dfb0c9b-81b1-4d02-a51d-218309cf20dd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'event_datetime': {'start': datetime.datetime(2024, 1, 1, 15, 0, tzinfo=datetime.timezone.utc), 'end': datetime.datetime(2024, 1, 3, 14, 0, tzinfo=datetime.timezone.utc), 'aware_datetime': datetime.datetime(1, 2, 3, 0, 1, 15, tzinfo=datetime.timezone.utc), 'deltat': datetime.timedelta(days=1, seconds=2), 'time_of_date': datetime.time(12, 45), 'inty': 1}}\n",
"{\"event_datetime\":{\"start\":\"2024-01-01T07:00:00-08:00\",\"end\":\"2024-01-03T20:00:00+06:00\",\"aware_datetime\":\"0001-02-03T00:00:00\",\"deltat\":\"P1DT2S\",\"time_of_date\":\"12:45:00\",\"inty\":1}}\n"
]
}
],
"source": [
"from datetime import datetime, time, timedelta, timezone\n",
"from typing import Any, Dict\n",
"\n",
"from pydantic import AwareDatetime, BaseModel, WrapSerializer\n",
"from typing_extensions import Annotated\n",
"\n",
"\n",
"class EventDatetime(BaseModel):\n",
" start: datetime\n",
" end: datetime\n",
" aware_datetime: AwareDatetime = datetime(1, 2, 3)\n",
" deltat: timedelta = timedelta(1, 2)\n",
" time_of_date: time = time(12, 45)\n",
" inty: int = 1\n",
"\n",
"\n",
"def convert_to_utc(value: Any, handler, info) -> Dict[str, Any]:\n",
" # Note that `helper` can actually help serialize the `value` for further custom serialization in case it's a subclass.\n",
" partial_result = handler(value, info)\n",
" fn = (\n",
" lambda v: \"datetime.fromisoformat(v).astimezone(timezone.utc)\"\n",
" if isinstance(v, datetime)\n",
" else v\n",
" )\n",
" if info.mode == \"json\":\n",
" return {k: fn(v) for k, v in partial_result.items()}\n",
" fn = lambda v: v.astimezone(timezone.utc) if isinstance(v, datetime) else v\n",
" return {k: fn(v) for k, v in partial_result.items()}\n",
"\n",
"\n",
"UTCEventDatetime = Annotated[EventDatetime, WrapSerializer(convert_to_utc)]\n",
"\n",
"\n",
"class EventModel(BaseModel):\n",
" event_datetime: UTCEventDatetime\n",
"\n",
"\n",
"dt = EventDatetime(start=\"2024-01-01T07:00:00-08:00\", end=\"2024-01-03T20:00:00+06:00\")\n",
"event = EventModel(event_datetime=dt)\n",
"print(event.model_dump())\n",
"\"\"\"\n",
"{\n",
" 'event_datetime': {\n",
" 'start': datetime.datetime(\n",
" 2024, 1, 1, 15, 0, tzinfo=datetime.timezone.utc\n",
" ),\n",
" 'end': datetime.datetime(\n",
" 2024, 1, 3, 14, 0, tzinfo=datetime.timezone.utc\n",
" ),\n",
" }\n",
"}\n",
"\"\"\"\n",
"\n",
"print(event.model_dump_json())"
]
},
{
"cell_type": "markdown",
"id": "2f022b81-38f1-43af-a5c0-18bbd964a040",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
12 changes: 12 additions & 0 deletions docs/frictionless-py-1678.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
https://github.com/frictionlessdata/frictionless-py/issues/1678
```{python}
import pandas as pd
x = range(0, 5)
y = [_**2 for _ in x]
z = [_*1.2 for _ in x]
df = pd.DataFrame({"x": x, "y": y, "z": z})
from frictionless import Resource
r = Resource(df)
r.read_rows()
```
32 changes: 32 additions & 0 deletions docs/under-the-hood.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


## Execution

```{mermaid}
stateDiagram
[*] --> Still
[*1*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
Crash --> [some]
```

```{python}
from frictionless import Resource, formats
resource = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
resource.write('table-output-sheet.xls', control=formats.ExcelControl(sheet='My Table'))
```


```{python}
a = ""
issubclass(a, str)
```

Loading

0 comments on commit b60cd58

Please sign in to comment.