Skip to content

Commit

Permalink
Fix: check if scripts folders are in env path (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Jan 24, 2022
1 parent 02e2de9 commit 4e1ba05
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions vpip/venv.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import re
import shutil
import sysconfig
import venv
from contextlib import contextmanager
from pathlib import Path
from typing import List
from typing import Iterable

from .execute import execute

Expand All @@ -25,16 +26,20 @@ class GlobalScriptFolderGetter:
'~/bin'
sysconfig.get_path('scripts')
"""
def __init__(self):
import sysconfig
self.folders = [
def __call__(self) -> Iterable[Path]:
folders = set([
Path("~/.local/bin").expanduser(),
Path("~/bin").expanduser(),
Path(sysconfig.get_path("scripts"))
]

def __call__(self) -> List[Path]:
return self.folders
])
cache = []
paths = [Path(p) for p in os.environ["PATH"].split(os.pathsep)]
for path in paths:
if path in folders:
yield path
cache.append(path)
if not cache:
raise Exception('Cannot find a valid scripts folder in env variable PATH')

get_global_script_folders = GlobalScriptFolderGetter()

Expand Down

0 comments on commit 4e1ba05

Please sign in to comment.