File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ import json
1
2
import logging
2
3
import pathlib
3
4
import sys
4
5
5
6
import ptscripts
7
+ import ptscripts .virtualenv
6
8
from ptscripts .models import DefaultPipConfig , VirtualEnvPipConfig
7
9
10
+
11
+ def _add_as_extra_site_packages (self ) -> None :
12
+ if self .config .add_as_extra_site_packages is False :
13
+ return
14
+ ret = self .run_code (
15
+ "import json,site; print(json.dumps(site.getsitepackages()))" ,
16
+ capture = True ,
17
+ check = False ,
18
+ )
19
+ if ret .returncode :
20
+ self .ctx .error (
21
+ f"1 Failed to get the virtualenv's site packages path: { ret .stdout .decode ()} { ret .stderr .decode ()} "
22
+ )
23
+ self .ctx .exit (1 )
24
+ for path in json .loads (ret .stdout .strip ().decode ()):
25
+ if path not in sys .path :
26
+ sys .path .append (path )
27
+
28
+
29
+ def _remove_extra_site_packages (self ) -> None :
30
+ if self .config .add_as_extra_site_packages is False :
31
+ return
32
+ ret = self .run_code (
33
+ "import json,site; print(json.dumps(site.getsitepackages()))" ,
34
+ capture = True ,
35
+ check = False ,
36
+ )
37
+ if ret .returncode :
38
+ self .ctx .error (
39
+ f"2 Failed to get the virtualenv's site packages path: { ret .stdout .decode ()} { ret .stderr .decode ()} "
40
+ )
41
+ self .ctx .exit (1 )
42
+ for path in json .loads (ret .stdout .strip ().decode ()):
43
+ if path in sys .path :
44
+ sys .path .remove (path )
45
+
46
+
47
+ ptscripts .virtualenv .VirtualEnv ._add_as_extra_site_packages = (
48
+ _add_as_extra_site_packages
49
+ )
50
+ ptscripts .virtualenv .VirtualEnv ._remove_extra_site_packages = (
51
+ _remove_extra_site_packages
52
+ )
53
+
8
54
REPO_ROOT = pathlib .Path (__file__ ).resolve ().parent .parent
9
55
REQUIREMENTS_FILES_PATH = REPO_ROOT / "requirements"
10
56
STATIC_REQUIREMENTS_PATH = REQUIREMENTS_FILES_PATH / "static"
You can’t perform that action at this time.
0 commit comments