Example #1
0
File: pew.py Project: alimuldal/pew
def first_run_setup():
    shell = supported_shell()
    if shell:
        if shell == 'fish':
            source_cmd = 'source (pew shell_config)'
        else:
            source_cmd = 'source $(pew shell_config)'
        rcpath = expandpath({
            'bash': '~/.bashrc',
            'zsh': '~/.zshrc',
            'fish': '~/.config/fish/config.fish'
        }[shell])
        with rcpath.open('r+') as rcfile:
            if (source_cmd + '\n') not in rcfile.readlines():
                choice = 'X'
                while choice not in ('y', '', 'n'):
                    choice = input(
                        "It seems that you're running pew for the first time\n"
                        "do you want to modify %s to source completions and"
                        " update your prompt? [y/N]\n> " % rcpath).lower()
                if choice == 'y':
                    rcfile.write('\n# added by Pew\n%s\n' % source_cmd)
                    print('Done')
                else:
                    print(
                        '\nOk, if you want to do it manually, just add\n %s\nat'
                        ' the end of %s' % (source_cmd, rcpath))
                print('\nWill now continue with the command:', *sys.argv[1:])
                input('[enter]')
Example #2
0
File: pew.py Project: jck/pew
def cp_cmd():
    """Duplicate the named virtualenv to make a new one."""
    parser = argparse.ArgumentParser()
    parser.add_argument('source')
    parser.add_argument('target', nargs='?')
    parser.add_argument('-d',
                        '--dont-activate',
                        action='store_false',
                        default=True,
                        dest='activate',
                        help="After \
                        creation, continue with the existing shell (don't \
                        activate the new environment).")

    args = parser.parse_args()
    source = expandpath(args.source)
    if not source.exists():
        source = workon_home / args.source
        if not source.exists():
            sys.exit('Please provide a valid virtualenv to copy')

    target_name = args.target or source.name

    target = workon_home / target_name

    if target.exists():
        sys.exit('%s virtualenv already exists in %s.' %
                 (target_name, workon_home))

    print('Copying {0} in {1}'.format(source, target_name))
    clone_virtualenv(str(source), str(target))
    if args.activate:
        shell(target_name)
Example #3
0
def cp_cmd():
    """Duplicate the named virtualenv to make a new one."""
    parser = argparse.ArgumentParser()
    parser.add_argument('source')
    parser.add_argument('target', nargs='?')
    parser.add_argument('-d', '--dont-activate', action='store_false',
                        default=True, dest='activate', help="After \
                        creation, continue with the existing shell (don't \
                        activate the new environment).")

    args = parser.parse_args()
    source = expandpath(args.source)
    if not source.exists():
        source = workon_home / args.source
        if not source.exists():
            sys.exit('Please provide a valid virtualenv to copy')

    target_name = args.target or source.name

    target = workon_home / target_name

    if target.exists():
        sys.exit('%s virtualenv already exists in %s.' % (target_name, workon_home))

    print('Copying {0} in {1}'.format(source, target_name))
    clone_virtualenv(str(source), str(target))
    if args.activate:
        shell(target_name)
Example #4
0
def cp_cmd():
    """Duplicate the named virtualenv to make a new one."""
    parser = argparse.ArgumentParser()
    parser.add_argument("source")
    parser.add_argument("target", nargs="?")
    parser.add_argument(
        "-d",
        "--dont-activate",
        action="store_false",
        default=True,
        dest="activate",
        help="After \
                        creation, continue with the existing shell (don't \
                        activate the new environment).",
    )

    args = parser.parse_args()
    source = expandpath(args.source)
    if not source.exists():
        source = workon_home / args.source
        if not source.exists():
            sys.exit("Please provide a valid virtualenv to copy")

    target_name = args.target or source.name

    target = workon_home / target_name

    if target.exists():
        sys.exit("%s virtualenv already exists in %s." % (target_name, workon_home))

    print("Copying {0} in {1}".format(source, target_name))
    clone_virtualenv(str(source), str(target))
    if args.activate:
        shell(target_name)
Example #5
0
File: pew.py Project: alimuldal/pew
def mkvirtualenv(envname,
                 python=None,
                 packages=[],
                 project=None,
                 requirements=None,
                 rest=[]):

    if python:
        rest = ["--python=%s" % python] + rest

    try:
        check_call(["virtualenv", envname] + rest, cwd=str(workon_home))

        if project:
            setvirtualenvproject(envname, project.absolute())

        if requirements:
            inve(envname, 'pip', 'install', '--allow-all-external', '-r',
                 str(expandpath(requirements)))

        if packages:
            inve(envname, 'pip', 'install', '--allow-all-external', *packages)

    except (CalledProcessError, KeyboardInterrupt):
        rmvirtualenvs([envname])
        raise
