Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
push:
pull_request:

jobs:
test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: |
python -m pip install --upgrade pip
pip install -e .

- name: Show version
run: |
tir-csv --version || true

- name: Run tests
run: |
chmod +x tests/run.sh
tests/run.sh

- name: Build package
run: |
pip install build
python -m build

- name: Check package
run: |
pip install twine
twine check dist/*
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish to PyPI

on:
push:
tags:
- "v*"

jobs:
publish:
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.x"

- run: |
python -m pip install --upgrade pip
pip install build

- run: python -m build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ pip install tir-csv

## Usage

tir-csv parse file.csv
```bash
tir-csv parse file.csv > file.tir
tir-csv unparse file.csv < file.tir
```
17 changes: 10 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"

[project]
name = "tir-csv"
version = "0.1.2"
description = "CSV/TSV <-> TIR converter backend for tirenvi"
readme = "README.md"
requires-python = ">=3.9"
license = { text = "MIT" }
authors = [{ name = "OGAWA Keiji" }]
dependencies = []
scripts = { tir-csv = "tir_csv.cli:main" }

dynamic = ["version"]

[build-system]
requires = ["setuptools>=61", "setuptools_scm"]
build-backend = "setuptools.build_meta"

[project.scripts]
tir-csv = "tir_csv.cli:main"
[tool.setuptools_scm]
version_scheme = "no-guess-dev"
local_scheme = "no-local-version"
11 changes: 8 additions & 3 deletions src/tir_csv/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Optional
from tir_csv.io_utils import input_stream_csv, output_stream_csv

__version__ = "0.1.2"
FORMAT_VERSION = "tir/0.1"

# ------------------------------------------------------------
Expand Down Expand Up @@ -79,14 +78,20 @@ def unparse(output_file_path: Optional[str], delimiter: str = ",") -> None:
# utilities
# ------------------------------------------------------------

from importlib.metadata import version


def get_version():
return version("tir-csv")


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


def usage() -> None:
print(
f"""tir-csv {__version__}
f"""tir-csv {get_version()}

usage:
tir-csv parse [--delimiter DELIM] [file|-]
Expand Down Expand Up @@ -143,7 +148,7 @@ def run(argv) -> int:
return 1

if args[0] == "--version":
print(__version__)
print(get_version())
return 0

if len(args) not in (1, 2):
Expand Down
3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# --- Generated by test runner ---
!data/

# Actual output (never commit)
out-actual
out-actual.txt
gen*
diff-*

Expand Down
Empty file.
4 changes: 4 additions & 0 deletions tests/cases/check/rg_no_ascii/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -eu

rg -n -g '*.py' -g '*.sh' '[^\x00-\x7F]' $TIRENVI_ROOT > out-actual.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
unknown sub command: help
tir-csv 0.1.2

usage:
tir-csv parse [--delimiter DELIM] [file|-]
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/tir-csv/help/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# help
set -u
exec > out-actual 2>&1

tir-csv help
tir-csv help > gen.txt 2>&1
grep -vE '^tir-csv [0-9]' gen.txt > out-actual.txt || true
2 changes: 1 addition & 1 deletion tests/cases/tir-csv/parse-file/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Test that newline and tab characters are correctly converted to \n and \t
# When a file name is specified, the absolute path of the file is output
set -eu
exec > out-actual 2>&1
exec > out-actual.txt 2>&1

# tir-csv parse "$TIRENVI_ROOT/tests/data/complex.csv" | sed "s|$TIRENVI_ROOT|/<ABS_PATH>|g"

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/tir-csv/parse-stdin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# When input is provided via stdin, the file name becomes null

set -eu
exec > out-actual 2>&1
exec > out-actual.txt 2>&1

tir-csv parse < "$TIRENVI_ROOT/tests/data/complex.csv"
2 changes: 1 addition & 1 deletion tests/cases/tir-csv/unparse/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -eu
exec > out-actual 2>&1
exec > out-actual.txt 2>&1

tir-csv unparse < "$TIRENVI_ROOT/tests/data/complex.tir"
2 changes: 1 addition & 1 deletion tests/cases/tir-tsv/parse-file/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Test that newline and tab characters are correctly converted to \n and \t
# When a file name is specified, the absolute path of the file is output
set -eu
exec > out-actual 2>&1
exec > out-actual.txt 2>&1

tir-csv parse --delimiter "\t" "$TIRENVI_ROOT/tests/data/complex.tsv" | sed "s|$TIRENVI_ROOT|/<ABS_PATH>|g"
2 changes: 1 addition & 1 deletion tests/cases/tir-tsv/unparse/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -eu
exec > out-actual 2>&1
exec > out-actual.txt 2>&1

tir-csv unparse --delimiter "\t" < "$TIRENVI_ROOT/tests/data/complex.tir"
115 changes: 115 additions & 0 deletions tests/data/complex.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
A1,B22,C333,D4444,E55555,F666666
alpha1,b2,c3,d4,e5,f6
===,- next -, line, has, no, value
,,,,,
x1,,y22,,z333,
===, - next -, line, has,linefeed,
"
""1""2h"", 34567890a",abc,DEF123,"


",gh,9
a,,"b
",,c,
===,- next -, lines, has,tab,
l ongtext01,mi d2,s,tt,uuu,vvvv
,, , ,,
R1C1,R1C2,R1C3,R1C4,R1C5,R1C6
===,- next -, line, is,multibyte, value
aaあい,いろ2,ぼんさんが,へを,こいた,.!...
g1,h22,i333,j4444,k55555,l6
===,- next -, lines, has,linefeed+,tab
,"
",n , o333,,
pqrst,uv,wx1,yz22,,345
,,,,,
a1b2c3,,XYZ,7777,,k9
short,longer12,x,yz,,end
,,,,,
row15a,row15b,row15c,row15d,row15e,row15f
1,22,333,4444,55555,666666
alpha,beta,gamma,delta,epsilon,zeta
,,,,,
mix1,,mix3,444,,six6
abc123,,def456,,ghi789,
z,,y,,x,
,,,,,
t1,t2,t3,t4,t5,t6
r1c1,r1c2,,r1c4,,r1c6
data1,data22,data333,data4444,data55555,data6
,,,,,
A,B,C,D,E,F
abc,,123,,XYZ,
one1,two22,three3,four44,five5,six66
,,,,,
r30a,r30b,r30c,r30d,r30e,r30f
longvalue1,mid,short,s,tt,uuu
,,,,,
x,y,z,,,end
abcde,fghij,klmno,pqrst,uvwxy,z
,,,,,
cell1,,cell3,,cell5,
111,2222,33333,444444,55,6
,,,,,
row40a,row40b,row40c,row40d,row40e,row40f
a1,a2,a3,a4,a5,a6
,,,,,
mixA,,mixC,DDD,,FFF
123abc,456def,,789ghi,,000
,,,,,
r45a,r45b,r45c,r45d,r45e,r45f
alpha9,,beta8,,gamma7,
,,,,,
A1B2C3,D4E5F6,G7H8I9,J0,K1,L2
short1,,short3,,short5,
,,,,,
r50a,r50b,r50c,r50d,r50e,r50f
x1y2,z3,,w4,,v5
,,,,,
longertext,mid,small,s1,s22,s333
,,,,,
r55a,r55b,r55c,r55d,r55e,r55f
abc,def,ghi,jkl,mno,pqr
,,,,,
1a,2b,3c,4d,5e,6f
,,,,,
row60a,row60b,row60c,row60d,row60e,row60f
value1,,value3,,value5,
,,,,,
aa,bb,cc,dd,ee,ff
,,,,,
r65a,r65b,r65c,r65d,r65e,r65f
x,,y,,z,
,,,,,
alpha01,beta02,gamma03,delta04,eps05,z6
,,,,,
row70a,row70b,row70c,row70d,row70e,row70f
1,,3,,5,
,,,,,
abc1,def2,ghi3,jkl4,mno5,pqr6
,,,,,
r75a,r75b,r75c,r75d,r75e,r75f
mix,,mix2,,mix3,
,,,,,
a,b,c,d,e,f
,,,,,
row80a,row80b,row80c,row80d,row80e,row80f
123,234,345,456,567,678
,,,,,
Aaa,Bbb,Ccc,Ddd,Eee,Fff
,,,,,
r85a,r85b,r85c,r85d,r85e,r85f
x1,,x3,,x5,
,,,,,
abcde12345,f1,g2,h3,i4,j5
,,,,,
row90a,row90b,row90c,row90d,row90e,row90f
1a2b3c,,4d5e6f,,7g8h9i,
,,,,,
short,,mid,,longer,
,,,,,
r95a,r95b,r95c,r95d,r95e,r95f
a1b,,c2d,,e3f,
,,,,,
end1,end2,end3,end4,end5,end6
,,,,,
Loading
Loading