MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / resolve_python_relative

Function resolve_python_relative

src/pipeline/fqn.c:246–270  ·  view source on GitHub ↗

Python relative import: ".foo", "..bar.baz" → resolve against source dir. */

Source from the content-addressed store, hash-verified

244
245/* Python relative import: ".foo", "..bar.baz" → resolve against source dir. */
246static char *resolve_python_relative(char *buf, size_t buf_size, const char *module_path) {
247 const char *p = module_path;
248 int dot_count = 0;
249 while (*p == '.') {
250 dot_count++;
251 p++;
252 }
253 for (int i = FQN_MIN_PY_DOTS; i < dot_count; i++) {
254 path_pop_segment(buf);
255 }
256 while (*p) {
257 const char *seg_start = p;
258 while (*p && *p != '.') {
259 p++;
260 }
261 size_t seg_len = (size_t)(p - seg_start);
262 if (seg_len > 0 && !path_append_segment(buf, buf_size, seg_start, seg_len)) {
263 return NULL;
264 }
265 if (*p == '.') {
266 p++;
267 }
268 }
269 return strdup(buf);
270}
271
272/* Strip a trailing file extension from a segment (e.g. "helpers.ts""helpers").
273 * Returns the new segment length. */

Callers 1

Calls 2

path_pop_segmentFunction · 0.85
path_append_segmentFunction · 0.85

Tested by

no test coverage detected