Example #6
0
def mkvirtualenv(envname,
                 python=None,
                 packages=[],
                 project=None,
                 requirements=None,
                 rest=[]):

    if python:
        rest = ["--python=%s" % python] + rest

    path = (workon_home / envname).absolute()

    try:
        check_call([sys.executable, "-m", "virtualenv", str(path)] + rest)
    except (CalledProcessError, KeyboardInterrupt):
        rmvirtualenvs([envname])
        raise
    else:
        if project:
            setvirtualenvproject(envname, project.absolute())
        if requirements:
            inve(envname, 'pip', 'install', '-r',
                 str(expandpath(requirements)))
        if packages:
            inve(envname, 'pip', 'install', *packages)
Example #7
0
File: pew.py Project: aranega/pew
def first_run_setup():
    shell = supported_shell()
    if shell:
        if shell == 'fish':
            source_cmd = 'source (pew shell_config)'
        else:
            source_cmd = 'source $(pew shell_config)'
        rcpath = expandpath({'bash': '~/.bashrc'
                           , 'zsh': '~/.zshrc'
                           , 'fish': '~/.config/fish/config.fish'}[shell])
        with rcpath.open('r+') as rcfile:
            if (source_cmd + '\n') not in rcfile.readlines():
                choice = 'X'
                while choice not in ('y', '', 'n'):
                    choice = input("It seems that you're running pew for the first time\n"
                                   "do you want to modify %s to source completions and"
                                   " update your prompt? [y/N]\n> " % rcpath).lower()
                if choice == 'y':
                    rcfile.write('\n# added by Pew\n%s\n' % source_cmd)
                    print('Done')
                else:
                    print('\nOk, if you want to do it manually, just add\n %s\nat'
                          ' the end of %s' % (source_cmd, rcpath))
                print('\nWill now continue with the command:', *sys.argv[1:])
                input('[enter]')
Example #8
0
def fork_cmder(env, cwd):
    shell_cmd = ['cmd']
    cmderrc_path = r'%CMDER_ROOT%\vendor\init.bat'
    if expandpath(cmderrc_path).exists():
        shell_cmd += ['/k', cmderrc_path]
    if cwd:
        os.environ['CMDER_START'] = cwd
    fork_shell(env, shell_cmd, cwd)
Example #9
0
def fork_bash(env, cwd):
    # bash is a special little snowflake, and prevent_path_errors cannot work there
    # https://github.com/berdario/pew/issues/58#issuecomment-102182346
    with NamedTemporaryFile('w+') as rcfile:
        with expandpath('~/.bashrc').open() as bashrc:
            rcfile.write(bashrc.read())
        rcfile.write('\nexport PATH=' + compute_path(env))
        fork_shell(env, ['bash', '--rcfile', rcfile.name], cwd)
Example #10
0
File: pew.py Project: berdario/pew
def fork_cmder(env, cwd):
    shell_cmd = ["cmd"]
    cmderrc_path = r"%CMDER_ROOT%\vendor\init.bat"
    if expandpath(cmderrc_path).exists():
        shell_cmd += ["/k", cmderrc_path]
    if cwd:
        os.environ["CMDER_START"] = cwd
    fork_shell(env, shell_cmd, cwd)
Example #11
0
File: pew.py Project: Lucas-C/pew
def fork_cmder(env, cwd):
    shell_cmd = ['cmd']
    cmderrc_path = r'%CMDER_ROOT%\vendor\init.bat'
    if expandpath(cmderrc_path).exists():
        shell_cmd += ['/k', cmderrc_path]
    if cwd:
        os.environ['CMDER_START'] = cwd
    fork_shell(env, shell_cmd, cwd)
Example #12
0
def fork_cmder(env, cwd):
    shell_cmd = ['cmd']
    escaped_cmder_root = os.environ['CMDER_ROOT'].replace(' ', '^ ')
    cmderrc_path = r'{0}\vendor\init.bat'.format(escaped_cmder_root)
    if expandpath(cmderrc_path).exists():
        shell_cmd += ['/k', cmderrc_path]
    if cwd:
        os.environ['CMDER_START'] = cwd
    fork_shell(env, shell_cmd, cwd)
Example #13
0
File: pew.py Project: aranega/pew
def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
             link.symlink_to(str(workon_home))
        return True
    else:
        return False
Example #14
0
File: pew.py Project: alimuldal/pew
def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
            link.symlink_to(str(workon_home))
        return True
    else:
        return False
