Skip to content

Commit fb53efe

Browse files
committed
refactor: align implementation with tir-gfm-lite
1 parent 31647ee commit fb53efe

24 files changed

Lines changed: 517 additions & 43 deletions

File tree

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: Test (Python ${{ matrix.python-version }})
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.9", "3.10", "3.11", "3.12"]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install package
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -e .
30+
31+
- name: Show version
32+
run: |
33+
tir-csv --version || true
34+
35+
- name: Run tests
36+
run: |
37+
chmod +x tests/run.sh
38+
tests/run.sh
39+
40+
- name: Build package
41+
run: |
42+
pip install build
43+
python -m build
44+
45+
- name: Check package
46+
run: |
47+
pip install twine
48+
twine check dist/*

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.x"
22+
23+
- run: |
24+
python -m pip install --upgrade pip
25+
pip install build
26+
27+
- run: python -m build
28+
29+
- name: Publish to PyPI
30+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ pip install tir-csv
1010

1111
## Usage
1212

13-
tir-csv parse file.csv
13+
```bash
14+
tir-csv parse file.csv > file.tir
15+
tir-csv unparse file.csv < file.tir
16+
```

pyproject.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
[build-system]
2-
requires = ["setuptools>=61"]
3-
build-backend = "setuptools.build_meta"
4-
51
[project]
62
name = "tir-csv"
7-
version = "0.1.2"
83
description = "CSV/TSV <-> TIR converter backend for tirenvi"
94
readme = "README.md"
105
requires-python = ">=3.9"
116
license = { text = "MIT" }
127
authors = [{ name = "OGAWA Keiji" }]
138
dependencies = []
9+
scripts = { tir-csv = "tir_csv.cli:main" }
10+
11+
dynamic = ["version"]
12+
13+
[build-system]
14+
requires = ["setuptools>=61", "setuptools_scm"]
15+
build-backend = "setuptools.build_meta"
1416

15-
[project.scripts]
16-
tir-csv = "tir_csv.cli:main"
17+
[tool.setuptools_scm]
18+
version_scheme = "no-guess-dev"
19+
local_scheme = "no-local-version"

src/tir_csv/parser.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Optional
88
from tir_csv.io_utils import input_stream_csv, output_stream_csv
99

10-
__version__ = "0.1.2"
1110
FORMAT_VERSION = "tir/0.1"
1211

1312
# ------------------------------------------------------------
@@ -79,14 +78,20 @@ def unparse(output_file_path: Optional[str], delimiter: str = ",") -> None:
7978
# utilities
8079
# ------------------------------------------------------------
8180

81+
from importlib.metadata import version
82+
83+
84+
def get_version():
85+
return version("tir-csv")
86+
8287

8388
def normalize_cell(cell: str) -> str:
8489
return cell.replace("\r\n", "\n").replace("\r", "\n")
8590

8691

8792
def usage() -> None:
8893
print(
89-
f"""tir-csv {__version__}
94+
f"""tir-csv {get_version()}
9095
9196
usage:
9297
tir-csv parse [--delimiter DELIM] [file|-]
@@ -143,7 +148,7 @@ def run(argv) -> int:
143148
return 1
144149

145150
if args[0] == "--version":
146-
print(__version__)
151+
print(get_version())
147152
return 0
148153

149154
if len(args) not in (1, 2):

tests/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# --- Generated by test runner ---
2+
!data/
23

34
# Actual output (never commit)
4-
out-actual
5+
out-actual.txt
56
gen*
67
diff-*
78

tests/cases/check/rg_no_ascii/out-expected.txt

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
rg -n -g '*.py' -g '*.sh' '[^\x00-\x7F]' $TIRENVI_ROOT > out-actual.txt
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
unknown sub command: help
2-
tir-csv 0.1.2
32

43
usage:
54
tir-csv parse [--delimiter DELIM] [file|-]

tests/cases/tir-csv/help/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# help
33
set -u
4-
exec > out-actual 2>&1
54

6-
tir-csv help
5+
tir-csv help > gen.txt 2>&1
6+
grep -vE '^tir-csv [0-9]' gen.txt > out-actual.txt || true

0 commit comments

Comments
 (0)