You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Print a nice error message if the user is running too old of a version of python.
3
+
Why not just put this block at the top of refresh.template.py?
4
+
Python versions introduce constructs that don't parse in older versions, leading to an error before the version check is executed, since python parses files eagerly.
5
+
For examples of this issue, see https://github.com/hedronvision/bazel-compile-commands-extractor/issues/119 and https://github.com/hedronvision/bazel-compile-commands-extractor/issues/95
6
+
This seems common enough that hopefully bazel will support it someday. We've filed a request: https://github.com/bazelbuild/bazel/issues/18389
7
+
"""
8
+
9
+
importsys
10
+
ifsys.version_info< (3,6):
11
+
sys.exit("\n\033[31mFATAL ERROR:\033[0m Python 3.6 or later is required. Please update!")
12
+
13
+
# Only import -> parse once we're sure we have the required python version
Copy file name to clipboardExpand all lines: refresh.template.py
+68-36
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,20 @@
10
10
- Crucially, this output is de-Bazeled; The result is a command that could be run from the workspace root directly, with no Bazel-specific requirements, environment variables, etc.
11
11
"""
12
12
13
+
# This file requires python 3.6, which is enforced by check_python_version.template.py
14
+
# 3.6 backwards compatibility required by @zhanyong-wan in https://github.com/hedronvision/bazel-compile-commands-extractor/issues/111.
15
+
# 3.7 backwards compatibility required by @lummax in https://github.com/hedronvision/bazel-compile-commands-extractor/pull/27.
16
+
# ^ Try to contact before upgrading.
17
+
# When adding things could be cleaner if we had a higher minimum version, please add a comment with MIN_PY=3.<v>.
18
+
# Similarly, when upgrading, please search for that MIN_PY= tag.
19
+
13
20
14
21
importconcurrent.futures
15
22
importenum
16
-
importfunctools
23
+
importfunctools# MIN_PY=3.9: Replace `functools.lru_cache(maxsize=None)` with `functools.cache`.
17
24
importitertools
18
25
importjson
19
26
importlocale
20
-
importorjson# orjson is much faster than the standard library's json module (1.9 seconds vs 6.6 seconds for a ~140 MB file). See https://github.com/hedronvision/bazel-compile-commands-extractor/pull/118
21
27
importos
22
28
importpathlib
23
29
importre
@@ -28,7 +34,7 @@
28
34
importtempfile
29
35
importtime
30
36
importtypes
31
-
importtyping
37
+
importtyping# MIN_PY=3.9: Switch e.g. typing.List[str] -> List[str]
cache_last_modified=os.path.getmtime(cache_file_path) # Do before opening just as a basic hedge against concurrent write, even though we won't handle the concurrent delete case perfectly.
# Unless xcode-select has been invoked (like for a beta) we'd expect, e.g., '/Applications/Xcode.app/Contents/Developer' or '/Library/Developer/CommandLineTools'.
729
753
# Traditionally stored in DEVELOPER_DIR environment variable, but not provided by Bazel. See https://github.com/bazelbuild/bazel/issues/12852
"""De-Bazel the command into something clangd can parse.
734
758
735
759
This function has fixes specific to Apple platforms, but you should call it on all platforms. It'll determine whether the fixes should be applied or not.
# Process each action from Bazelisms -> file paths and their clang commands
1122
1148
# Threads instead of processes because most of the execution time is farmed out to subprocesses. No need to sidestep the GIL. Might change after https://github.com/clangd/clangd/issues/123 resolved
max_workers=min(32, (os.cpu_count() or1) +4) # Backport. Default in MIN_PY=3.8. See "using very large resources implicitly on many-core machines" in https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor
log_error(f">>> //external already exists, but it isn't a {'junction'ifis_windowselse'symlink'}. //external is reserved by Bazel and needed for this tool. Please rename or delete your existing //external and rerun. More details in the README if you want them.") # Don't auto delete in case the user has something important there.
0 commit comments