Example #15
0
File: pew.py Project: hoganld/pew
def new_cmd(argv):
    """Create a new environment, in $WORKON_HOME."""
    parser = mkvirtualenv_argparser()
    parser.add_argument('-a', dest='project', help='Provide a full path to a \
project directory to associate with the new environment.')

    parser.add_argument('envname')
    args, rest = parser.parse_known_args(argv)
    project = expandpath(args.project) if args.project else None
    mkvirtualenv(args.envname, args.python, args.packages, project,
                 args.requirements, args.type, rest)
    if args.activate:
        shell(args.envname)
Example #16
0
File: pew.py Project: alimuldal/pew
def fork_bash(env, cwd):
    # bash is a special little snowflake, and prevent_path_errors cannot work there
    # https://github.com/berdario/pew/issues/58#issuecomment-102182346
    bashrcpath = expandpath('~/.bashrc')
    if bashrcpath.exists():
        with NamedTemporaryFile('w+') as rcfile:
            with bashrcpath.open() as bashrc:
                rcfile.write(bashrc.read())
            rcfile.write('\nexport PATH=' + compute_path(env))
            rcfile.flush()
            fork_shell(env, ['bash', '--rcfile', rcfile.name], cwd)
    else:
        fork_shell(env, ['bash'], cwd)
Example #17
0
File: pew.py Project: jck/pew
def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
            try:
                workon_home.symlink_to(str(link))
            except OSError as e:
                # FIXME on TravisCI, even if I check with `link.exists()`, this
                # exception can be raised and needs to be catched, maybe it's a race condition?
                if e.errno != 17:
                    raise
Example #18
0
def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
            try:
                workon_home.symlink_to(str(link))
            except OSError as e:
                # FIXME on TravisCI, even if I check with `link.exists()`, this
                # exception can be raised and needs to be catched, maybe it's a race condition?
                if e.errno != 17:
                    raise
Example #19
0
File: pew.py Project: berdario/pew
def fork_bash(env, cwd):
    # bash is a special little snowflake, and prevent_path_errors cannot work there
    # https://github.com/berdario/pew/issues/58#issuecomment-102182346
    bashrcpath = expandpath("~/.bashrc")
    if bashrcpath.exists():
        with NamedTemporaryFile("w+") as rcfile:
            with bashrcpath.open() as bashrc:
                rcfile.write(bashrc.read())
            rcfile.write('\nexport PATH="' + to_unicode(compute_path(env)) + '"')
            rcfile.flush()
            fork_shell(env, ["bash", "--rcfile", rcfile.name], cwd)
    else:
        fork_shell(env, ["bash"], cwd)
Example #20
0
File: pew.py Project: berdario/pew
def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath("~/.virtualenvs")
        if (
            os.name == "posix"
            and "WORKON_HOME" not in os.environ
            and "XDG_DATA_HOME" not in os.environ
            and not link.exists()
        ):
            link.symlink_to(str(workon_home))
        return True
    else:
        return False
Example #21
0
def new_cmd(argv):
    """Create a new environment, in $WORKON_HOME."""
    parser = mkvirtualenv_argparser()
    parser.add_argument('-a', dest='project', help='Provide a full path to a \
project directory to associate with the new environment.')

    parser.add_argument('envname')
    args, rest = parser.parse_known_args(argv)
    project = expandpath(args.project) if args.project else None

    mkvirtualenv(args.envname, args.python, args.packages, project,
                 args.requirements, rest)
    if args.activate:
        shell(args.envname)
Example #22
0
File: pew.py Project: berdario/pew
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]):

    if python:
        rest = ["--python=%s" % python] + rest

    try:
        check_call(["virtualenv", envname] + rest, cwd=str(workon_home))
    except (CalledProcessError, KeyboardInterrupt):
        rmvirtualenvs([envname])
        raise
    else:
        if project:
            setvirtualenvproject(envname, project.absolute())
        if requirements:
            inve(envname, "pip", "install", "-r", str(expandpath(requirements)))
        if packages:
            inve(envname, "pip", "install", *packages)
Example #23
0
def new_cmd():
    """Create a new environment, in $WORKON_HOME."""
    parser = mkvirtualenv_argparser()
    parser.add_argument(
        "-a",
        dest="project",
        help="Provide a full path to a \
project directory to associate with the new environment.",
    )

    parser.add_argument("envname")
    args, rest = parser.parse_known_args()
    project = expandpath(args.project) if args.project else None

    mkvirtualenv(args.envname, args.python, args.packages, project, args.requirements, rest)
    if args.activate:
        shell(args.envname)
