1#-----------------------------------------------------------------------------
2# Copyright (c) 2005-2019, PyInstaller Development Team.
3#
4# Distributed under the terms of the GNU General Public License with exception
5# for distributing bootloader.
6#
7# The full license is in the file COPYING.txt, distributed with this software.
8#-----------------------------------------------------------------------------
9
10
11# Test that the Pythons 'site' module is disabled and Python is not searching
12# for any user-specific site directories.
13
14# Check that option -S is passed to Python interpreter and that sys.path has
15# not been modified.
16
17
18import sys
19
20# The option -S tells Python not to import `site` on startup.
21# If site has been imported already, that's instant failure.
22if 'site' in sys.modules:
23    raise SystemExit('site module already imported')
24
25import site
26
27# Check it is really disabled.
28if not sys.flags.no_site:
29    raise SystemExit('site module is enabled!')
30
31# Default values 'site' module when it is disabled.
32# On Py2, ENABLE_USER_SITE should be False; on Py3, it should be None.
33if site.ENABLE_USER_SITE not in (None, False):
34    raise SystemExit('ENABLE_USER_SITE is %s, expected %s.' %
35                     (site.ENABLE_USER_SITE, (None, False)))
36
37# Since we import `site` here in the test, this causes USER_SITE and USER_BASE to be
38# initialized on Py2, so all we can do is confirm that the paths aren't in sys.path
39
40if site.USER_SITE is not None:
41    if site.USER_SITE in sys.path:
42        raise SystemExit('USER_SITE found in sys.path')
43
44# This should never happen, USER_BASE isn't a site-modules folder and is only used by
45# distutils for installing module datas.
46if site.USER_BASE is not None:
47    if site.USER_SITE in sys.path:
48        raise SystemExit('USER_BASE found in sys.path')
49
50
51# Check if this is realy our fake-site module
52assert site.__pyinstaller__faked__site__module__ == True
53