codec-bridge 0.2.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codec_bridge
3
- Version: 0.2.0
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
@@ -31,7 +31,7 @@ Classifier: Programming Language :: Python :: 3.12
31
31
  Classifier: Operating System :: OS Independent
32
32
  Classifier: Operating System :: Microsoft :: Windows
33
33
  Classifier: Operating System :: POSIX :: Linux
34
- Requires-Python: >=3.12
34
+ Requires-Python: >=3.11
35
35
  Description-Content-Type: text/markdown
36
36
  License-File: license.txt
37
37
  Requires-Dist: charset-normalizer>=3.4.2
@@ -2,8 +2,7 @@ import charset_normalizer
2
2
  import os
3
3
  import re
4
4
 
5
- from repository.python_to_duckdb import PYTHON_TO_DUCKDB_ENCODING, ENCODINGS_UNDERSCORE_CONFLICT
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
  """
@@ -112,30 +111,4 @@ def write_utf8_csv(file_path: str, new_csv_file_path: str):
112
111
  with open(file_path, 'r') as file:
113
112
  with open(new_csv_file_path, 'w', encoding='utf-8') as new_file:
114
113
  for line in file:
115
- new_file.write(line)
116
-
117
- if __name__ == "__main__":
118
- import duckdb
119
- from tests.duckdb_utils import create_table_from_csv
120
-
121
- csv_directory_path = "//tests/assets/"
122
-
123
- connection = duckdb.connect(database=":memory:")
124
-
125
- connection.execute("INSTALL encodings")
126
- connection.execute("LOAD encodings")
127
-
128
- detector = get_duckdb_encoding(csv_directory_path)
129
-
130
- file_results = process_files(csv_directory_path)
131
-
132
- for result in file_results:
133
- create_table_from_csv(
134
- conn=connection,
135
- file_path=result["path"],
136
- table_name=result["table_name"],
137
- delimiter=result["delimiter"],
138
- encoding=result["duckdb_encoding"]
139
- )
140
-
141
- connection.close()
114
+ new_file.write(line)
File without changes
@@ -0,0 +1,80 @@
1
+ PYTHON_TO_DUCKDB_ENCODING = {
2
+ # --- UTF-8 ---
3
+ 'utf_8': 'utf-8',
4
+ 'utf8': 'utf_8',
5
+ 'utf_16': 'utf-16',
6
+ 'utf-16': 'utf-16',
7
+ 'utf_16be': 'utf-16-be',
8
+ 'utf_16le': 'utf-16-le',
9
+
10
+ # --- ASCII ---
11
+ 'ascii': 'ascii',
12
+ 'us-ascii': 'ascii',
13
+ 'ibm-367_p100-1995': 'ascii',
14
+ 'iso-ir-6': 'ascii',
15
+
16
+ # --- Latin-1 (Ocidental Europe) ---
17
+ 'latin-1': 'latin_1',
18
+ 'latin1': 'latin_1',
19
+ 'iso-8859-1': 'latin_1',
20
+ 'iso_8859_1': 'latin_1',
21
+ 'ibm-819': 'latin_1',
22
+ 'cp819': 'latin_1',
23
+ 'iso8859_1': 'latin_1',
24
+ 'iso8859_14': 'ISO_8859_14',
25
+ 'iso8859_10': 'ISO_8859_10',
26
+
27
+ # --- Windows-1252 ---
28
+ 'windows-1252': 'ISO8859_1',
29
+ 'cp1252': 'windows_1252',
30
+
31
+ # --- Latin-2 (Central Europe / Oriental Europe) ---
32
+ 'iso-8859-2': 'latin_2',
33
+ 'iso_8859_2': 'latin_2',
34
+ 'latin-2': 'latin_2',
35
+ 'latin2': 'latin_2',
36
+ 'windows-1250': 'CP1250',
37
+ 'cp1250': 'windows_1250',
38
+ 'cp852': 'cp852',
39
+ "mac_iceland": "MAC_IS",
40
+
41
+ # --- Cyrillic ---
42
+ 'iso-8859-5': 'iso_8859_5',
43
+ 'iso_8859_5': 'iso_8859_5',
44
+ 'cyrillic': 'iso_8859_5',
45
+ 'windows-1251': 'windows_1251',
46
+ 'cp1251': 'windows_1251',
47
+ 'koi8-r': 'koi8_r',
48
+ 'koi8_r': 'koi8_r',
49
+
50
+ # --- Greek ---
51
+ 'iso-8859-7': 'iso_8859_7',
52
+ 'iso_8859_7': 'iso_8859_7',
53
+ 'windows-1253': 'windows_1253',
54
+ 'cp1253': 'windows_1253',
55
+
56
+ # --- Japenese ---
57
+ 'shift_jis': 'shift_jis',
58
+ 'sjis': 'shift_jis',
59
+ 'ibm-943': 'shift_jis',
60
+ 'windows-932': 'shift_jis',
61
+ 'euc-jp': 'euc_jp',
62
+
63
+ # --- Chinese ---
64
+ 'gbk': 'gbk',
65
+ 'gb2312': 'gb2312',
66
+ 'big5': 'big5',
67
+
68
+ # --- Korean ---
69
+ 'euc-kr': 'euc_kr',
70
+ 'cp949': 'cp949',
71
+ 'johab': 'johab',
72
+ }
73
+
74
+ ENCODINGS_UNDERSCORE_CONFLICT = {
75
+ 'shift_jis',
76
+ 'cp932',
77
+ 'big5',
78
+ 'gbk',
79
+ 'gb2312',
80
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codec_bridge
3
- Version: 0.2.0
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
@@ -31,7 +31,7 @@ Classifier: Programming Language :: Python :: 3.12
31
31
  Classifier: Operating System :: OS Independent
32
32
  Classifier: Operating System :: Microsoft :: Windows
33
33
  Classifier: Operating System :: POSIX :: Linux
34
- Requires-Python: >=3.12
34
+ Requires-Python: >=3.11
35
35
  Description-Content-Type: text/markdown
36
36
  License-File: license.txt
37
37
  Requires-Dist: charset-normalizer>=3.4.2
@@ -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,13 +1,13 @@
1
1
  [project]
2
2
  name = "codec_bridge"
3
- version = "0.2.0"
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" }
7
7
  ]
8
8
  license = { file = "license.txt"}
9
9
  readme = "README.md"
10
- requires-python = ">=3.12"
10
+ requires-python = ">=3.11"
11
11
 
12
12
  dependencies = [
13
13
  "charset-normalizer>=3.4.2",
@@ -2,9 +2,8 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='codec_bridge',
5
- version='0.2.0',
6
- packages=find_packages(where="src"),
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',
@@ -12,10 +11,10 @@ setup(
12
11
  author_email='jpferraz554@gmail.com',
13
12
  url='https://github.com/jpferraz-git/codec_bridge',
14
13
  classifiers=[
15
- 'Programming Language :: Python :: 3.12',
14
+ 'Programming Language :: Python :: 3.11',
16
15
  'Operating System :: OS Independent',
17
16
  'Operating System :: Microsoft :: Windows',
18
17
  'Operating System :: POSIX :: Linux',
19
18
  ],
20
- python_requires='>=3.12',
19
+ python_requires='>=3.11',
21
20
  )
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,11 +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
File without changes
File without changes
File without changes