forked from DonJayamanne/pythonVSCode
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
Latest commit
196 lines (164 loc) · 6.09 KB
/
Copy pathnoxfile.py
File metadata and controls
196 lines (164 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
importos
importpathlib
importnox
importshutil
importsys
importsysconfig
importuuid
EXT_ROOT=pathlib.Path(__file__).parent
@nox.session()
definstall_python_libs(session: nox.Session):
requirements= [
("./python_files/lib/python", "./requirements.txt"),
(
"./python_files/lib/jedilsp",
"./python_files/jedilsp_requirements/requirements.txt",
),
]
fortarget, fileinrequirements:
session.install(
"-t",
target,
"--no-cache-dir",
"--implementation",
"py",
"--no-deps",
"--require-hashes",
"--only-binary",
":all:",
"-r",
file,
)
session.install("packaging")
# Download get-pip script
session.run(
"python",
"./python_files/download_get_pip.py",
env={"PYTHONPATH": "./python_files/lib/temp"},
)
ifpathlib.Path("./python_files/lib/temp").exists():
shutil.rmtree("./python_files/lib/temp")
@nox.session()
defazure_pet_build_before(session: nox.Session):
source_dir=pathlib.Path(pathlib.Path.cwd() /"python-env-tools").resolve()
config_toml_disabled=source_dir/".cargo"/"config.toml.disabled"
config_toml=source_dir/".cargo"/"config.toml"
ifconfig_toml_disabled.exists() andnotconfig_toml.exists():
config_toml.write_bytes(config_toml_disabled.read_bytes())
@nox.session()
defazure_pet_build_after(session: nox.Session):
source_dir=pathlib.Path(pathlib.Path.cwd() /"python-env-tools").resolve()
ext=sysconfig.get_config_var("EXE") or""
bin_name=f"pet{ext}"
abs_bin_path=None
forroot, _, filesinos.walk(os.fspath(source_dir/"target")):
bin_path=pathlib.Path(root) /"release"/bin_name
ifbin_path.exists():
abs_bin_path=bin_path.absolute()
break
assertabs_bin_path
dest_dir=pathlib.Path(pathlib.Path.cwd() /"python-env-tools").resolve()
ifnotpathlib.Path(dest_dir/"bin").exists():
pathlib.Path(dest_dir/"bin").mkdir()
bin_dest=dest_dir/"bin"/bin_name
shutil.copyfile(abs_bin_path, bin_dest)
ifsys.platform!="win32":
os.chmod(os.fspath(bin_dest), 0o755)
@nox.session()
defnative_build(session: nox.Session):
source_dir=pathlib.Path(pathlib.Path.cwd() /"python-env-tools").resolve()
dest_dir=pathlib.Path(pathlib.Path.cwd() /"python-env-tools").resolve()
withsession.cd(source_dir):
ifnotpathlib.Path(dest_dir/"bin").exists():
pathlib.Path(dest_dir/"bin").mkdir()
ifnotpathlib.Path(dest_dir/"bin"/".gitignore").exists():
pathlib.Path(dest_dir/"bin"/".gitignore").write_text(
"*\n", encoding="utf-8"
)
ext=sysconfig.get_config_var("EXE") or""
target=os.environ.get("CARGO_TARGET", None)
session.run("cargo", "fetch", external=True)
iftarget:
session.run(
"cargo",
"build",
"--frozen",
"--release",
"--target",
target,
external=True,
)
source=source_dir/"target"/target/"release"/f"pet{ext}"
else:
session.run(
"cargo",
"build",
"--frozen",
"--release",
external=True,
)
source=source_dir/"target"/"release"/f"pet{ext}"
dest=dest_dir/"bin"/f"pet{ext}"
shutil.copy(source, dest)
# Remove python-env-tools/bin exclusion from .vscodeignore
vscode_ignore=EXT_ROOT/".vscodeignore"
remove_patterns= ("python-env-tools/bin/**",)
lines=vscode_ignore.read_text(encoding="utf-8").splitlines()
filtered_lines= [lineforlineinlinesifnotline.startswith(remove_patterns)]
vscode_ignore.write_text("\n".join(filtered_lines) +"\n", encoding="utf-8")
defdelete_dir(path: pathlib.Path, ignore_errors=None):
attempt=0
known= []
whileattempt<5:
try:
shutil.rmtree(os.fspath(path), ignore_errors=ignore_errors)
return
exceptPermissionErroraspe:
ifos.fspath(pe.filename) inknown:
break
print(f"Changing permissions on {pe.filename}")
os.chmod(pe.filename, 0o666)
shutil.rmtree(os.fspath(path))
@nox.session()
defcheckout_native(session: nox.Session):
dest= (pathlib.Path.cwd() /"python-env-tools").resolve()
ifdest.exists():
shutil.rmtree(os.fspath(dest))
tempdir=os.getenv("TEMP") oros.getenv("TMP") or"/tmp"
tempdir=pathlib.Path(tempdir) /str(uuid.uuid4()) /"python-env-tools"
tempdir.mkdir(0o666, parents=True)
session.log(f"Temp dir: {tempdir}")
session.log(f"Cloning python-environment-tools to {tempdir}")
try:
withsession.cd(tempdir):
session.run("git", "init", external=True)
session.run(
"git",
"remote",
"add",
"origin",
"https://github.com/microsoft/python-environment-tools",
external=True,
)
session.run("git", "fetch", "origin", "main", external=True)
session.run(
"git", "checkout", "--force", "-B", "main", "origin/main", external=True
)
delete_dir(tempdir/".git")
delete_dir(tempdir/".github")
delete_dir(tempdir/".vscode")
(tempdir/"CODE_OF_CONDUCT.md").unlink()
shutil.move(os.fspath(tempdir), os.fspath(dest))
exceptPermissionErrorase:
print(f"Permission error: {e}")
ifnotdest.exists():
raise
finally:
delete_dir(tempdir.parent, ignore_errors=True)
@nox.session()
defsetup_repo(session: nox.Session):
install_python_libs(session)
checkout_native(session)
native_build(session)