Spaces:
Runtime error
Runtime error
| 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="[email protected]", | |
| 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"], | |
| ) | |