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
4 changes: 3 additions & 1 deletion data/make_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
for i in range(100):
values = []
for j in range(col):
values.append(f"({i*col+j},\"{''.join(random.choices(alphabet,k=10))}\")")
values.append(
f'({i * col + j},"{"".join(random.choices(alphabet, k=10))}")'
)
conn.exec_driver_sql(f"insert into test.t1 value{','.join(values)}")
conn.commit()
5 changes: 3 additions & 2 deletions devtools/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ class User(Base):
ids = iter(random.sample(range(0, 2 * 1000 * 1000), 1000 * 1000))
for i in range(1000):
session.bulk_insert_mappings(
User, [{"id": next(ids), "name": "a"*5000, "age": 10} for j in range(1000)]
User,
[{"id": next(ids), "name": "a" * 5000, "age": 10} for j in range(1000)],
)
elif len(sys.argv) > 1 and sys.argv[1] == "drop":
User.__table__.drop(bind=engine)
else:
for i in range(1000):
session.bulk_insert_mappings(
User, [{"name": "a"*5000, "age": 10} for i in range(1000)]
User, [{"name": "a" * 5000, "age": 10} for i in range(1000)]
)

session.commit()
19 changes: 14 additions & 5 deletions devtools/deploy_mysqld.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import click
import json
from pprint import pprint
from pathlib import Path

from dataclasses import dataclass, asdict
from testcontainers.mysql import MySqlContainer
Expand All @@ -18,6 +19,8 @@

c.ryuk_disabled = True

def get_project_root():
return Path(__file__).parent.parent

@click.group()
def main():
Expand All @@ -29,6 +32,8 @@ def tlist():
data = load_deploy()
pprint(data)

DEPLOY_MYSQLD_PATH=get_project_root() / ".deploy_mysqld"
DATADIR_BASE=get_project_root() / "datadir"

@main.command()
@click.option("--version", type=click.STRING)
Expand All @@ -47,7 +52,7 @@ def clean(version):
shutil.rmtree(deploy.datadir)

del data[version]
with open(".deploy_mysqld", "w") as f:
with open(DEPLOY_MYSQLD_PATH, "w") as f:
dump_deploy(data, f)


Expand All @@ -60,8 +65,8 @@ class Instance:


def load_deploy():
if os.path.exists(".deploy_mysqld"):
with open(".deploy_mysqld", "r") as f:
if os.path.exists(DEPLOY_MYSQLD_PATH):
with open(DEPLOY_MYSQLD_PATH, "r") as f:
try:
data = json.load(f)
for k, v in data.items():
Expand Down Expand Up @@ -90,12 +95,12 @@ def mDeploy(version):
return

mContainer = MySqlContainer(f"mysql:{version}")
datadir = os.getcwd() + f"/datadir/{version}"
datadir = DATADIR_BASE / f"/datadir/{version}"
mContainer.with_volume_mapping(datadir, "/var/lib/mysql", "rw")
os.makedirs(datadir)
mContainer.with_kwargs(remove=True, user=os.getuid(), userns_mode="host")
mysql = mContainer.start()
with open(".deploy_mysqld", "w") as f:
with open(DEPLOY_MYSQLD_PATH, "w") as f:
deploy_container[version] = Instance(
url=mysql.get_connection_url().replace("localhost", "127.0.0.1"),
container_id=f"{mysql._container.short_id}",
Expand Down Expand Up @@ -138,6 +143,10 @@ def exec(version, sql, file):
url = deploy_container.get(version).url
engine = create_engine(url)
if file != "":
if not os.path.isabs(file):
poe_cwd = os.getenv("POE_CWD")
if poe_cwd:
file = os.path.join(poe_cwd, file)
with open(file, "r") as f:
sql = f.read()
with engine.connect() as conn:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyinnodb"
version = "0.0.28"
version = "0.0.29"
description = "A parser for InnoDB file formats, in Python"
authors = [
{ name = "WinChua", email = "winchua@foxmail.com" }
Expand Down Expand Up @@ -57,6 +57,6 @@ of = ["of:init", "of:req", "of:cp", "of:clean", "of:zip", "of:patch", "of:ex"]
"of:zip" = "python -m zipapp target/ -m pyinnodb.cli:main -o pyinnodb.sh"
"of:patch" = 'sed -i "1i\#!/usr/bin/env python3" pyinnodb.sh'
"of:ex" = 'chmod a+x pyinnodb.sh'
"dp" = "python devtools/deploy_mysqld.py"
"dp" = "python ${POE_ROOT}/devtools/deploy_mysqld.py"
"td" = "tar cvzf tests/test_data.tgz tests/mysql5/ tests/mysql8"
bp.shell = "uv version --bump patch && git add -u . && git commit -m \"version release: `uv version --short`\" && git push"
4 changes: 4 additions & 0 deletions src/pyinnodb/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .main import *
import os

if __name__ == "__main__":
poe_cwd = os.getenv("POE_CWD")
if poe_cwd:
os.chdir(poe_cwd)
main()
3 changes: 2 additions & 1 deletion tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pathlib
import pytest
from collections import namedtuple
#ruff: noqa

# ruff: noqa
from pyinnodb import const

cur_file = pathlib.Path(__file__)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_parse_mysql8(mysqlfile: MysqlFile):
REAL=1092.892,
SMALLINT=981,
TEXT="TEXT",
TIME=MTime2(bin_data=b'\x801\x00'),
TIME=MTime2(bin_data=b"\x801\x00"),
TIMESTAMP=datetime.datetime.strptime("2024-07-24 09:05:28", timeformat).replace(
tzinfo=datetime.timezone.utc
),
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.