MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / configure

Function configure

tensorflow/tools/git/gen_git_source.py:65–139  ·  view source on GitHub ↗

Configure `src_base_path` to embed git hashes if available.

(src_base_path, gen_path, debug=False)

Source from the content-addressed store, hash-verified

63
64
65def configure(src_base_path, gen_path, debug=False):
66 """Configure `src_base_path` to embed git hashes if available."""
67
68 # TODO(aselle): No files generated or symlinked here are deleted by
69 # the build system. I don't know of a way to do it in bazel. It
70 # should only be a problem if somebody moves a sandbox directory
71 # without running ./configure again.
72
73 git_path = os.path.join(src_base_path, ".git")
74
75 # Remove and recreate the path
76 if os.path.exists(gen_path):
77 if os.path.isdir(gen_path):
78 try:
79 shutil.rmtree(gen_path)
80 except OSError:
81 raise RuntimeError("Cannot delete directory %s due to permission "
82 "error, inspect and remove manually" % gen_path)
83 else:
84 raise RuntimeError("Cannot delete non-directory %s, inspect ",
85 "and remove manually" % gen_path)
86 os.makedirs(gen_path)
87
88 if not os.path.isdir(gen_path):
89 raise RuntimeError("gen_git_source.py: Failed to create dir")
90
91 # file that specifies what the state of the git repo is
92 spec = {}
93
94 # value file names will be mapped to the keys
95 link_map = {"head": None, "branch_ref": None}
96
97 if not os.path.isdir(git_path):
98 # No git directory
99 spec["git"] = False
100 open(os.path.join(gen_path, "head"), "w").write("")
101 open(os.path.join(gen_path, "branch_ref"), "w").write("")
102 else:
103 # Git directory, possibly detached or attached
104 spec["git"] = True
105 spec["path"] = src_base_path
106 git_head_path = os.path.join(git_path, "HEAD")
107 spec["branch"] = parse_branch_ref(git_head_path)
108 link_map["head"] = git_head_path
109 if spec["branch"] is not None:
110 # attached method
111 link_map["branch_ref"] = os.path.join(git_path, *
112 os.path.split(spec["branch"]))
113 # Create symlinks or dummy files
114 for target, src in link_map.items():
115 if src is None:
116 open(os.path.join(gen_path, target), "w").write("")
117 elif not os.path.exists(src):
118 # Git repo is configured in a way we don't support such as having
119 # packed refs. Even though in a git repo, tf.__git_version__ will not
120 # be accurate.
121 # TODO(mikecase): Support grabbing git info when using packed refs.
122 open(os.path.join(gen_path, target), "w").write("")

Callers 1

gen_git_source.pyFile · 0.70

Calls 5

parse_branch_refFunction · 0.85
joinMethod · 0.45
writeMethod · 0.45
splitMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected