Skip to content

Commit 8600553

Browse files
committed
Debug build
1 parent 0a94b6b commit 8600553

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tools/__init__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,56 @@
1+
import json
12
import logging
23
import pathlib
34
import sys
45

56
import ptscripts
7+
import ptscripts.virtualenv
68
from ptscripts.models import DefaultPipConfig, VirtualEnvPipConfig
79

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+
854
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
955
REQUIREMENTS_FILES_PATH = REPO_ROOT / "requirements"
1056
STATIC_REQUIREMENTS_PATH = REQUIREMENTS_FILES_PATH / "static"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy