codec-bridge 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codec_bridge-0.2.1 → codec_bridge-0.2.2}/PKG-INFO +1 -1
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2}/codec_bridge/encoding_translator.py +1 -2
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2}/codec_bridge.egg-info/PKG-INFO +1 -1
- codec_bridge-0.2.2/codec_bridge.egg-info/SOURCES.txt +16 -0
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2}/codec_bridge.egg-info/top_level.txt +1 -1
- {codec_bridge-0.2.1 → codec_bridge-0.2.2}/pyproject.toml +1 -1
- {codec_bridge-0.2.1 → codec_bridge-0.2.2}/setup.py +2 -3
- codec_bridge-0.2.2/tests/__init__.py +0 -0
- codec_bridge-0.2.2/tests/duckdb_utils.py +21 -0
- codec_bridge-0.2.2/tests/generate_test_data.py +60 -0
- codec_bridge-0.2.1/src/codec_bridge.egg-info/SOURCES.txt +0 -13
- {codec_bridge-0.2.1 → codec_bridge-0.2.2}/README.md +0 -0
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2}/codec_bridge/__init__.py +0 -0
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2/codec_bridge}/repository/__init__.py +0 -0
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2/codec_bridge}/repository/python_to_duckdb.py +0 -0
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2}/codec_bridge.egg-info/dependency_links.txt +0 -0
- {codec_bridge-0.2.1/src → codec_bridge-0.2.2}/codec_bridge.egg-info/requires.txt +0 -0
- {codec_bridge-0.2.1 → codec_bridge-0.2.2}/license.txt +0 -0
- {codec_bridge-0.2.1 → codec_bridge-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codec_bridge
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)
|
|
5
5
|
Home-page: https://github.com/jpferraz-git/codec_bridge
|
|
6
6
|
Author: João Pedro Ferraz Bezerra
|
|
@@ -2,8 +2,7 @@ import charset_normalizer
|
|
|
2
2
|
import os
|
|
3
3
|
import re
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
|
|
5
|
+
from codec_bridge.repository.python_to_duckdb import PYTHON_TO_DUCKDB_ENCODING, ENCODINGS_UNDERSCORE_CONFLICT
|
|
7
6
|
|
|
8
7
|
def get_duckdb_encoding(python_encoding_name: str) -> str:
|
|
9
8
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codec_bridge
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)
|
|
5
5
|
Home-page: https://github.com/jpferraz-git/codec_bridge
|
|
6
6
|
Author: João Pedro Ferraz Bezerra
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
license.txt
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
codec_bridge/__init__.py
|
|
6
|
+
codec_bridge/encoding_translator.py
|
|
7
|
+
codec_bridge.egg-info/PKG-INFO
|
|
8
|
+
codec_bridge.egg-info/SOURCES.txt
|
|
9
|
+
codec_bridge.egg-info/dependency_links.txt
|
|
10
|
+
codec_bridge.egg-info/requires.txt
|
|
11
|
+
codec_bridge.egg-info/top_level.txt
|
|
12
|
+
codec_bridge/repository/__init__.py
|
|
13
|
+
codec_bridge/repository/python_to_duckdb.py
|
|
14
|
+
tests/__init__.py
|
|
15
|
+
tests/duckdb_utils.py
|
|
16
|
+
tests/generate_test_data.py
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
codec_bridge
|
|
2
|
-
|
|
2
|
+
tests
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codec_bridge"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "João Pedro Ferraz Bezerra", email = "jpferraz554@gmail.com" }
|
|
@@ -2,9 +2,8 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='codec_bridge',
|
|
5
|
-
version='0.2.
|
|
6
|
-
packages=find_packages(
|
|
7
|
-
package_dir={"": "src"},
|
|
5
|
+
version='0.2.2',
|
|
6
|
+
packages=find_packages(),
|
|
8
7
|
description='Encoding and case normalization bridge for DuckDB and other engines',
|
|
9
8
|
long_description=open('README.md', encoding='utf-8').read(),
|
|
10
9
|
long_description_content_type='text/markdown',
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import os
|
|
2
|
+
def create_table_from_csv(conn, file_path: str, table_name: str, delimiter: str = '|', encoding: str = "utf-8"):
|
|
3
|
+
"""
|
|
4
|
+
Create a table on DuckDB
|
|
5
|
+
"""
|
|
6
|
+
print(f"Processando '{os.path.basename(file_path)}': Tabela='{table_name}', Encoding='{encoding}', Delim='{delimiter}'")
|
|
7
|
+
try:
|
|
8
|
+
conn.sql(f"""
|
|
9
|
+
CREATE OR REPLACE TEMP TABLE "{table_name}" AS
|
|
10
|
+
(SELECT * FROM
|
|
11
|
+
read_csv('{file_path}',
|
|
12
|
+
delim='{delimiter}',
|
|
13
|
+
encoding='{encoding}',
|
|
14
|
+
header=true,
|
|
15
|
+
auto_detect=true
|
|
16
|
+
) LIMIT 1000)
|
|
17
|
+
""")
|
|
18
|
+
print(f"✅ Tabela '{table_name}' criada com sucesso.")
|
|
19
|
+
print(conn.sql(f'SELECT * FROM "{table_name}" LIMIT 3'))
|
|
20
|
+
except Exception as e:
|
|
21
|
+
print(f"❌ ERRO ao criar a tabela '{table_name}': {e}")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
DEFAULT_OUTPUT_DIR = os.path.join(os.path.dirname(__file__), "assets")
|
|
5
|
+
|
|
6
|
+
def generate_csv_test_files(output_dir: str = DEFAULT_OUTPUT_DIR, num_rows: int = 1000):
|
|
7
|
+
"""
|
|
8
|
+
Generates a suite of CSV files with different encodings and characters
|
|
9
|
+
to be used as assets for running tests.
|
|
10
|
+
"""
|
|
11
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
12
|
+
print(f"Generating test files in: {output_dir}")
|
|
13
|
+
|
|
14
|
+
encodings_to_test = [
|
|
15
|
+
"utf-8", "utf-16", "iso-8859-1", "windows-1252",
|
|
16
|
+
"ascii", "iso-8859-2", "iso-8859-5", "koi8-r",
|
|
17
|
+
"shift_jis", "gbk", "big5", "windows-1253", "iso-8859-15"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
# Dictionary of "killer characters" to make each encoding unique
|
|
21
|
+
special_chars = {
|
|
22
|
+
"iso-8859-1": "ç",
|
|
23
|
+
"windows-1252": "€",
|
|
24
|
+
"iso-8859-2": "ść",
|
|
25
|
+
"iso-8859-5": "ДЖ",
|
|
26
|
+
"koi8-r": "ДЖ",
|
|
27
|
+
"shift_jis": "ア",
|
|
28
|
+
"gbk": "你好",
|
|
29
|
+
"big5": "你好",
|
|
30
|
+
"windows-1253": "αβ",
|
|
31
|
+
"iso-8859-15": "€",
|
|
32
|
+
"utf-8": "🚀",
|
|
33
|
+
"utf-16": "🚀",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
def generate_rows(example_char=""):
|
|
37
|
+
# Add the special character to the first cell of each row
|
|
38
|
+
return [[f"Data_{i}_{j}{example_char if j == 0 else ''}" for j in range(10)] for i in range(num_rows)]
|
|
39
|
+
|
|
40
|
+
# Loop through encodings and generate files
|
|
41
|
+
for enc in encodings_to_test:
|
|
42
|
+
filename = os.path.join(output_dir, f"test_{enc}.csv")
|
|
43
|
+
special_char = special_chars.get(enc, "")
|
|
44
|
+
rows = generate_rows(special_char)
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
with open(filename, mode="w", encoding=enc, newline="") as file:
|
|
48
|
+
writer = csv.writer(file)
|
|
49
|
+
writer.writerow(["Header_1", "Header_2", "Header_3", "Header_4", "Header_5"])
|
|
50
|
+
writer.writerows(rows)
|
|
51
|
+
print(f"✅ Generated: {os.path.basename(filename)} (with char: '{special_char}')")
|
|
52
|
+
except UnicodeEncodeError:
|
|
53
|
+
print(f"❌ Encoding Error with {enc}: The character '{special_char}' is not supported.")
|
|
54
|
+
except Exception as e:
|
|
55
|
+
print(f"⚠️ Unexpected Error with {enc}: {e}")
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
# This allows you to run the script directly to generate the files
|
|
59
|
+
# python tests/generate_test_data.py
|
|
60
|
+
generate_csv_test_files()
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
README.md
|
|
2
|
-
license.txt
|
|
3
|
-
pyproject.toml
|
|
4
|
-
setup.py
|
|
5
|
-
src/codec_bridge/__init__.py
|
|
6
|
-
src/codec_bridge/encoding_translator.py
|
|
7
|
-
src/codec_bridge.egg-info/PKG-INFO
|
|
8
|
-
src/codec_bridge.egg-info/SOURCES.txt
|
|
9
|
-
src/codec_bridge.egg-info/dependency_links.txt
|
|
10
|
-
src/codec_bridge.egg-info/requires.txt
|
|
11
|
-
src/codec_bridge.egg-info/top_level.txt
|
|
12
|
-
src/repository/__init__.py
|
|
13
|
-
src/repository/python_to_duckdb.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|