Skip to content

Commit

Permalink
Move to uv, upgrade to ovld 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
breuleux committed Sep 10, 2024
1 parent 028310f commit 71928cf
Show file tree
Hide file tree
Showing 17 changed files with 419 additions and 133 deletions.
30 changes: 17 additions & 13 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ jobs:
steps:
- name: Check out the code
uses: actions/checkout@v3
- name: Install rye
uses: eifinger/setup-rye@v4
- name: Set up uv
uses: hynek/setup-cached-uv@v2
with:
cache-dependency-path: uv.lock
- name: Pin Python version
run: rye pin ${{ matrix.python-version }}
run: uv python pin ${{ matrix.python-version }}
- name: Sync dependencies
run: rye sync
run: uv sync
- name: Lint check
run: rye check
run: uvx ruff check
- name: Check formatting
run: rye format --check
run: uvx ruff format --check

test:
runs-on: ubuntu-latest
Expand All @@ -42,18 +44,20 @@ jobs:
steps:
- name: Check out the code
uses: actions/checkout@v3
- name: Install rye
uses: eifinger/setup-rye@v4
- name: Set up uv
uses: hynek/setup-cached-uv@v2
with:
cache-dependency-path: uv.lock
- name: Pin Python version
run: rye pin ${{ matrix.settings.python }}
run: uv python pin ${{ matrix.settings.python }}
- name: Sync dependencies
run: rye sync
run: uv sync
- name: Test with pytest
if: ${{ !matrix.settings.coverage }}
run: rye run pytest
run: uv run pytest tests/
- name: Test with pytest and coverage
if: ${{ matrix.settings.coverage }}
run: rye run pytest --cov=src --cov-report term-missing
run: uv run pytest --cov=src --cov-report term-missing tests/
- name: Verify coverage
if: ${{ matrix.settings.coverage }}
run: rye run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
run: uv run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
37 changes: 24 additions & 13 deletions examples/Basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,14 @@
"source": [
"from hrepr import hrepr\n",
"\n",
"hrepr({\n",
" 'strings': \"Hello this is hrepr\",\n",
" 'numbers': [1, -2, 3.0],\n",
" 'booleans': (True, False),\n",
" 'none': None\n",
"})"
"hrepr(\n",
" {\n",
" \"strings\": \"Hello this is hrepr\",\n",
" \"numbers\": [1, -2, 3.0],\n",
" \"booleans\": (True, False),\n",
" \"none\": None,\n",
" }\n",
")"
]
},
{
Expand Down Expand Up @@ -543,11 +545,13 @@
"# Dataclasses are supported natively\n",
"from dataclasses import dataclass\n",
"\n",
"\n",
"@dataclass\n",
"class Point:\n",
" x: int\n",
" y: int\n",
"\n",
"\n",
"hrepr(Point(1, Point(2, 3)))"
]
},
Expand Down Expand Up @@ -860,10 +864,13 @@
" H.style(\".nice { font-weight: bold; }\"),\n",
" H.ul(\n",
" H.li(\"You can generate HTML directly\"),\n",
" H.li(\"Syntax: \", H.code(\"H.<tag>[<class>](<child>..., <attr>=<value>...)\")),\n",
" H.li(\n",
" \"Syntax: \",\n",
" H.code(\"H.<tag>[<class>](<child>..., <attr>=<value>...)\"),\n",
" ),\n",
" H.li[\"nice\"](\"Isn't this nice?\"),\n",
" style=\"list-style-type:circle\"\n",
" )\n",
" style=\"list-style-type:circle\",\n",
" ),\n",
")"
]
},
Expand Down Expand Up @@ -1238,8 +1245,8 @@
" \"\"\"\n",
" return H.div(style=style)\n",
"\n",
"hrepr([Color(i*32, 0, 0) for i in range(9)],\n",
" swatch_size=20)"
"\n",
"hrepr([Color(i * 32, 0, 0) for i in range(9)], swatch_size=20)"
]
},
{
Expand Down Expand Up @@ -1766,6 +1773,7 @@
"# Another custom class example\n",
"from IPython.display import display_html\n",
"\n",
"\n",
"class Person:\n",
" def __init__(self, name, age, job):\n",
" self.name = name\n",
Expand Down Expand Up @@ -1802,7 +1810,8 @@
" # through pprint is \"x\" whereas H.span(x) would be \"<span>x</span>\".\n",
" return H.atom[\"person-short\"](self.name)\n",
"\n",
"alice = Person('Alice', 46, 'chef')\n",
"\n",
"alice = Person(\"Alice\", 46, \"chef\")\n",
"\n",
"# Triggers __hrepr__\n",
"display_html(hrepr(alice))\n",
Expand Down Expand Up @@ -2936,7 +2945,9 @@
"# Customize this behavior with shortrefs and norefs:\n",
"\n",
"display_html(H.h4(\"Normal\"), hrepr([alice, alice, alice]))\n",
"display_html(H.h4(\"shortrefs=True\"), hrepr([alice, alice, alice], shortrefs=True))\n",
"display_html(\n",
" H.h4(\"shortrefs=True\"), hrepr([alice, alice, alice], shortrefs=True)\n",
")\n",
"display_html(H.h4(\"norefs=True\"), hrepr([alice, alice, alice], norefs=True))"
]
},
Expand Down
22 changes: 11 additions & 11 deletions examples/exhibit.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
border-color: magenta !important;
}
.person-short { font-weight: bold; color: green; }
</style><style>.my-integer { color: fuchsia; }</style><style>.highlight { border: 3px solid red !important; }</style><script>$$HREPR = {
</style><style>.highlight { border: 3px solid red !important; }</style><script>$$HREPR = {
scriptStatus: {},
counters: {},
fromHTML(html) {
Expand Down Expand Up @@ -434,21 +434,21 @@
width: 50px;
height: 50px;
margin: 3px;
"></div></div></div><div class="hrepr-close">]</div></div><h4>Without a mixin</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-int">1</span></div><div><span class="hreprt-int">2</span></div><div><div class="hrepr-refbox"><span class="hrepr-ref">#1=</span><span class="hreprt-Farfetchd">&lt;__main__.Farfetchd&gt;</span></div></div><div><span class="hreprt-int">4</span></div><div><div class="hrepr-refbox"><span class="hrepr-ref">#1=</span><span class="hreprt-Farfetchd">&lt;__main__.Farfetchd&gt;</span></div></div></div><div class="hrepr-close">]</div></div><h4>With a custom mixin</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="my-integer">The number 1</span></div><div><span class="my-integer">The number 2</span></div><div><span>🦆</span></div><div><span class="my-integer">The number 4</span></div><div><span>🦆</span></div></div><div class="hrepr-close">]</div></div><h4>Playing with max_depth</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="my-integer">1</span></div><div><span class="my-integer">2</span></div><div><span>🦆</span></div><div><span class="my-integer">4</span></div><div><span>🦆</span></div></div><div class="hrepr-close">]</div></div><h4>Use a postprocessor to highlight the number 2</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-int">1</span></div><div><span class="hreprt-int highlight">2</span></div><div><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-int">3</span></div><div><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-float highlight">2.0</span></div></div><div class="hrepr-close">]</div></div></div><div><span class="hreprt-str">2</span></div></div><div class="hrepr-close">]</div></div></div></div><div class="hrepr-close">]</div></div><h2>Cool stuff</h2><h4>Plot with plotly</h4><div id="H1184"></div><h4>Graph with cytoscape</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><div style="width:300px;height:300px;border:1px solid black;" id="H1193"></div></div><div><div style="width:300px;height:300px;border:1px solid black;" id="H1196"></div></div></div><div class="hrepr-close">]</div></div><script>$$HREPR.prepare("H1184");</script><script type="module">const $$INTO = document.getElementById("H1184");
$$HREPR.run(["https://cdn.plot.ly/plotly-latest.min.js"],'#H1184',()=>{
"></div></div></div><div class="hrepr-close">]</div></div><h4>Without a mixin</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-int">1</span></div><div><span class="hreprt-int">2</span></div><div><div class="hrepr-refbox"><span class="hrepr-ref">#1=</span><span class="hreprt-Farfetchd">&lt;__main__.Farfetchd&gt;</span></div></div><div><span class="hreprt-int">4</span></div><div><div class="hrepr-refbox"><span class="hrepr-ref">#1=</span><span class="hreprt-Farfetchd">&lt;__main__.Farfetchd&gt;</span></div></div></div><div class="hrepr-close">]</div></div><h4>With a custom mixin</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="my-integer">The number 1</span></div><div><span class="my-integer">The number 2</span></div><div><span>🦆</span></div><div><span class="my-integer">The number 4</span></div><div><span>🦆</span></div></div><div class="hrepr-close">]</div></div><h4>Playing with max_depth</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="my-integer">1</span></div><div><span class="my-integer">2</span></div><div><span>🦆</span></div><div><span class="my-integer">4</span></div><div><span>🦆</span></div></div><div class="hrepr-close">]</div></div><h4>Use a postprocessor to highlight the number 2</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-int">1</span></div><div><span class="hreprt-int highlight">2</span></div><div><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-int">3</span></div><div><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><span class="hreprt-float highlight">2.0</span></div></div><div class="hrepr-close">]</div></div></div><div><span class="hreprt-str">2</span></div></div><div class="hrepr-close">]</div></div></div></div><div class="hrepr-close">]</div></div><h2>Cool stuff</h2><h4>Plot with plotly</h4><div id="H1178"></div><h4>Graph with cytoscape</h4><div class="hreprt-list hrepr-bracketed"><div class="hrepr-open">[</div><div class="hreprl-h hrepr-body"><div><div style="width:300px;height:300px;border:1px solid black;" id="H1187"></div></div><div><div style="width:300px;height:300px;border:1px solid black;" id="H1190"></div></div></div><div class="hrepr-close">]</div></div><script>$$HREPR.prepare("H1178");</script><script type="module">const $$INTO = document.getElementById("H1178");
$$HREPR.run(["https://cdn.plot.ly/plotly-latest.min.js"],'#H1178',()=>{
const obj = $$HREPR.ucall(Plotly,"newPlot",$$INTO,[{"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], "y": [0.0, 0.09983341664682815, 0.19866933079506122, 0.29552020666133955, 0.3894183423086505, 0.479425538604203, 0.5646424733950354, 0.644217687237691, 0.7173560908995228, 0.7833269096274834, 0.8414709848078965, 0.8912073600614354, 0.9320390859672263, 0.963558185417193, 0.9854497299884601, 0.9974949866040544, 0.9995736030415051, 0.9916648104524686, 0.9738476308781951, 0.9463000876874145, 0.9092974268256817, 0.8632093666488737, 0.8084964038195901, 0.7457052121767204, 0.6754631805511511, 0.5984721441039564, 0.5155013718214642, 0.4273798802338298, 0.3349881501559051, 0.23924932921398243, 0.1411200080598672, 0.04158066243329049, -0.058374143427580086, -0.1577456941432482, -0.2555411020268312, -0.35078322768961984, -0.44252044329485246, -0.5298361409084934, -0.6118578909427189, -0.6877661591839738, -0.7568024953079283, -0.8182771110644103, -0.8715757724135882, -0.9161659367494549, -0.9516020738895161, -0.977530117665097, -0.9936910036334644, -0.9999232575641008, -0.9961646088358407, -0.9824526126243325, -0.9589242746631385, -0.9258146823277325, -0.8834546557201531, -0.8322674422239013, -0.7727644875559871, -0.7055403255703919, -0.6312666378723216, -0.5506855425976376, -0.46460217941375737, -0.373876664830236, -0.27941549819892586, -0.18216250427209588, -0.0830894028174964, 0.016813900484349713, 0.11654920485049364, 0.21511998808781552, 0.31154136351337786, 0.4048499206165983, 0.49411335113860816, 0.5784397643882002, 0.6569865987187891, 0.7289690401258759, 0.7936678638491531, 0.8504366206285644, 0.8987080958116269, 0.9379999767747389, 0.9679196720314863, 0.9881682338770004, 0.998543345374605, 0.998941341839772, 0.9893582466233818, 0.9698898108450863, 0.9407305566797731, 0.9021718337562934, 0.8545989080882804, 0.7984871126234903, 0.7343970978741134, 0.6629692300821833, 0.5849171928917617, 0.5010208564578846, 0.4121184852417566, 0.3190983623493521, 0.22288991410024764, 0.1244544235070617, 0.024775425453357765, -0.0751511204618093, -0.17432678122297965, -0.27176062641094245, -0.36647912925192844, -0.4575358937753214]}]);
$$INTO.__object.__resolve(obj);

});</script><script>$$HREPR.prepare("H1193");</script><script type="module">import default__1493 from "https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.23.0/cytoscape.esm.min.js";
const $$INTO = document.getElementById("H1193");
$$HREPR.run([],'#H1193',()=>{
const obj = $$HREPR.ucall(default__1493,null,{"container": $$INTO, "elements": [{"data": {"id": "B"}}, {"data": {"id": "D"}}, {"data": {"id": "C"}}, {"data": {"id": "E"}}, {"data": {"id": "A"}}, {"data": {"source": "A", "target": "B"}}, {"data": {"source": "B", "target": "A"}}, {"data": {"source": "A", "target": "C"}}, {"data": {"source": "C", "target": "D"}}, {"data": {"source": "D", "target": "E"}}], "style": [{"selector": "node", "style": {"background-color": "#800", "label": "data(id)"}}, {"selector": "edge", "style": {"width": 3, "line-color": "#ccc", "target-arrow-color": "#ccc", "target-arrow-shape": "triangle", "curve-style": "bezier"}}], "layout": {"name": "cose"}});
});</script><script>$$HREPR.prepare("H1187");</script><script type="module">import default__1487 from "https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.23.0/cytoscape.esm.min.js";
const $$INTO = document.getElementById("H1187");
$$HREPR.run([],'#H1187',()=>{
const obj = $$HREPR.ucall(default__1487,null,{"container": $$INTO, "elements": [{"data": {"id": "B"}}, {"data": {"id": "E"}}, {"data": {"id": "C"}}, {"data": {"id": "D"}}, {"data": {"id": "A"}}, {"data": {"source": "A", "target": "B"}}, {"data": {"source": "B", "target": "A"}}, {"data": {"source": "A", "target": "C"}}, {"data": {"source": "C", "target": "D"}}, {"data": {"source": "D", "target": "E"}}], "style": [{"selector": "node", "style": {"background-color": "#800", "label": "data(id)"}}, {"selector": "edge", "style": {"width": 3, "line-color": "#ccc", "target-arrow-color": "#ccc", "target-arrow-shape": "triangle", "curve-style": "bezier"}}], "layout": {"name": "cose"}});
$$INTO.__object.__resolve(obj);

});</script><script>$$HREPR.prepare("H1196");</script><script type="module">import default__1496 from "https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.23.0/cytoscape.esm.min.js";
const $$INTO = document.getElementById("H1196");
$$HREPR.run([],'#H1196',()=>{
const obj = $$HREPR.ucall(default__1496,null,{"container": $$INTO, "elements": [{"data": {"id": "Scissors"}}, {"data": {"id": "Rock"}}, {"data": {"id": "Paper"}}, {"data": {"source": "Rock", "target": "Scissors"}}, {"data": {"source": "Scissors", "target": "Paper"}}, {"data": {"source": "Paper", "target": "Rock"}}], "style": [{"selector": "node", "style": {"background-color": "#800", "label": "data(id)"}}, {"selector": "edge", "style": {"width": 3, "line-color": "#ccc", "target-arrow-color": "#ccc", "target-arrow-shape": "triangle", "curve-style": "bezier"}}], "layout": {"name": "cose"}});
});</script><script>$$HREPR.prepare("H1190");</script><script type="module">import default__1490 from "https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.23.0/cytoscape.esm.min.js";
const $$INTO = document.getElementById("H1190");
$$HREPR.run([],'#H1190',()=>{
const obj = $$HREPR.ucall(default__1490,null,{"container": $$INTO, "elements": [{"data": {"id": "Paper"}}, {"data": {"id": "Rock"}}, {"data": {"id": "Scissors"}}, {"data": {"source": "Rock", "target": "Scissors"}}, {"data": {"source": "Scissors", "target": "Paper"}}, {"data": {"source": "Paper", "target": "Rock"}}], "style": [{"selector": "node", "style": {"background-color": "#800", "label": "data(id)"}}, {"selector": "edge", "style": {"width": 3, "line-color": "#ccc", "target-arrow-color": "#ccc", "target-arrow-shape": "triangle", "curve-style": "bezier"}}], "layout": {"name": "cose"}});
$$INTO.__object.__resolve(obj);

});</script></body></html>
6 changes: 4 additions & 2 deletions examples/exhibit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import math
from dataclasses import dataclass

from ovld import OvldMC, extend_super
from ovld.types import HasMethod

from hrepr import H, J, hrepr, returns
from ovld import OvldMC, extend_super, has_attribute


@dataclass
Expand Down Expand Up @@ -82,7 +84,7 @@ def hrepr_short(self, n: int):

# Specially handle any object with a "quack" method

def hrepr_short(self, duck: has_attribute("quack")):
def hrepr_short(self, duck: HasMethod["quack"]):
# Note: if there is no hrepr it falls back to hrepr_short
return self.H.span("🦆")

Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ authors = [
]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/breuleux/hrepr"
repository = "https://github.com/breuleux/hrepr"
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
]
dependencies = [
"ovld~=0.3.6",
"ovld~=0.4.0",
]
requires-python = ">= 3.9"

[project.urls]
Homepage = "https://github.com/breuleux/hrepr"
Repository = "https://github.com/breuleux/hrepr"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
[tool.uv]
managed = true
dev-dependencies = [
"pytest>=8.3.2",
Expand Down
32 changes: 0 additions & 32 deletions requirements-dev.lock

This file was deleted.

14 changes: 0 additions & 14 deletions requirements.lock

This file was deleted.

Loading

0 comments on commit 71928cf

Please sign in to comment.