mirror of
https://github.com/esphome/esphome.git
synced 2025-01-30 23:02:14 +01:00
Don't activate venv in devcontainer
This commit is contained in:
parent
c2e52f4b11
commit
ae1e9eaf1c
@ -45,6 +45,6 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
name: pylint
|
name: pylint
|
||||||
entry: python script/run-in-env pylint
|
entry: python3 script/run-in-env.py pylint
|
||||||
language: system
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
|
@ -7,6 +7,13 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def find_and_activate_virtualenv():
|
def find_and_activate_virtualenv():
|
||||||
|
if (
|
||||||
|
("VIRTUAL_ENV" in os.environ)
|
||||||
|
or os.environ.get("DEVCONTAINER", False)
|
||||||
|
or os.environ.get("ESPHOME_NO_VENV", False)
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get the top-level directory of the git repository
|
# Get the top-level directory of the git repository
|
||||||
my_path = subprocess.check_output(
|
my_path = subprocess.check_output(
|
||||||
@ -17,7 +24,7 @@ def find_and_activate_virtualenv():
|
|||||||
"Error: Not a git repository or unable to determine the top-level directory.",
|
"Error: Not a git repository or unable to determine the top-level directory.",
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
return
|
||||||
|
|
||||||
# Check for virtual environments
|
# Check for virtual environments
|
||||||
for venv in ["venv", ".venv", "."]:
|
for venv in ["venv", ".venv", "."]:
|
||||||
@ -29,25 +36,26 @@ def find_and_activate_virtualenv():
|
|||||||
)
|
)
|
||||||
if activate_path.exists():
|
if activate_path.exists():
|
||||||
# Activate the virtual environment by updating PATH
|
# Activate the virtual environment by updating PATH
|
||||||
env = os.environ.copy()
|
|
||||||
venv_bin_dir = activate_path.parent
|
venv_bin_dir = activate_path.parent
|
||||||
env["PATH"] = f"{venv_bin_dir}{os.pathsep}{env['PATH']}"
|
os.environ["PATH"] = f"{venv_bin_dir}{os.pathsep}{os.environ['PATH']}"
|
||||||
env["VIRTUAL_ENV"] = str(venv_bin_dir.parent)
|
os.environ["VIRTUAL_ENV"] = str(venv_bin_dir.parent)
|
||||||
print(f"Activated virtual environment: {venv_bin_dir.parent}")
|
print(f"Activated virtual environment: {venv_bin_dir.parent}")
|
||||||
|
return
|
||||||
|
|
||||||
|
print("No virtual environment found.", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def run_command():
|
||||||
# Execute the remaining arguments in the new environment
|
# Execute the remaining arguments in the new environment
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
subprocess.run(sys.argv[1:], env=env, check=False)
|
subprocess.run(sys.argv[1:], check=False)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
"No command provided to run in the virtual environment.",
|
"No command provided to run in the virtual environment.",
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
print("No virtual environment found.", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
find_and_activate_virtualenv()
|
find_and_activate_virtualenv()
|
||||||
|
run_command()
|
Loading…
Reference in New Issue
Block a user