enhance-setup-script (#1)
Browse files- Enhance setup.py with Rich library and polish code (f311738978bb8f3bf5c7de9ba9bcc4fc95537a2b)
Co-authored-by: p3nGu1nZz <p3nGu1nZz@users.noreply.huggingface.co>
- .gitignore +131 -0
- setup.py +143 -0
.gitignore
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.cache/
|
52 |
+
|
53 |
+
# Translations
|
54 |
+
*.mo
|
55 |
+
*.pot
|
56 |
+
|
57 |
+
# Django stuff:
|
58 |
+
*.log
|
59 |
+
local_settings.py
|
60 |
+
|
61 |
+
# Flask stuff:
|
62 |
+
instance/
|
63 |
+
.webassets-cache
|
64 |
+
|
65 |
+
# Scrapy stuff:
|
66 |
+
.scrapy
|
67 |
+
|
68 |
+
# Sphinx documentation
|
69 |
+
docs/_build/
|
70 |
+
|
71 |
+
# PyBuilder
|
72 |
+
target/
|
73 |
+
|
74 |
+
# Jupyter Notebook
|
75 |
+
.ipynb_checkpoints
|
76 |
+
|
77 |
+
# IPython
|
78 |
+
profile_default/
|
79 |
+
ipython_config.py
|
80 |
+
|
81 |
+
# pyenv
|
82 |
+
.python-version
|
83 |
+
|
84 |
+
# pipenv
|
85 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
86 |
+
# However, in case you wish to ignore it, uncomment the following line.
|
87 |
+
# Pipfile.lock
|
88 |
+
|
89 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
90 |
+
__pypackages__/
|
91 |
+
|
92 |
+
# Celery
|
93 |
+
celerybeat-schedule
|
94 |
+
celerybeat.pid
|
95 |
+
|
96 |
+
# SageMath parsed files
|
97 |
+
*.sage.py
|
98 |
+
|
99 |
+
# Environments
|
100 |
+
.env
|
101 |
+
.venv
|
102 |
+
env/
|
103 |
+
venv/
|
104 |
+
ENV/
|
105 |
+
env.bak/
|
106 |
+
venv.bak/
|
107 |
+
.donut/
|
108 |
+
|
109 |
+
# Spyder project settings
|
110 |
+
.spyderproject
|
111 |
+
|
112 |
+
# Rope project settings
|
113 |
+
.ropeproject
|
114 |
+
|
115 |
+
# mkdocs documentation
|
116 |
+
/site
|
117 |
+
|
118 |
+
# mypy
|
119 |
+
.mypy_cache/
|
120 |
+
.dmypy.json
|
121 |
+
dmypy.json
|
122 |
+
|
123 |
+
# Pyre type checker
|
124 |
+
.pyre/
|
125 |
+
|
126 |
+
# pytype static type analyzer
|
127 |
+
.pytype/
|
128 |
+
|
129 |
+
# Cython debug symbols
|
130 |
+
cython_debug/
|
131 |
+
```[_{{{CITATION{{{_1{](https://github.com/newtocodingbrah/new-man-bad-code/tree/6aba7132c453e71e9007846a64568c097ab318b8/README.md)[_{{{CITATION{{{_2{](https://github.com/Preetfip/CRE/tree/ef76ddb821e8ec579307c73ef7abc216800a12ed/.gitignore.py)[_{{{CITATION{{{_3{](https://github.com/TheTumbleweedKid/Tank/tree/5b416c317135dbac9e4fb36d229cf8ffa1e84471/.gitignore.py)
|
setup.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
3 |
+
β Author: p3nGu1nZz β
|
4 |
+
β Email: rawsonkara@gmail.com β
|
5 |
+
β Copyright (c) 2025 Huggingface β
|
6 |
+
β License: MIT β
|
7 |
+
β This source file is subject to the terms and conditions β
|
8 |
+
β defined in the file 'LICENSE', which is part of this sorcery β
|
9 |
+
β code package. β
|
10 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
11 |
+
"""
|
12 |
+
|
13 |
+
DONUT = """
|
14 |
+
β β β β β β β β’β£β£β£β£β£β£β£β β β β β β
|
15 |
+
β β β β’β‘€β β β β β’β β β β β ⠻⠷⣦β‘β β
|
16 |
+
β β β£°β β β β β‘β β β β’ β‘°β β β ⣨β‘β’¦β
|
17 |
+
β β’β£―β ―β β β β β’β£€β£€β£€β£β‘β β β β β β‘
|
18 |
+
β β‘β β β β‘β β‘΄β β β ⠺⑻⣦β β β ²β β β’Ή
|
19 |
+
β’⑷⑦β β β β’Έβ β β β β β£»β£Ώβ β β β β£Ώ
|
20 |
+
β β Ώβ β β β β β’β β β β’⣴⣿β β’Άβ β β’ β‘
|
21 |
+
β β’β’β£€β£β β β β β β β β’©β‘β β β β β‘Ύβ
|
22 |
+
β β β’§β£Έβ ±β β β β β β β β β’β‘ β’€β β£ β β β
|
23 |
+
β β β β β »β’¬β‘©β‘β’β‘β‘β’β£ͺ⣡⣲⑾β β β β β
|
24 |
+
β β β β β β β β β β β β β β β β β β β β β β β β
|
25 |
+
"""
|
26 |
+
|
27 |
+
CONFIG = {
|
28 |
+
"url": "https://download.pytorch.org/whl/cu124",
|
29 |
+
"cmds": [
|
30 |
+
"python -m pip install --upgrade pip",
|
31 |
+
"python -m pip install --upgrade setuptools",
|
32 |
+
"python -m pip install --upgrade wheel"
|
33 |
+
],
|
34 |
+
"pkg_common": ["tqdm==4.62.3", "pillow==8.4.0"],
|
35 |
+
"pkg_cuda" : ["torch==2.5.1+cu124 --index-url https://download.pytorch.org/whl/cu124"],
|
36 |
+
"pkg_cpu" : ["torch==2.5.1"],
|
37 |
+
"pkg_indiv" : ["matplotlib", "numpy==2.1.3"]
|
38 |
+
}
|
39 |
+
|
40 |
+
import subprocess as sp
|
41 |
+
import sys
|
42 |
+
import importlib.metadata as imd
|
43 |
+
|
44 |
+
def ensure_rich():
|
45 |
+
"""
|
46 |
+
Ensure the rich library is installed.
|
47 |
+
"""
|
48 |
+
try:
|
49 |
+
imd.version("rich")
|
50 |
+
except imd.PackageNotFoundError:
|
51 |
+
sp.check_call([sys.executable, "-m", "pip", "install", "rich"])
|
52 |
+
|
53 |
+
# Ensure rich is installed before importing
|
54 |
+
ensure_rich()
|
55 |
+
|
56 |
+
from rich.console import Console
|
57 |
+
from rich.text import Text
|
58 |
+
|
59 |
+
console = Console()
|
60 |
+
|
61 |
+
def run_cmd(cmd):
|
62 |
+
"""
|
63 |
+
Execute a shell command.
|
64 |
+
"""
|
65 |
+
try:
|
66 |
+
sp.check_call(cmd, shell=True)
|
67 |
+
except sp.CalledProcessError as err:
|
68 |
+
console.print(f"[red]Error running command: {cmd}\n{err}[/red]")
|
69 |
+
|
70 |
+
def install_pkg(pkg):
|
71 |
+
"""
|
72 |
+
Install a package using pip.
|
73 |
+
"""
|
74 |
+
try:
|
75 |
+
sp.check_call([sys.executable, "-m", "pip", "install", pkg])
|
76 |
+
except sp.CalledProcessError as err:
|
77 |
+
console.print(f"[red]Error installing package: {pkg}\n{err}[/red]")
|
78 |
+
|
79 |
+
def is_installed(pkg):
|
80 |
+
"""
|
81 |
+
Check if a package is installed.
|
82 |
+
"""
|
83 |
+
try:
|
84 |
+
imd.version(pkg)
|
85 |
+
return True
|
86 |
+
except imd.PackageNotFoundError:
|
87 |
+
return False
|
88 |
+
|
89 |
+
def display_donut():
|
90 |
+
"""
|
91 |
+
Display the ASCII donut art.
|
92 |
+
"""
|
93 |
+
donut_text = Text(DONUT, style="bold magenta")
|
94 |
+
console.print(donut_text)
|
95 |
+
|
96 |
+
def upgrade_tools():
|
97 |
+
"""
|
98 |
+
Upgrade pip, setuptools, and wheel.
|
99 |
+
"""
|
100 |
+
for cmd in CONFIG["cmds"]:
|
101 |
+
run_cmd(cmd)
|
102 |
+
|
103 |
+
def install_packages(packages):
|
104 |
+
"""
|
105 |
+
Install a list of packages if not already installed.
|
106 |
+
"""
|
107 |
+
for pkg in packages:
|
108 |
+
if not is_installed(pkg.split("==")[0]):
|
109 |
+
install_pkg(pkg)
|
110 |
+
|
111 |
+
def ensure_numpy():
|
112 |
+
"""
|
113 |
+
Ensure numpy is compatible.
|
114 |
+
"""
|
115 |
+
try:
|
116 |
+
np_ver = imd.version("numpy")
|
117 |
+
if not np_ver.startswith("2.1.3"):
|
118 |
+
install_pkg("numpy==2.1.3")
|
119 |
+
except imd.PackageNotFoundError:
|
120 |
+
install_pkg("numpy==2.1.3")
|
121 |
+
|
122 |
+
def main():
|
123 |
+
"""
|
124 |
+
Main function to orchestrate the setup.
|
125 |
+
"""
|
126 |
+
display_donut()
|
127 |
+
upgrade_tools()
|
128 |
+
ensure_numpy()
|
129 |
+
install_pkg("matplotlib")
|
130 |
+
install_packages(CONFIG["pkg_common"])
|
131 |
+
try:
|
132 |
+
import torch
|
133 |
+
if torch.cuda.is_available():
|
134 |
+
install_packages(CONFIG["pkg_cuda"])
|
135 |
+
else:
|
136 |
+
install_packages(CONFIG["pkg_cpu"])
|
137 |
+
except ImportError:
|
138 |
+
install_packages(CONFIG["pkg_cpu"])
|
139 |
+
|
140 |
+
console.print("[bold green]All Your Donut Belong To Us![/bold green]\n")
|
141 |
+
|
142 |
+
if __name__ == "__main__":
|
143 |
+
main()
|