[F] Fix entry

This commit is contained in:
Azalea Gui 2024-12-22 06:19:24 -05:00
parent 48f52be2d3
commit 8cc06c02b5
4 changed files with 43 additions and 30 deletions

View file

@ -1,31 +1,10 @@
import os
import platform
from pathlib import Path
from . import main
from .color_util import printc
def run_py():
try:
main.run()
except KeyboardInterrupt:
printc('&cThe program is interrupted by ^C, exiting...')
exit(0)
def run_rust():
# Find the rust executable
pd = Path(__file__).parent.joinpath('rust')
pd = pd.joinpath('hyfetch.exe' if platform.system() == 'Windows' else 'hyfetch')
if not pd.exists():
printc('&cThe rust executable is not found, falling back to python...')
run_py()
return
# Run the rust executable
os.system(str(pd))
from .py import run_py
from .rs import run_rust
if __name__ == '__main__':
run_py()
if os.environ.get('HYFETCH_PY', False):
run_py()
else:
run_rust()

13
hyfetch/py.py Normal file
View file

@ -0,0 +1,13 @@
from . import main
from .color_util import printc
def run_py():
try:
main.run()
except KeyboardInterrupt:
printc('&cThe program is interrupted by ^C, exiting...')
exit(0)
if __name__ == '__main__':
run_py()

View file

@ -1,4 +1,24 @@
from .__main__ import run_rust
import platform
import subprocess
import sys
from pathlib import Path
from .color_util import printc
from .py import run_py
def run_rust():
# Find the rust executable
pd = Path(__file__).parent.joinpath('rust')
pd = pd.joinpath('hyfetch.exe' if platform.system() == 'Windows' else 'hyfetch')
if not pd.exists():
printc('&cThe rust executable is not found, falling back to python...')
run_py()
return
# Run the rust executable, passing in all arguments
subprocess.run([str(pd)] + sys.argv[1:])
if __name__ == '__main__':
run_rust()

View file

@ -48,8 +48,9 @@ setup(
],
entry_points={
"console_scripts": [
"hyfetch.py=hyfetch:run_py",
"hyfetch=hyfetch:run_rust",
"hyfetch.v1=hyfetch.__main__:run_py",
"hyfetch.rs=hyfetch.__main__:run_rust",
"hyfetch=hyfetch.__main__:run_rust",
]
},
scripts=['hyfetch/scripts/neowofetch']