Skip to content

Commit 45d93f5

Browse files
committed
ci: avoid tomllib dependency
1 parent 8f5ec8b commit 45d93f5

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,44 @@ jobs:
6767
exit 1
6868
fi
6969
70-
PYPROJECT_VERSION=$(python -c 'import pathlib, tomllib; data = tomllib.loads(pathlib.Path("pyproject.toml").read_text()); print(data["project"]["version"])')
71-
72-
INIT_VERSION=$(python -c 'import pathlib, re, sys; text = pathlib.Path("src/code_index_mcp/__init__.py").read_text(); match = re.search(r"__version__\s*=\s*\"([^\"]+)\"", text); sys.exit("Could not read __version__ from src/code_index_mcp/__init__.py") if not match else print(match.group(1))')
73-
74-
LOCK_VERSION=$(python -c 'import pathlib, tomllib, sys; data = tomllib.loads(pathlib.Path("uv.lock").read_text()); print(next((pkg["version"] for pkg in data["package"] if pkg["name"] == "code-index-mcp"), None) or sys.exit("Could not find code-index-mcp in uv.lock"))')
70+
PYPROJECT_VERSION=$(python - <<'PY'
71+
import pathlib, re
72+
73+
text = pathlib.Path("pyproject.toml").read_text()
74+
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.MULTILINE)
75+
if not match:
76+
raise SystemExit("Could not read version from pyproject.toml")
77+
print(match.group(1))
78+
PY
79+
)
80+
81+
INIT_VERSION=$(python - <<'PY'
82+
import pathlib, re
83+
84+
text = pathlib.Path("src/code_index_mcp/__init__.py").read_text()
85+
match = re.search(r'__version__\s*=\s*"([^"]+)"', text)
86+
if not match:
87+
raise SystemExit("Could not read __version__ from src/code_index_mcp/__init__.py")
88+
print(match.group(1))
89+
PY
90+
)
91+
92+
LOCK_VERSION=$(python - <<'PY'
93+
version = None
94+
with open("uv.lock", "r", encoding="utf-8") as fh:
95+
lines = fh.readlines()
96+
for idx, line in enumerate(lines):
97+
if line.strip() == 'name = "code-index-mcp"':
98+
for follower in lines[idx:idx+6]:
99+
if follower.strip().startswith("version ="):
100+
version = follower.split("=", 1)[1].strip().strip('"')
101+
break
102+
break
103+
if version is None:
104+
raise SystemExit("Could not find code-index-mcp in uv.lock")
105+
print(version)
106+
PY
107+
)
75108
76109
for entry in "pyproject.toml:$PYPROJECT_VERSION" "src/code_index_mcp/__init__.py:$INIT_VERSION" "uv.lock:$LOCK_VERSION"; do
77110
FILE=${entry%%:*}

0 commit comments

Comments
 (0)