Skip to content

Commit 3a68bbb

Browse files
authored
🚚 move package to src directory (#110)
1 parent 2ac7aac commit 3a68bbb

File tree

15 files changed

+74
-52
lines changed

15 files changed

+74
-52
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
id: compare
2525
run: |
2626
set -e
27-
VERSION=$(awk -F'"' '/__version__/ {print $2}' sqlite3_to_mysql/__init__.py)
27+
VERSION=$(awk -F'"' '/__version__/ {print $2}' src/sqlite3_to_mysql/__init__.py)
2828
TAG=${GITHUB_REF_NAME#v}
2929
if [[ "$VERSION" != "$TAG" ]]; then
30-
echo "Version in sqlite3_to_mysql/__version__.py ($VERSION) does not match tag ($TAG)"
30+
echo "Version in src/sqlite3_to_mysql/__version__.py ($VERSION) does not match tag ($TAG)"
3131
exit 1
3232
fi
3333
echo "VERSION=$VERSION" >> $GITHUB_ENV

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ jobs:
508508
- name: Upload coverage to Codecov
509509
uses: codecov/codecov-action@v4
510510
with:
511+
token: ${{ secrets.CODECOV_TOKEN }}
512+
slug: techouse/sqlite3-to-mysql
511513
files: ./coverage.xml
512514
env_vars: OS,PYTHON
513515
verbose: true

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ Sponsor = "https://github.com/sponsors/techouse"
5757
PayPal = "https://paypal.me/ktusar"
5858

5959
[tool.hatch.version]
60-
path = "sqlite3_to_mysql/__init__.py"
60+
path = "src/sqlite3_to_mysql/__init__.py"
6161

6262
[tool.hatch.build.targets.sdist]
6363
include = [
64-
"sqlite3_to_mysql",
64+
"src",
6565
"tests",
6666
"README.md",
6767
"CHANGELOG.md",
@@ -103,6 +103,7 @@ known_first_party = "sqlite3_to_mysql"
103103
skip_gitignore = true
104104

105105
[tool.pytest.ini_options]
106+
pythonpath = ["src"]
106107
testpaths = ["tests"]
107108
norecursedirs = [".*", "venv", "env", "*.egg", "dist", "build"]
108109
minversion = "7.3.1"
@@ -115,6 +116,7 @@ markers = [
115116
]
116117

117118
[tool.mypy]
119+
mypy_path = "src"
118120
python_version = "3.8"
119121
exclude = [
120122
"tests",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utility to transfer data from SQLite 3 to MySQL."""
2+
23
__version__ = "2.1.7"
34

45
from .transporter import SQLite3toMySQL

sqlite3_to_mysql/cli.py renamed to src/sqlite3_to_mysql/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""The command line interface of SQLite3toMySQL."""
2+
23
import os
34
import sys
45
import typing as t
File renamed without changes.
File renamed without changes.

sqlite3_to_mysql/mysql_utils.py renamed to src/sqlite3_to_mysql/mysql_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""MySQL helpers."""
2+
23
import re
34
import typing as t
45

File renamed without changes.

sqlite3_to_mysql/transporter.py renamed to src/sqlite3_to_mysql/transporter.py

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ def _translate_type_from_sqlite_to_mysql(self, column_type: str) -> str:
273273
if data_type == "UNSIGNED BIG INT":
274274
return f"BIGINT{self._column_type_length(column_type)} UNSIGNED"
275275
if data_type.startswith(("TINYINT", "INT1")):
276-
print("length", self._column_type_length(column_type))
277276
return f"TINYINT{self._column_type_length(column_type)}{' UNSIGNED' if unsigned else ''}"
278277
if data_type.startswith(("SMALLINT", "INT2")):
279278
return f"SMALLINT{self._column_type_length(column_type)}{' UNSIGNED' if unsigned else ''}"
@@ -349,9 +348,13 @@ def _create_table(self, table_name: str, transfer_rowid: bool = False) -> None:
349348
type=column_type,
350349
notnull="NOT NULL" if column["notnull"] or column["pk"] else "NULL",
351350
auto_increment="AUTO_INCREMENT" if auto_increment else "",
352-
default="DEFAULT " + column["dflt_value"]
353-
if column["dflt_value"] and column_type not in MYSQL_COLUMN_TYPES_WITHOUT_DEFAULT and not auto_increment
354-
else "",
351+
default=(
352+
"DEFAULT " + column["dflt_value"]
353+
if column["dflt_value"]
354+
and column_type not in MYSQL_COLUMN_TYPES_WITHOUT_DEFAULT
355+
and not auto_increment
356+
else ""
357+
),
355358
)
356359

357360
if column["pk"] > 0:
@@ -438,9 +441,11 @@ def _add_indices(self, table_name: str) -> None:
438441
index_columns = ", ".join(
439442
"`{column}`{length}".format(
440443
column=safe_identifier_length(index_info["name"]),
441-
length="(255)"
442-
if table_columns[index_info["name"]].upper() in MYSQL_TEXT_COLUMN_TYPES_WITH_JSON
443-
else "",
444+
length=(
445+
"(255)"
446+
if table_columns[index_info["name"]].upper() in MYSQL_TEXT_COLUMN_TYPES_WITH_JSON
447+
else ""
448+
),
444449
)
445450
for index_info in index_infos
446451
)
@@ -478,9 +483,11 @@ def _add_indices(self, table_name: str) -> None:
478483
index_columns=", ".join(
479484
"`{column}`{length}".format(
480485
column=safe_identifier_length(index_info["name"]),
481-
length="(255)"
482-
if table_columns[index_info["name"]].upper() in MYSQL_TEXT_COLUMN_TYPES_WITH_JSON
483-
else "",
486+
length=(
487+
"(255)"
488+
if table_columns[index_info["name"]].upper() in MYSQL_TEXT_COLUMN_TYPES_WITH_JSON
489+
else ""
490+
),
484491
)
485492
for index_info in index_infos
486493
),
@@ -498,16 +505,20 @@ def _add_index(
498505
index_infos: t.Tuple[t.Dict[str, t.Any], ...],
499506
index_iteration: int = 0,
500507
) -> None:
501-
sql: str = """
508+
sql: str = (
509+
"""
502510
ALTER TABLE `{table}`
503511
ADD {index_type} `{name}`({columns})
504512
""".format(
505-
table=safe_identifier_length(table_name),
506-
index_type=index_type,
507-
name=safe_identifier_length(index["name"])
508-
if index_iteration == 0
509-
else f'{safe_identifier_length(index["name"], max_length=60)}_{index_iteration}',
510-
columns=index_columns,
513+
table=safe_identifier_length(table_name),
514+
index_type=index_type,
515+
name=(
516+
safe_identifier_length(index["name"])
517+
if index_iteration == 0
518+
else f'{safe_identifier_length(index["name"], max_length=60)}_{index_iteration}'
519+
),
520+
columns=index_columns,
521+
)
511522
)
512523

513524
try:
@@ -580,12 +591,16 @@ def _add_foreign_keys(self, table_name: str) -> None:
580591
column=safe_identifier_length(foreign_key["from"]),
581592
ref_table=safe_identifier_length(foreign_key["table"]),
582593
ref_column=safe_identifier_length(foreign_key["to"]),
583-
on_delete=foreign_key["on_delete"].upper()
584-
if foreign_key["on_delete"].upper() != "SET DEFAULT"
585-
else "NO ACTION",
586-
on_update=foreign_key["on_update"].upper()
587-
if foreign_key["on_update"].upper() != "SET DEFAULT"
588-
else "NO ACTION",
594+
on_delete=(
595+
foreign_key["on_delete"].upper()
596+
if foreign_key["on_delete"].upper() != "SET DEFAULT"
597+
else "NO ACTION"
598+
),
599+
on_update=(
600+
foreign_key["on_update"].upper()
601+
if foreign_key["on_update"].upper() != "SET DEFAULT"
602+
else "NO ACTION"
603+
),
589604
)
590605

591606
try:
@@ -686,18 +701,20 @@ def transfer(self) -> None:
686701
safe_identifier_length(column[0]) for column in self._sqlite_cur.description
687702
]
688703
if self._mysql_insert_method.upper() == "UPDATE":
689-
sql: str = """
704+
sql: str = (
705+
"""
690706
INSERT
691707
INTO `{table}` ({fields})
692708
VALUES ({placeholders}) AS `__new__`
693709
ON DUPLICATE KEY UPDATE {field_updates}
694710
""".format(
695-
table=safe_identifier_length(table["name"]),
696-
fields=("`{}`, " * len(columns)).rstrip(" ,").format(*columns),
697-
placeholders=("%s, " * len(columns)).rstrip(" ,"),
698-
field_updates=("`{}`=`__new__`.`{}`, " * len(columns))
699-
.rstrip(" ,")
700-
.format(*list(chain.from_iterable((column, column) for column in columns))),
711+
table=safe_identifier_length(table["name"]),
712+
fields=("`{}`, " * len(columns)).rstrip(" ,").format(*columns),
713+
placeholders=("%s, " * len(columns)).rstrip(" ,"),
714+
field_updates=("`{}`=`__new__`.`{}`, " * len(columns))
715+
.rstrip(" ,")
716+
.format(*list(chain.from_iterable((column, column) for column in columns))),
717+
)
701718
)
702719
else:
703720
sql = """

sqlite3_to_mysql/types.py renamed to src/sqlite3_to_mysql/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Types for sqlite3-to-mysql."""
2+
23
import os
34
import typing as t
45
from logging import Logger

tests/func/sqlite3_to_mysql_test.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
313313
mysql_inspect: Inspector = inspect(mysql_engine)
314314
mysql_tables: t.List[str] = mysql_inspect.get_table_names()
315315

316-
mysql_connector_connection: t.Union[
317-
PooledMySQLConnection, MySQLConnection, CMySQLConnection
318-
] = mysql.connector.connect(
319-
user=mysql_credentials.user,
320-
password=mysql_credentials.password,
321-
host=mysql_credentials.host,
322-
port=mysql_credentials.port,
323-
database=mysql_credentials.database,
316+
mysql_connector_connection: t.Union[PooledMySQLConnection, MySQLConnection, CMySQLConnection] = (
317+
mysql.connector.connect(
318+
user=mysql_credentials.user,
319+
password=mysql_credentials.password,
320+
host=mysql_credentials.host,
321+
port=mysql_credentials.port,
322+
database=mysql_credentials.database,
323+
)
324324
)
325325
server_version: t.Tuple[int, ...] = mysql_connector_connection.get_server_version()
326326

@@ -370,9 +370,7 @@ def test_transfer_transfers_all_tables_in_sqlite_file(
370370
AND i.CONSTRAINT_TYPE = :constraint_type
371371
""".format(
372372
# MySQL 8.0.19 still works with "LEFT JOIN" everything above requires "JOIN"
373-
JOIN="JOIN"
374-
if (server_version[0] == 8 and server_version[2] > 19)
375-
else "LEFT JOIN"
373+
JOIN="JOIN" if (server_version[0] == 8 and server_version[2] > 19) else "LEFT JOIN"
376374
)
377375
).bindparams(
378376
table_schema=mysql_credentials.database,

tests/func/test_cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ def test_quiet(
540540
sqlite3mysql,
541541
arguments,
542542
)
543-
print(result.output)
544543
assert result.exit_code == 0
545544
assert (
546545
f"{sqlite3mysql.name} version {package_version} Copyright (c) 2018-{datetime.now().year} Klemen Tusar"

tox.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ passenv =
2626
deps =
2727
-rrequirements_dev.txt
2828
commands =
29-
pytest -v --cov=sqlite3_to_mysql --cov-report=xml
29+
pytest -v --cov=src/sqlite3_to_mysql --cov-report=xml
3030

3131
[testenv:black]
3232
basepython = python3
3333
skip_install = true
3434
deps =
3535
black
3636
commands =
37-
black sqlite3_to_mysql tests/
37+
black src/sqlite3_to_mysql tests/
3838

3939
[testenv:isort]
4040
basepython = python3
@@ -54,7 +54,7 @@ deps =
5454
flake8-import-order
5555
flake8-typing-imports
5656
pep8-naming
57-
commands = flake8 sqlite3_to_mysql
57+
commands = flake8 src/sqlite3_to_mysql
5858

5959
[testenv:pylint]
6060
basepython = python3
@@ -63,15 +63,15 @@ deps =
6363
pylint
6464
-rrequirements_dev.txt
6565
commands =
66-
pylint --rcfile=tox.ini sqlite3_to_mysql
66+
pylint --rcfile=tox.ini src/sqlite3_to_mysql
6767

6868
[testenv:bandit]
6969
basepython = python3
7070
skip_install = true
7171
deps =
7272
bandit
7373
commands =
74-
bandit -r sqlite3_to_mysql -c .bandit.yml
74+
bandit -r src/sqlite3_to_mysql -c .bandit.yml
7575

7676
[testenv:mypy]
7777
basepython = python3
@@ -80,7 +80,7 @@ deps =
8080
mypy>=1.3.0
8181
-rrequirements_dev.txt
8282
commands =
83-
mypy sqlite3_to_mysql --enable-incomplete-feature=Unpack
83+
mypy src/sqlite3_to_mysql
8484

8585
[testenv:linters]
8686
basepython = python3

0 commit comments

Comments
 (0)