Example #24
0
File: pew.py Project: berdario/pew
def copy_virtualenv_project(source, target):
    source = expandpath(source)
    if not source.exists():
        source = workon_home / source
        if not source.exists():
            sys.exit("Please provide a valid virtualenv to copy")

    target_name = target or source.name

    target = workon_home / target_name

    if target.exists():
        sys.exit("%s virtualenv already exists in %s." % (target_name, workon_home))

    print("Copying {0} in {1}".format(source, target_name))
    clone_virtualenv(str(source), str(target))
    return target_name
Example #25
0
File: pew.py Project: berdario/pew
def first_run_setup():
    shell = supported_shell()
    if shell:
        if shell == "fish":
            source_cmd = "source (pew shell_config)"
        else:
            source_cmd = "source $(pew shell_config)"
        rcpath = expandpath({"bash": "~/.bashrc", "zsh": "~/.zshrc", "fish": "~/.config/fish/config.fish"}[shell])
        if rcpath.exists():
            update_config_file(rcpath, source_cmd)
        else:
            print(
                "It seems that you're running pew for the first time\n"
                "If you want source shell competions and update your prompt, "
                "Add the following line to your shell config file:\n %s" % source_cmd
            )
        print("\nWill now continue with the command:", *sys.argv[1:])
        input("[enter]")
Example #26
0
def first_run_setup():
    shell = supported_shell()
    if shell:
        if shell == 'fish':
            source_cmd = 'source (pew shell_config)'
        else:
            source_cmd = 'source $(pew shell_config)'
        rcpath = expandpath({'bash': '~/.bashrc'
                           , 'zsh': '~/.zshrc'
                           , 'fish': '~/.config/fish/config.fish'}[shell])
        if rcpath.exists():
            update_config_file(rcpath, source_cmd)
        else:
            print("It seems that you're running pew for the first time\n"
                  "If you want source shell competions and update your prompt, "
                  "Add the following line to your shell config file:\n %s" % source_cmd)
        print('\nWill now continue with the command:', *sys.argv[1:])
        input('[enter]')
Example #27
0
File: pew.py Project: alimuldal/pew
def copy_virtualenv_project(source, target):
    source = expandpath(source)
    if not source.exists():
        source = workon_home / source
        if not source.exists():
            sys.exit('Please provide a valid virtualenv to copy')

    target_name = target or source.name

    target = workon_home / target_name

    if target.exists():
        sys.exit('%s virtualenv already exists in %s.' %
                 (target_name, workon_home))

    print('Copying {0} in {1}'.format(source, target_name))
    clone_virtualenv(str(source), str(target))
    return target_name
Example #28
0
File: pew.py Project: berdario/pew
def first_run_setup():
    shell = supported_shell()
    if shell:
        if shell == 'fish':
            source_cmd = 'source (pew shell_config)'
        else:
            source_cmd = 'source "$(pew shell_config)"'
        rcpath = expandpath({'bash': '~/.bashrc'
                           , 'zsh': '~/.zshrc'
                           , 'fish': '~/.config/fish/config.fish'}[shell])
        if rcpath.exists():
            update_config_file(rcpath, source_cmd)
        else:
            print("It seems that you're running pew for the first time\n"
                  "If you want source shell competions and update your prompt, "
                  "Add the following line to your shell config file:\n %s" % source_cmd)
        print('\nWill now continue with the command:', *sys.argv[1:])
        input('[enter]')
Example #29
0
File: pew.py Project: berdario/pew
def mkvirtualenv(envname, python=None, packages=[], project=None,
                 requirements=None, rest=[]):

    if python:
        rest = ["--python=%s" % python] + rest

    path = (workon_home / envname).absolute()

    try:
        check_call([sys.executable, "-m", "virtualenv", str(path)] + rest)
    except (CalledProcessError, KeyboardInterrupt):
        rmvirtualenvs([envname])
        raise
    else:
        if project:
            setvirtualenvproject(envname, project.absolute())
        if requirements:
            inve(envname, 'pip', 'install', '-r', str(expandpath(requirements)))
        if packages:
            inve(envname, 'pip', 'install', *packages)
Example #30
0
File: pew.py Project: hoganld/pew
def mkvirtualenv(envname, python=None, packages=[], project=None,
                 requirements=None, pytype='cpython', rest=[]):

    if python:
        version_path = locate_python_by_version(python, pytype)
        if version_path:
            python = version_path
        rest = ["--python=%s" % python] + rest

    try:
        check_call(["virtualenv", envname] + rest, cwd=str(workon_home))
    except (CalledProcessError, KeyboardInterrupt):
        rmvirtualenvs([envname])
        raise
    else:
        if project:
            setvirtualenvproject(envname, project.absolute())
        if requirements:
            inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements)))
        if packages:
            inve(envname, 'pip', 'install', '--allow-all-external', *packages)
