Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build-and-publish-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ jobs:
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: python -m twine upload dist/*.whl
# Prodcution
# run: python -m twine upload dist/*.whl
# Test
run: python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*.whl

- name: Upload artifact (wheel)
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "initvenv"
version = "0.1.0a7"
version = "0.1.0a10"
description = "Test InitVenv package. Currently available as a standalone executable at https://github.com/Dev2Forge/Init-Venv/releases."
readme = { file = "README.md", content-type = "text/markdown", charset = "utf-8" }
license = "GPL-3.0"
Expand Down
63 changes: 41 additions & 22 deletions src/initvenv/_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,68 @@
import sys
import platform
from pathlib import Path

import subprocess

def main():
"""Launcher entry point that runs the bundled initvenv.bat (or initvenv.exe).

On Windows this will execute the shipped .bat (preferred) or the .exe.
On other platforms it prints a short message with the platform name.
If the user does not pass a path, uses "." as default.
"""
system_name = platform.system()
# If not Windows, inform the user and exit gracefully
if not system_name.lower().startswith("win"):
print(f"Próximamente funcionará en esta plataforma {system_name}")

if not platform.system().lower().startswith("win"):
print(f"Próximamente funcionará en esta plataforma {platform.system()}")
return 0

# Prevent recursive re-invocation
if os.environ.get("INITVENV_LAUNCHED") == "1":
return 0

# location of this module -> package root
pkg_root = Path(__file__).resolve().parent
# scripts directory inside the package
scripts_dir = pkg_root / "scripts"

# prefer the .bat next to the installed script
bat = scripts_dir / "initvenv.bat"
exe = scripts_dir / "initvenv.exe"

# If not found where expected, try one level up (defensive)
if not bat.exists() and not exe.exists():
pkg_root_up = pkg_root.parent
scripts_dir = pkg_root_up / "scripts"
bat = scripts_dir / "initvenv.bat"
# exe = scripts_dir / "initvenv.exe"
exe = scripts_dir / "initvenv.exe"

# If no path provided, default to current directory "."
user_args = sys.argv[1:]
if not user_args:
target = "."
else:
target = user_args[0]

env = os.environ.copy()
env["INITVENV_LAUNCHED"] = "1"

cmd = os.environ.get("COMSPEC", "cmd.exe")

if bat.exists():
# On Windows run the .bat through cmd.exe so associations work
cmd = "cmd.exe" # os.environ.get("COMSPEC", "cmd.exe")
args = [cmd, "/c", str(bat)] + sys.argv[1:]
os.execv(cmd, args)
bat_path = str(bat)
argv = [cmd, "/c", bat_path, target]
try:
subprocess.run(argv, check=True, env=env)
return 0
except subprocess.CalledProcessError as e:
print(f"Error ejecutando {bat}: {e}", file=sys.stderr)
return e.returncode

# if exe.exists():
# # Execute the exe directly, replacing the current process
# os.execv(str(exe), [str(exe)] + sys.argv[1:])
if exe.exists():
exe_path = str(exe)
argv = [exe_path, target]
try:
subprocess.run(argv, check=True, env=env)
return 0
except subprocess.CalledProcessError as e:
print(f"Error ejecutando {exe}: {e}", file=sys.stderr)
return e.returncode

print("Error: neither initvenv.bat nor initvenv.exe were found in package scripts/", file=sys.stderr)
return 2


if __name__ == '__main__':
sys.exit(main())
if __name__ == "__main__":
sys.exit(main())
12 changes: 10 additions & 2 deletions src/initvenv/scripts/initvenv.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
@echo off
start "" "initvenv.exe" "%CD%"
exit
if "%~1"=="" (
set "target=%CD%"
) else (
set "target=%~1"
)

setlocal
"%~dp0initvenv.exe" "%target%"
endlocal
exit /b %ERRORLEVEL%