diff --git a/hyfetch/__main__.py b/hyfetch/__main__.py index 2750d868..204ab68f 100644 --- a/hyfetch/__main__.py +++ b/hyfetch/__main__.py @@ -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() diff --git a/hyfetch/py.py b/hyfetch/py.py new file mode 100644 index 00000000..022cd6ad --- /dev/null +++ b/hyfetch/py.py @@ -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() diff --git a/hyfetch/rs.py b/hyfetch/rs.py index e3d723d0..80bafb57 100644 --- a/hyfetch/rs.py +++ b/hyfetch/rs.py @@ -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() diff --git a/setup.py b/setup.py index 5c4c9486..4f16eac7 100755 --- a/setup.py +++ b/setup.py @@ -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']