Skip to content

Commit

Permalink
Manage the case of running from source inside a virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
stefano-maggiolo committed Mar 12, 2017
1 parent 37f859c commit af988d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 10 additions & 6 deletions cms/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ def __init__(self):
self.pdf_printing_allowed = False

# Installed or from source?
self.installed = (sys.argv[0].startswith("/usr/") and
sys.argv[0] != '/usr/bin/ipython' and
sys.argv[0] != '/usr/bin/python2' and
sys.argv[0] != '/usr/bin/python')
# Test for virtualenv (see http://stackoverflow.com/a/1883251/747654)
self.installed |= hasattr(sys, 'real_prefix')
# We declare we are running from installed if the program was
# NOT invoked through some python flavor, and the file is in
# the prefix (or real_prefix to accommodate virtualenvs).
bin_path = os.path.join(os.getcwd(), sys.argv[0])
bin_name = os.path.basename(bin_path)
bin_is_python = bin_name in ["ipython", "python", "python2", "python3"]
bin_in_installed_path = bin_path.startswith(sys.prefix) or (
hasattr(sys, 'real_prefix')
and bin_path.startswith(sys.real_prefix))
self.installed = bin_in_installed_path and not bin_is_python

if self.installed:
self.log_dir = os.path.join("/", "var", "local", "log", "cms")
Expand Down
14 changes: 8 additions & 6 deletions cmsranking/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ def __init__(self):
self.buffer_size = 100 # Needs to be strictly positive.

# File system.
self.installed = (sys.argv[0].startswith("/usr/") and
sys.argv[0] != '/usr/bin/ipython' and
sys.argv[0] != '/usr/bin/python2' and
sys.argv[0] != '/usr/bin/python')
# Test for virtualenv (see http://stackoverflow.com/a/1883251/747654)
self.installed |= hasattr(sys, 'real_prefix')
# TODO: move to cmscommon as it is used both here and in cms/conf.py
bin_path = os.path.join(os.getcwd(), sys.argv[0])
bin_name = os.path.basename(bin_path)
bin_is_python = bin_name in ["ipython", "python", "python2", "python3"]
bin_in_installed_path = bin_path.startswith(sys.prefix) or (
hasattr(sys, 'real_prefix')
and bin_path.startswith(sys.real_prefix))
self.installed = bin_in_installed_path and not bin_is_python

self.web_dir = pkg_resources.resource_filename("cmsranking", "static")
if self.installed:
Expand Down

0 comments on commit af988d7

Please sign in to comment.