File size: 2,996 Bytes
837a656
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
from setuptools import setup
from pathlib import Path
import zipfile
import io

# raise NotImplementedError()


def download_real_code(zip_url: str, dest: Path, overwrite=False):
    # download zip_url
    # extract files into dest, but strip 1st path component like tar --strip-components=1
    try:
        # Open the URL with built-in urllib
        with urlopen(zip_url) as response:
            # Read the content
            zip_content = response.read()

            # Create the destination directory if it doesn't exist
            dest.mkdir(parents=True, exist_ok=True)

            # Create a ZipFile object from the downloaded content
            with zipfile.ZipFile(io.BytesIO(zip_content)) as zip_ref:
                # Extract files, stripping the first path component
                for member in zip_ref.infolist():
                    # Skip the first path component
                    parts = member.filename.split("/", 1)
                    if len(parts) > 1:
                        new_filename = parts[1]
                    else:
                        new_filename = member.filename

                    # Skip directories and empty filenames
                    if not new_filename or new_filename.endswith("/"):
                        continue

                    # Extract the file to the destination
                    source = zip_ref.open(member)
                    target = dest / new_filename

                    # Skip existing file
                    if target.exists() and not overwrite:
                        continue

                    # Ensure the target directory exists
                    target.parent.mkdir(parents=True, exist_ok=True)

                    # Write the file content
                    with target.open("wb") as f:
                        f.write(source.read())

    except HTTPError as e:
        print(f"HTTP Error {e.code}: {e.reason}")
        raise
    except URLError as e:
        print(f"URL Error: {e.reason}")
        raise


download_real_code(
    "https://github.com/moeflow-com/manga-image-translator/archive/6b4294bb7b04e037f303d34d46dbc49491b9460f.zip",
    Path(__file__).parent.joinpath("."),
)

version_main = "0.1.0"
version = f"{version_main}"

setup(
    name="mit_gradio_loader",
    version=version,
    author="jokester",
    author_email="momocraft@gmail.com",
    description="transforms",
    # long_description=open('README.md').read(),
    # long_description_content_type='text/markdown',
    url="https://github.com/moeflow-com/manga-image-translator",
    project_urls={
        "Bug Tracker": "https://github.com/moeflow-com/manga-image-translator/issues",
    },
    classifiers=[],
    package_data={},
    packages=["mit_gradio_loader"],
    # package_dir={"": "mit_gradio_loader"},
    include_package_data=False,
    python_requires=">=3.10,<3.13",
    setup_requires=["setuptools>=61.0"],
)