Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmylo committed May 5, 2023
0 parents commit 80e231e
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 0 deletions.
4 changes: 4 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


def ensure_installed():
pass
5 changes: 5 additions & 0 deletions install_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;;; Do not run pip install -r on this file, let the installer handle it.
;;; Every line will be executed like [package package package];[args];[condition];[comment].
;;; If there's no condition, always install.
torch torchvision torchaudio;--index-url https://download.pytorch.org/whl/cu117;windows
torch torchvision torchaudio;;not windows
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from logging import info
from install import ensure_installed

info('Checking installs and venv')

ensure_installed() # Installs missing packages
8 changes: 8 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@echo off
where py -V > nul 2> nul
if %errorlevel%==0 (
call run_py.bat
) else (
call run_python.bat
)
pause
2 changes: 2 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python main.py
read -n1 -r -p "Press any key to exit..." key
3 changes: 3 additions & 0 deletions run_py.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
py main.py
pause
3 changes: 3 additions & 0 deletions run_python.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
python main.py
pause
Empty file added setup_tools/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions setup_tools/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def run_command(command, args=''):
pass
5 changes: 5 additions & 0 deletions setup_tools/os.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os


def is_windows():
return os.name == 'nt'
27 changes: 27 additions & 0 deletions setup_tools/requirements_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .os import is_windows


def parse_requirements(req_file='install_requirements.txt'):

# Some stuff for the install_requirements
windows = is_windows()

requirements_parsed = []
with open(req_file, 'r') as file:
for line in file.readlines():
line = line.strip()

# Make sure it can be unpacked
semis = line.count(';')
add_semis = (2 - semis) * ';'
line = line + add_semis

packages, args, condition = line.split(';')[:3]
# if eval(condition):
if condition:
if eval(condition):
for package in packages.split(' '):
package = package.strip()
if package:
requirements_parsed.append(f'{package} {args}')
return requirements_parsed
31 changes: 31 additions & 0 deletions setup_tools/venv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys
from .os import is_windows
import os

venv_name = 'venv'
venv_activate_path = f'{venv_name}/' + 'Scripts/activate.bat' if is_windows() else 'bin/activate'


def get_base_prefix_compat():
"""Get base/real prefix, or sys.prefix if there is none."""
return getattr(sys, "base_prefix", None) or getattr(sys, "real_prefix", None) or sys.prefix


def in_venv():
return get_base_prefix_compat() != sys.prefix


def activate_venv():
if not os.path.isdir(venv_name):
pass
# Launch the main.py with the venv
exit() # Exit after the venv'ed version exits


def ensure_venv():
if not in_venv():
print('activating venv')
activate_venv()
else:
print('in venv')
print('after venv in venv:', in_venv())

0 comments on commit 80e231e

Please sign in to comment.