Skip to content

Commit

Permalink
Allow installation directly into environments
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Apr 3, 2015
1 parent 1f4c9e4 commit f5b35ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bootstrap_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from pathlib import Path
from flit.install import Installer
from flit.log import enable_colourful_output

enable_colourful_output()
p = Path('flit.ini')
Installer(p, symlink=True).install()
8 changes: 7 additions & 1 deletion flit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def main(argv=None):
parser_install.add_argument('--symlink', action='store_true',
help="Symlink the module/package into site packages instead of copying it"
)
parser_install.add_argument('--user', action='store_true', default=None,
help="Do a user-local install (default if site.ENABLE_USER_SITE is True)"
)
parser_install.add_argument('--env', action='store_false', dest='user',
help="Install into sys.prefix (default if site.ENABLE_USER_SITE is False, i.e. in virtualenvs)"
)

args = ap.parse_args(argv)

Expand All @@ -43,7 +49,7 @@ def main(argv=None):
verify_metadata=args.verify_metadata).build()
elif args.subcmd == 'install':
from .install import Installer
Installer(args.ini_file, symlink=args.symlink).install()
Installer(args.ini_file, user=args.user, symlink=args.symlink).install()
else:
sys.exit('No command specified')

Expand Down
16 changes: 14 additions & 2 deletions flit/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,27 @@ def get_dirs(user=True):
'purelib': purelib.format_map(_interpolation_vars),
}

class RootInstallError(Exception):
def __str__(self):
return ("Installing packages as root is not recommended. "
"To allow this, set FLIT_ROOT_INSTALL=1 and try again.")

class Installer(object):
def __init__(self, ini_path, user=True, symlink=False):
def __init__(self, ini_path, user=None, symlink=False):
self.ini_path = ini_path
self.ini_info = inifile.read_pkg_ini(ini_path)
self.module = common.Module(self.ini_info['module'],
ini_path.parent)
self.metadata = common.make_metadata(self.module, self.ini_info)

self.user = user
print(user, site.ENABLE_USER_SITE)
if user is None:
self.user = site.ENABLE_USER_SITE
else:
self.user = user
if (os.getuid() == 0) and (not os.environ.get('FLIT_ROOT_INSTALL')):
raise RootInstallError

self.symlink = symlink
self.installed_files = []

Expand Down

0 comments on commit f5b35ac

Please sign in to comment.