MCPcopy Create free account
hub / github.com/catboost/catboost / get_code

Method get_code

library/python/runtime_py3/__res.py:446–486  ·  view source on GitHub ↗
(self, fullname)

Source from the content-addressed store, hash-verified

444 return _s(data) if data else ''
445
446 def get_code(self, fullname):
447 modname = fullname
448 if self.is_package(fullname):
449 fullname += '.__init__'
450
451 path = mod_path(fullname)
452 relpath = self._find_mod_path(fullname)
453 if relpath:
454 abspath = resfs_resolve(relpath)
455 if abspath:
456 if EXTERNAL_PY_FILES_MODE:
457 if not resfs_has(path):
458 # 1. This is the case when the requested module is registered in the metadata,
459 # but the content itself is not embedded in the binary.
460 # And the application itself is compiled in the external py files mode.
461 # Thus, we have an abspath to the python file and we need to get its bytecode.
462 # We transfer control to the standard python machinery,
463 # which will process the bytecode generation and cache it nearby,
464 # according to the general rules.
465 return super().get_code(modname)
466 else:
467 # 2. This is the case when the binary is launched in the mode of
468 # reading python sources from the file system (Y_PYTHON_SOURCE_ROOT),
469 # and not from the built-in storage.
470 data = file_bytes(abspath)
471 return compile(data, _s(abspath), 'exec', dont_inherit=True)
472
473 yapyc_path = path + b'.yapyc3'
474 yapyc_data = resfs_read(yapyc_path, builtin=True)
475 if yapyc_data:
476 # 3. This is the basic case - we read the compiled bytecode from the built-in storage.
477 return marshal.loads(yapyc_data)
478 else:
479 py_data = resfs_read(path, builtin=True)
480 if py_data:
481 # 4. This is the case when the bytecode for the module is not embedded in the binary (PYBUILD_NO_PYC).
482 # Read the python file and compile on the fly.
483 return compile(py_data, _s(relpath), 'exec', dont_inherit=True)
484 else:
485 # 5. This covers packages with no __init__.py in resources.
486 return compile('', modname, 'exec', dont_inherit=True)
487
488 def path_stats(self, path):
489 path = resfs_resolve(path, check_existence=False)

Callers 1

exec_moduleMethod · 0.95

Calls 8

is_packageMethod · 0.95
_find_mod_pathMethod · 0.95
mod_pathFunction · 0.85
resfs_resolveFunction · 0.85
resfs_hasFunction · 0.85
file_bytesFunction · 0.85
resfs_readFunction · 0.85
compileFunction · 0.50

Tested by

no test coverage detected