main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -3,10 +3,8 @@ import os
import shlex
import sys
from contextlib import contextmanager
from typing import Any, Dict, IO, Iterator, List, Optional
if sys.platform == 'win32':
from subprocess import Popen
from subprocess import Popen
from typing import Any, Dict, IO, Iterator, List
try:
import click
@@ -19,7 +17,7 @@ from .main import dotenv_values, set_key, unset_key
from .version import __version__
def enumerate_env() -> Optional[str]:
def enumerate_env():
"""
Return a path for the ${pwd}/.env file.
@@ -163,13 +161,14 @@ def run(ctx: click.Context, override: bool, commandline: List[str]) -> None:
if not commandline:
click.echo('No command given.')
exit(1)
run_command(commandline, dotenv_as_dict)
ret = run_command(commandline, dotenv_as_dict)
exit(ret)
def run_command(command: List[str], env: Dict[str, str]) -> None:
"""Replace the current process with the specified command.
def run_command(command: List[str], env: Dict[str, str]) -> int:
"""Run command in sub process.
Replaces the current process with the specified command and the variables from `env`
Runs the command in a sub process with the variables from `env`
added in the current environment variables.
Parameters
@@ -181,8 +180,8 @@ def run_command(command: List[str], env: Dict[str, str]) -> None:
Returns
-------
None
This function does not return any value. It replaces the current process with the new one.
int
The return code of the command
"""
# copy the current environment variables and add the vales from
@@ -190,16 +189,11 @@ def run_command(command: List[str], env: Dict[str, str]) -> None:
cmd_env = os.environ.copy()
cmd_env.update(env)
if sys.platform == 'win32':
# execvpe on Windows returns control immediately
# rather than once the command has finished.
p = Popen(command,
universal_newlines=True,
bufsize=0,
shell=False,
env=cmd_env)
_, _ = p.communicate()
p = Popen(command,
universal_newlines=True,
bufsize=0,
shell=False,
env=cmd_env)
_, _ = p.communicate()
exit(p.returncode)
else:
os.execvpe(command[0], args=command, env=cmd_env)
return p.returncode