Example #31
0
def mkvirtualenv(envname, python=None, packages=[], project=None,
                 requirements=None, rest=[]):

    if python:
        rest = ["--python=%s" % python] + rest

    try:
        check_call(["virtualenv", envname] + rest, cwd=str(workon_home))

        if project:
            setvirtualenvproject(envname, project.absolute())

        if requirements:
            inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements)))

        if packages:
            inve(envname, 'pip', 'install', '--allow-all-external', *packages)

    except CalledProcessError:
        rmvirtualenvs([envname])
        raise
Example #32
0
def get_workon_home():
    return expandpath(os.environ.get('WORKON_HOME', default_home))
Example #33
0
File: pew.py Project: aranega/pew
    InstallCommand = ListPythons = LocatePython = \
        lambda : sys.exit('Command not supported on this platform')

from pew import __version__
from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir,
                        check_path, temp_environ, NamedTemporaryFile, to_unicode)
from pew._print_utils import print_virtualenvs

if sys.version_info[0] == 2:
    input = raw_input

err = partial(print, file=sys.stderr)

workon_home = expandpath(
    os.environ.get('WORKON_HOME',
                   os.path.join(os.environ.get('XDG_DATA_HOME',
                                               '~/.local/share'),
                                'virtualenvs')))


def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
             link.symlink_to(str(workon_home))
        return True
    else:
        return False
Example #34
0
from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir,
                        check_path, temp_environ, NamedTemporaryFile, to_unicode)
from pew._print_utils import print_virtualenvs

if sys.version_info[0] == 2:
    input = raw_input

err = partial(print, file=sys.stderr)

if windows:
    default_home = '~/.virtualenvs'
else:
    default_home = os.path.join(
        os.environ.get('XDG_DATA_HOME', '~/.local/share'), 'virtualenvs')
workon_home = expandpath(
    os.environ.get('WORKON_HOME', default_home))


def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
             link.symlink_to(str(workon_home))
        return True
    else:
        return False

pew_site = Path(__file__).parent
Example #35
0
File: pew.py Project: alimuldal/pew
else:
    # Pythonz does not support windows
    InstallCommand = ListPythons = LocatePython = \
        lambda : sys.exit('Command not supported on this platform')

from pew import __version__
from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir,
                        check_path, temp_environ)
from pew._print_utils import print_virtualenvs

if sys.version_info[0] == 2:
    input = raw_input

workon_home = expandpath(
    os.environ.get(
        'WORKON_HOME',
        os.path.join(os.environ.get('XDG_DATA_HOME', '~/.local/share'),
                     'virtualenvs')))


def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath('~/.virtualenvs')
        if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \
           'XDG_DATA_HOME' not in os.environ and not link.exists():
            link.symlink_to(str(workon_home))
        return True
    else:
        return False
Example #36
0
File: pew.py Project: berdario/pew
    temp_environ,
    NamedTemporaryFile,
    to_unicode,
)
from pew._print_utils import print_virtualenvs

if sys.version_info[0] == 2:
    input = raw_input

err = partial(print, file=sys.stderr)

if windows:
    default_home = "~/.virtualenvs"
else:
    default_home = os.path.join(os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs")
workon_home = expandpath(os.environ.get("WORKON_HOME", default_home))


def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath("~/.virtualenvs")
        if (
            os.name == "posix"
            and "WORKON_HOME" not in os.environ
            and "XDG_DATA_HOME" not in os.environ
            and not link.exists()
        ):
            link.symlink_to(str(workon_home))
        return True
    else:
Example #37
0
from pew import __version__
from pew._utils import check_call, invoke, expandpath, own, env_bin_dir, check_path, temp_environ
from pew._print_utils import print_virtualenvs

windows = sys.platform == "win32"


def update_args_dict():
    global args
    args = dict(enumerate(sys.argv))


update_args_dict()

workon_home = expandpath(
    os.environ.get("WORKON_HOME", os.path.join(os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs"))
)


def makedirs_and_symlink_if_needed(workon_home):
    if not workon_home.exists() and own(workon_home):
        workon_home.mkdir(parents=True)
        link = expandpath("~/.virtualenvs")
        if (
            os.name == "posix"
            and "WORKON_HOME" not in os.environ
            and "XDG_DATA_HOME" not in os.environ
            and not link.exists()
        ):
            try:
                workon_home.symlink_to(str(link))