Skip to content

Commit 118c1f4

Browse files
committed
CI bits
1 parent 2a9c801 commit 118c1f4

4 files changed

Lines changed: 162 additions & 8 deletions

File tree

.github/workflows/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Amara CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.12", "3.13"]
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install ruff pytest pytest-mock
23+
# Install Amara itself
24+
pip install -U .
25+
26+
- name: Lint with ruff
27+
run: |
28+
# Stop the build if there are Python syntax errors or undefined names
29+
ruff check --select=E9,F63,F7,F82 --target-version=py312 .
30+
# Run default ruff checks
31+
ruff check --target-version=py312 .
32+
33+
- name: Test with pytest
34+
run: |
35+
pytest test/ -v

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
environment: pypi # GitHub environment for additional protection
11+
permissions:
12+
id-token: write # Required for trusted publishing
13+
14+
steps:
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: Install build tools
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build twine
26+
27+
- name: Build package
28+
run: python -m build
29+
30+
# - name: Build wheel
31+
# run: python -m build --wheel
32+
33+
- name: Publish to PyPI
34+
uses: pypa/gh-action-pypi-publish@release/v1
35+
# with:
36+
# Uses OIDC trusted publishing - no token needed if configured
37+
# If you need to use a token instead, uncomment below:
38+
# password: ${{ secrets.PYPI_API_TOKEN }}

README.md

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ Requires Python 3.12 or later.
1818
pip install amara
1919
```
2020

21-
Or with uv:
21+
Or with uv (recommended):
2222

2323
```bash
2424
uv pip install amara
2525
```
2626

27+
**Note**: This package is currently in development. For the latest features and bug fixes, you can install directly from source:
28+
29+
```bash
30+
git clone https://github.com/OoriData/Amara.git
31+
cd Amara
32+
pip install -U .
33+
```
34+
2735
## Quick Start
2836

2937
### IRI Processing
@@ -33,8 +41,16 @@ from amara.iri import I, iri
3341

3442
# Create and manipulate IRIs
3543
url = I('http://example.org/path/to/resource')
44+
print(url.scheme) # 'http'
45+
print(url.host) # 'example.org'
46+
47+
# Join relative paths with base URLs
3648
joined = iri.join('http://example.org/a/b', '../c')
37-
# Result: 'http://example.org/a/c'
49+
print(joined) # 'http://example.org/a/c'
50+
51+
# Percent encoding/decoding
52+
encoded = iri.percent_encode('hello world!')
53+
print(encoded) # 'hello%20world%21'
3854
```
3955

4056
### XML Processing
@@ -47,14 +63,21 @@ SAMPLE_XML = """<monty>
4763
<python ministry="abuse">But I was looking for argument</python>
4864
</monty>"""
4965

66+
# Parse XML
5067
builder = xml.treebuilder()
5168
root = builder.parse(SAMPLE_XML)
5269
print(root.xml_name) # "monty"
5370

54-
# Access children
71+
# Access children and attributes
5572
for child in root.xml_children:
5673
if hasattr(child, 'xml_attributes'):
57-
print(child.xml_attributes.get('spam'))
74+
print(f"Element: {child.xml_name}")
75+
print(f"Spam attr: {child.xml_attributes.get('spam')}")
76+
print(f"Text: {child.xml_text}")
77+
78+
# Iterate through all elements
79+
for elem in root.xml_iter():
80+
print(f"Found element: {elem.xml_name}")
5881
```
5982

6083
### HTML5 Processing
@@ -69,11 +92,42 @@ HTML_DOC = """<!DOCTYPE html>
6992
</html>"""
7093

7194
doc = html5.parse(HTML_DOC)
95+
print(doc.xml_name) # "html"
96+
```
97+
98+
### XPath-like Queries
99+
100+
```python
101+
from amara.uxpath import xpath
102+
103+
SAMPLE_XML = """<catalog>
104+
<book id="1">
105+
<title>Python Programming</title>
106+
<author>John Doe</author>
107+
</book>
108+
<book id="2">
109+
<title>Web Development</title>
110+
<author>Jane Smith</author>
111+
</book>
112+
</catalog>"""
113+
114+
builder = xml.treebuilder()
115+
root = builder.parse(SAMPLE_XML)
116+
117+
# Find all book titles
118+
titles = xpath.select(root, '//book/title')
119+
for title in titles:
120+
print(title.xml_text)
121+
122+
# Find book by ID
123+
book = xpath.select(root, "//book[@id='2']")
124+
if book:
125+
print(f"Found: {book[0].xml_children[0].xml_text}")
72126
```
73127

74128
### Command-Line Tool
75129

76-
The `microx` command provides powerful XML/MicroXML querying:
130+
The `microx` command provides powerful XML/MicroXML querying and processing:
77131

78132
```bash
79133
# Extract elements by name
@@ -82,13 +136,40 @@ microx file.xml --match=item
82136
# XPath-like expressions
83137
microx file.xml --expr="//item[@id='2']"
84138

85-
# Extract text content
139+
# Extract text content from specific elements
86140
microx file.xml --match=name --foreach="text()"
141+
142+
# Process multiple files
143+
microx *.xml --match=title --foreach="text()"
144+
145+
# Pretty-print XML
146+
microx file.xml --pretty
147+
148+
# Convert to MicroXML
149+
microx file.xml --microxml
87150
```
88151

152+
For more options, run:
153+
```bash
154+
microx --help
155+
```
89156

157+
## Requirements
158+
159+
- Python 3.12+
160+
- Dependencies: [`ply`](https://www.dabeaz.com/ply/ply.html), [`html5lib-modern`](https://github.com/ashleysommer/html5lib-modern), [`nameparser`](https://pypi.org/project/nameparser/)
161+
162+
## Development
163+
164+
This project is actively developed by [Oori Data](https://www.oori.dev/). For development setup:
165+
166+
```bash
167+
git clone https://github.com/OoriData/Amara.git
168+
cd Amara
169+
pip install -U .
170+
```
90171

91-
# History
172+
## History
92173

93174
Amara was originally an open source project I created, renaming and expanding on [Anobind 2003](https://www.xml.com/pub/a/2003/08/13/py-xml.html), looking to simplify and rethink XML and related technology processing. It went through a few evolutions and progress had slowed down since the late 2010s.
94175

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
dependencies = [
2929
"nameparser",
3030
"ply",
31-
"html5lib-modern",
31+
"html5lib-modern", # https://github.com/ashleysommer/html5lib-modern
3232
]
3333

3434
[project.optional-dependencies]

0 commit comments

Comments
 (0)