Skip to content

Commit 2ca89d2

Browse files
authored
🎨 black & isort (#68)
1 parent 9f26fd5 commit 2ca89d2

File tree

16 files changed

+217
-423
lines changed

16 files changed

+217
-423
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@ name: Test
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches:
6+
- master
67
pull_request:
7-
branches: [ master ]
8+
branches:
9+
- master
10+
defaults:
11+
run:
12+
shell: bash
13+
permissions: read-all
814

915
jobs:
16+
analyze:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Python
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: "3.x"
24+
- name: Install dependencies
25+
run: |
26+
python3 -m pip install --upgrade pip
27+
pip install -r requirements_dev.txt
28+
- name: Run static analysis
29+
run: tox -e linters
1030
test:
31+
needs: analyze
1132
runs-on: ubuntu-latest
1233
strategy:
1334
matrix:

pyproject.toml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,33 @@ license-files = ["LICENSE"]
7373
universal = true
7474

7575
[project.scripts]
76-
sqlite3mysql = "sqlite3_to_mysql.cli:cli"
76+
sqlite3mysql = "sqlite3_to_mysql.cli:cli"
77+
78+
[tool.black]
79+
line-length = 120
80+
target-version = ["py35", "py36", "py37", "py38", "py39", "py310", "py311"]
81+
include = '\.pyi?$'
82+
exclude = '''
83+
(
84+
/(
85+
\.eggs
86+
| \.git
87+
| \.hg
88+
| \.mypy_cache
89+
| \.tox
90+
| \.venv
91+
| _build
92+
| buck-out
93+
| build
94+
| dist
95+
)/
96+
| foo.py
97+
)
98+
'''
99+
100+
[tool.isort]
101+
line_length = 120
102+
profile = "black"
103+
lines_after_imports = 2
104+
known_first_party = "sqlite3_to_mysql"
105+
skip_gitignore = true

sqlite3_to_mysql/cli.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
from . import SQLite3toMySQL
1010
from .click_utils import OptionEatAll, prompt_password
1111
from .debug_info import info
12-
from .mysql_utils import (
13-
MYSQL_INSERT_METHOD,
14-
MYSQL_TEXT_COLUMN_TYPES,
15-
mysql_supported_character_sets,
16-
)
12+
from .mysql_utils import MYSQL_INSERT_METHOD, MYSQL_TEXT_COLUMN_TYPES, mysql_supported_character_sets
1713

1814

1915
@click.command()
@@ -33,19 +29,15 @@
3329
help="Transfer only these specific tables (space separated table names). "
3430
"Implies --without-foreign-keys which inhibits the transfer of foreign keys.",
3531
)
36-
@click.option(
37-
"-X", "--without-foreign-keys", is_flag=True, help="Do not transfer foreign keys."
38-
)
32+
@click.option("-X", "--without-foreign-keys", is_flag=True, help="Do not transfer foreign keys.")
3933
@click.option(
4034
"-W",
4135
"--ignore-duplicate-keys",
4236
is_flag=True,
4337
help="Ignore duplicate keys. The default behavior is to create new ones with a numerical suffix, e.g. "
4438
"'exising_key' -> 'existing_key_1'",
4539
)
46-
@click.option(
47-
"-d", "--mysql-database", default=None, help="MySQL database name", required=True
48-
)
40+
@click.option("-d", "--mysql-database", default=None, help="MySQL database name", required=True)
4941
@click.option("-u", "--mysql-user", default=None, help="MySQL user", required=True)
5042
@click.option(
5143
"-p",
@@ -56,15 +48,9 @@
5648
help="Prompt for MySQL password",
5749
)
5850
@click.option("--mysql-password", default=None, help="MySQL password")
59-
@click.option(
60-
"-h", "--mysql-host", default="localhost", help="MySQL host. Defaults to localhost."
61-
)
62-
@click.option(
63-
"-P", "--mysql-port", type=int, default=3306, help="MySQL port. Defaults to 3306."
64-
)
65-
@click.option(
66-
"-S", "--skip-ssl", is_flag=True, help="Disable MySQL connection encryption."
67-
)
51+
@click.option("-h", "--mysql-host", default="localhost", help="MySQL host. Defaults to localhost.")
52+
@click.option("-P", "--mysql-port", type=int, default=3306, help="MySQL port. Defaults to 3306.")
53+
@click.option("-S", "--skip-ssl", is_flag=True, help="Disable MySQL connection encryption.")
6854
@click.option(
6955
"-i",
7056
"--mysql-insert-method",
@@ -124,15 +110,11 @@
124110
"Will throw an error if your MySQL version does not support InnoDB FULLTEXT indexes!",
125111
)
126112
@click.option("--with-rowid", is_flag=True, help="Transfer rowid columns.")
127-
@click.option(
128-
"-c", "--chunk", type=int, default=None, help="Chunk reading/writing SQL records"
129-
)
113+
@click.option("-c", "--chunk", type=int, default=None, help="Chunk reading/writing SQL records")
130114
@click.option("-l", "--log-file", type=click.Path(), help="Log file")
131115
@click.option("-q", "--quiet", is_flag=True, help="Quiet. Display only errors.")
132116
@click.option("--debug", is_flag=True, help="Debug mode. Will throw exceptions.")
133-
@click.version_option(
134-
message=tabulate(info(), headers=["software", "version"], tablefmt="github")
135-
)
117+
@click.version_option(message=tabulate(info(), headers=["software", "version"], tablefmt="github"))
136118
def cli(
137119
sqlite_file,
138120
sqlite_tables,
@@ -162,10 +144,7 @@ def cli(
162144
"""Transfer SQLite to MySQL using the provided CLI options."""
163145
try:
164146
if mysql_collation:
165-
charset_collations = tuple(
166-
cs.collation
167-
for cs in mysql_supported_character_sets(mysql_charset.lower())
168-
)
147+
charset_collations = tuple(cs.collation for cs in mysql_supported_character_sets(mysql_charset.lower()))
169148
if mysql_collation not in set(charset_collations):
170149
raise click.ClickException(
171150
"Error: Invalid value for '--collation' of charset '{charset}': '{collation}' is not one of "
@@ -179,8 +158,7 @@ def cli(
179158
converter = SQLite3toMySQL(
180159
sqlite_file=sqlite_file,
181160
sqlite_tables=sqlite_tables,
182-
without_foreign_keys=without_foreign_keys
183-
or (sqlite_tables is not None and len(sqlite_tables) > 0),
161+
without_foreign_keys=without_foreign_keys or (sqlite_tables is not None and len(sqlite_tables) > 0),
184162
mysql_user=mysql_user,
185163
mysql_password=mysql_password or prompt_mysql_password,
186164
mysql_database=mysql_database,

sqlite3_to_mysql/click_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def parser_process(value, state):
4040
# call the actual process
4141
self._previous_parser_process(value, state)
4242

43-
retval = super(OptionEatAll, self).add_to_parser( # pylint: disable=E1111
44-
parser, ctx
45-
)
43+
retval = super(OptionEatAll, self).add_to_parser(parser, ctx) # pylint: disable=E1111
4644
for name in self.opts:
4745
# pylint: disable=W0212
4846
our_parser = parser._long_opt.get(name) or parser._short_opt.get(name)

sqlite3_to_mysql/debug_info.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def _implementation():
4343
sys.pypy_version_info.minor, # noqa: ignore=E1101 pylint: disable=E1101
4444
sys.pypy_version_info.micro, # noqa: ignore=E1101 pylint: disable=E1101
4545
)
46-
rel = (
47-
sys.pypy_version_info.releaselevel # noqa: ignore=E1101 pylint: disable=E1101
48-
)
46+
rel = sys.pypy_version_info.releaselevel # noqa: ignore=E1101 pylint: disable=E1101
4947
if rel != "final":
5048
implementation_version = "".join([implementation_version, rel])
5149
elif implementation == "Jython":

sqlite3_to_mysql/mysql_utils.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from mysql.connector.charsets import MYSQL_CHARACTER_SETS
77
from packaging import version
88

9+
910
# Shamelessly copied from SQLAlchemy's dialects/mysql/__init__.py
1011
MYSQL_COLUMN_TYPES = {
1112
"BIGINT",
@@ -103,11 +104,7 @@ def check_mysql_json_support(version_string):
103104
"""Check for MySQL JSON support."""
104105
mysql_version = get_mysql_version(version_string)
105106
if version_string.lower().endswith("-mariadb"):
106-
if (
107-
mysql_version.major >= 10
108-
and mysql_version.minor >= 2
109-
and mysql_version.micro >= 7
110-
):
107+
if mysql_version.major >= 10 and mysql_version.minor >= 2 and mysql_version.micro >= 7:
111108
return True
112109
else:
113110
if mysql_version.major >= 8:
@@ -121,11 +118,7 @@ def check_mysql_fulltext_support(version_string):
121118
"""Check for FULLTEXT indexing support."""
122119
mysql_version = get_mysql_version(version_string)
123120
if version_string.lower().endswith("-mariadb"):
124-
if (
125-
mysql_version.major >= 10
126-
and mysql_version.minor >= 0
127-
and mysql_version.micro >= 5
128-
):
121+
if mysql_version.major >= 10 and mysql_version.minor >= 0 and mysql_version.micro >= 5:
129122
return True
130123
else:
131124
if mysql_version.major >= 8:

sqlite3_to_mysql/sqlite_utils.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from sys import version_info
88

99
import six
10+
from packaging import version
1011
from pytimeparse.timeparse import timeparse
1112
from unidecode import unidecode
12-
from packaging import version
13+
1314

1415
if version_info.major == 3 and 4 <= version_info.minor <= 6:
1516
from backports.datetime_fromisoformat import MonkeyPatch # pylint: disable=E0401
@@ -57,22 +58,16 @@ def convert_date(value):
5758
try:
5859
return date.fromisoformat(value.decode())
5960
except ValueError as err:
60-
raise ValueError( # pylint: disable=W0707
61-
"DATE field contains {}".format(err)
62-
)
61+
raise ValueError("DATE field contains {}".format(err)) # pylint: disable=W0707
6362
try:
6463
return datetime.strptime(value.decode(), "%Y-%m-%d").date()
6564
except ValueError as err:
66-
raise ValueError( # pylint: disable=W0707
67-
"DATE field contains Invalid isoformat string: {}".format(err)
68-
)
65+
raise ValueError("DATE field contains Invalid isoformat string: {}".format(err)) # pylint: disable=W0707
6966

7067

7168
def check_sqlite_table_xinfo_support(version_string):
7269
"""Check for SQLite table_xinfo support."""
7370
sqlite_version = version.parse(version_string)
74-
if sqlite_version.major > 3 or (
75-
sqlite_version.major == 3 and sqlite_version.minor >= 26
76-
):
71+
if sqlite_version.major > 3 or (sqlite_version.major == 3 and sqlite_version.minor >= 26):
7772
return True
7873
return False

0 commit comments

Comments
 (0)