Skip to content

Commit 643eebc

Browse files
authored
Merge pull request #19 from kurtmckee/test-bundling
Create a framework for testing bundling and importing
2 parents 6aed888 + 2fc8b78 commit 643eebc

33 files changed

+309
-30
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ci:
44
default_language_version:
55
python: "python3.12"
66

7+
exclude: tests/installed-projects
8+
79
repos:
810
- repo: "meta"
911
hooks:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Development
2+
-----------
3+
4+
* Create a framework for testing bundling and importing.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixed
2+
-----
3+
4+
* Fix a bug that prevented databases bundled on Windows from finding package metadata.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ source = [
4747

4848
[tool.coverage.report]
4949
skip_covered = true
50-
fail_under = 27
50+
fail_under = 52
5151

5252

5353
# mypy

src/sqliteimport/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def add_file(self, directory: pathlib.Path, file: pathlib.Path) -> None:
5858
""",
5959
(
6060
fullname.replace("/", ".").replace("\\", "."),
61-
str(file),
61+
str(pathlib.PurePosixPath(file)),
6262
is_package,
6363
(directory / file).read_text(),
6464
),

src/sqliteimport/bundler.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pathlib
2+
3+
import sqliteimport.accessor
4+
5+
6+
def bundle(directory: pathlib.Path, accessor: sqliteimport.accessor.Accessor) -> None:
7+
"""Bundle files in a directory into a database."""
8+
9+
paths: list[pathlib.Path] = list(directory.glob("*"))
10+
files = []
11+
for path in paths:
12+
rel_path = path.relative_to(directory)
13+
if rel_path.suffix in {".so"}:
14+
continue
15+
if rel_path.name == "__pycache__":
16+
continue
17+
if str(rel_path) == "bin":
18+
continue
19+
if path.is_dir():
20+
files.append(rel_path)
21+
paths.extend(path.glob("*"))
22+
else:
23+
files.append(rel_path)
24+
25+
for file in sorted(files):
26+
is_package = (directory / file / "__init__.py").exists()
27+
print(f"{'* ' if is_package else ' '} {file}")
28+
if (directory / file).is_dir():
29+
continue
30+
accessor.add_file(directory, file)

src/sqliteimport/cli.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import textwrap
55

6+
from . import bundler
67
from .accessor import Accessor
78

89
try:
@@ -43,32 +44,9 @@ def bundle(directory: pathlib.Path, database: pathlib.Path) -> None:
4344
pip install --target=DIRECTORY --requirement=path/to/requirements.txt
4445
"""
4546

46-
paths: list[pathlib.Path] = list(directory.glob("*"))
47-
files = []
48-
for path in paths:
49-
rel_path = path.relative_to(directory)
50-
if rel_path.suffix in {".so"}:
51-
continue
52-
if rel_path.name == "__pycache__":
53-
continue
54-
if str(rel_path) == "bin":
55-
continue
56-
if path.is_dir():
57-
files.append(rel_path)
58-
paths.extend(path.glob("*"))
59-
else:
60-
files.append(rel_path)
47+
with sqlite3.connect(database) as connection:
48+
accessor = Accessor(connection)
49+
accessor.initialize_database()
6150

62-
connection = sqlite3.connect(database)
63-
accessor = Accessor(connection)
64-
accessor.initialize_database()
65-
66-
for file in sorted(files):
67-
is_package = (directory / file / "__init__.py").exists()
68-
print(f"{'* ' if is_package else ' '} {file}")
69-
if (directory / file).is_dir():
70-
continue
71-
accessor.add_file(directory, file)
72-
73-
connection.commit()
74-
connection.close()
51+
bundler.bundle(directory, accessor)
52+
connection.commit()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Metadata-Version: 2.1
2+
Name: module-filesystem
3+
Version: 1.1.1
4+
Summary:
5+
License: MIT
6+
Author: Kurt McKee
7+
Author-email: [email protected]
8+
Classifier: License :: OSI Approved :: MIT License
9+
Classifier: Programming Language :: Python :: 2
10+
Classifier: Programming Language :: Python :: 2.7
11+
Classifier: Programming Language :: Python :: 3
12+
Classifier: Programming Language :: Python :: 3.4
13+
Classifier: Programming Language :: Python :: 3.5
14+
Classifier: Programming Language :: Python :: 3.6
15+
Classifier: Programming Language :: Python :: 3.7
16+
Classifier: Programming Language :: Python :: 3.8
17+
Classifier: Programming Language :: Python :: 3.9
18+
Classifier: Programming Language :: Python :: 3.10
19+
Classifier: Programming Language :: Python :: 3.11
20+
Classifier: Programming Language :: Python :: 3.12
21+
Classifier: Programming Language :: Python :: 3.13
22+
Description-Content-Type: text/x-rst
23+
24+
A single-file module project.
25+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module_filesystem-1.1.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
2+
module_filesystem-1.1.1.dist-info/METADATA,sha256=q63m78qbu8_bgx_cRJQ2R3AN_YP3KN5IVzcsv5S7vgY,911
3+
module_filesystem-1.1.1.dist-info/RECORD,,
4+
module_filesystem-1.1.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5+
module_filesystem-1.1.1.dist-info/WHEEL,sha256=iAMR_6Qh95yyjYIwRxyjpiFq4FhDPemrEV-SyWIQB3U,92
6+
module_filesystem-1.1.1.dist-info/direct_url.json,,
7+
module_filesystem.py,sha256=bUu1TcGpMlFUpoB9EAQVyK4Mb-dhj5n5mNBaqYZrjfM,13

0 commit comments

Comments
 (0)