90 with TemporaryDirectory(prefix="temp-cwctl-newcube-install") as tmpdir: |
90 with TemporaryDirectory(prefix="temp-cwctl-newcube-install") as tmpdir: |
91 newcube(tmpdir, 'foo') |
91 newcube(tmpdir, 'foo') |
92 projectdir = osp.join(tmpdir, 'cubicweb-foo') |
92 projectdir = osp.join(tmpdir, 'cubicweb-foo') |
93 env = os.environ.copy() |
93 env = os.environ.copy() |
94 env['HOME'] = tmpdir |
94 env['HOME'] = tmpdir |
|
95 # Retrieve user-site first to later set the PYTHONPATH. |
|
96 proc = Popen([sys.executable, '-m', 'site', '--user-site'], |
|
97 stdout=PIPE, stderr=PIPE, env=env, cwd=tmpdir) |
|
98 retcode = proc.wait() |
|
99 # Exit codes below 2 are not errors and are ok for us (see |
|
100 # 'python3 -m site --help' for details). |
|
101 self.assertFalse(retcode > 2, to_unicode(proc.stderr.read())) |
|
102 user_site = proc.stdout.read().strip() |
|
103 # We need this otherwise setuptools will complain that the |
|
104 # installation target is not in PYTHONPATH (probably because we |
|
105 # use a fake HOME). |
|
106 env['PYTHONPATH'] = user_site |
95 cmd = [sys.executable, 'setup.py', 'install', '--user'] |
107 cmd = [sys.executable, 'setup.py', 'install', '--user'] |
96 proc = Popen(cmd, stdout=PIPE, stderr=STDOUT, |
108 proc = Popen(cmd, stdout=PIPE, stderr=STDOUT, |
97 cwd=projectdir, env=env) |
109 cwd=projectdir, env=env) |
98 retcode = proc.wait() |
110 retcode = proc.wait() |
99 stdout = to_unicode(proc.stdout.read()) |
111 stdout = to_unicode(proc.stdout.read()) |
100 self.assertEqual(retcode, 0, stdout) |
112 self.assertEqual(retcode, 0, stdout) |
101 targetdir = check_output([sys.executable, '-m', 'site', '--user-site'], |
|
102 env=env, cwd=projectdir).strip() |
|
103 target_egg = 'cubicweb_foo-0.1.0-py{0}.egg'.format(sys.version[:3]).encode() |
113 target_egg = 'cubicweb_foo-0.1.0-py{0}.egg'.format(sys.version[:3]).encode() |
104 self.assertTrue(osp.isdir(osp.join(targetdir, target_egg)), |
114 self.assertTrue(osp.isdir(osp.join(user_site, target_egg)), |
105 'target directory content: %s' % os.listdir(targetdir)) |
115 'target directory content: %s' % os.listdir(user_site)) |
106 pkgdir = osp.join(targetdir, target_egg, b'cubicweb_foo') |
116 pkgdir = osp.join(user_site, target_egg, b'cubicweb_foo') |
107 self.assertTrue(osp.isdir(pkgdir), |
117 self.assertTrue(osp.isdir(pkgdir), |
108 os.listdir(osp.join(targetdir, target_egg))) |
118 os.listdir(osp.join(user_site, target_egg))) |
109 pkgcontent = [f for f in os.listdir(pkgdir) if f.endswith(b'.py')] |
119 pkgcontent = [f for f in os.listdir(pkgdir) if f.endswith(b'.py')] |
110 self.assertItemsEqual(pkgcontent, |
120 self.assertItemsEqual(pkgcontent, |
111 [b'schema.py', b'entities.py', b'hooks.py', b'__init__.py', |
121 [b'schema.py', b'entities.py', b'hooks.py', b'__init__.py', |
112 b'__pkginfo__.py', b'views.py']) |
122 b'__pkginfo__.py', b'views.py']) |
113 |
123 |