Exemple #1
0
 def _get_code(self, fullmodname):
   submodname, is_package, relpath = self._get_info(fullmodname)
   relsplit, _ = os.path.split(relpath)
   fullpath = '%s%s%s' % (self.archive, os.sep, relpath)
   pyc = os.path.splitext(fullpath)[0] + '.pyc'
   try:
     with timed('Unmarshaling %s' % pyc, at_level=2):
       pyc_object = CodeMarshaller.from_pyc(Nested.read(pyc))
   except (Nested.FileNotFound, ValueError, CodeMarshaller.InvalidCode) as e:
     with timed('Compiling %s because of %s' % (fullpath, e.__class__.__name__), at_level=2):
       py = Nested.read(fullpath).decode('utf-8')
       assert py is not None
       py = py.replace('\r\n', '\n').replace('\r', '\n')
       pyc_object = CodeMarshaller.from_py(py, fullpath)
   return submodname, is_package, fullpath, pyc_object.code
Exemple #2
0
 def _get_code(self, fullmodname):
   submodname, is_package, relpath = self._get_info(fullmodname)
   relsplit, _ = os.path.split(relpath)
   fullpath = '%s%s%s' % (self.archive, os.sep, relpath)
   pyc = os.path.splitext(fullpath)[0] + '.pyc'
   try:
     with timed('Unmarshaling %s' % pyc, at_level=2):
       pyc_object = CodeMarshaller.from_pyc(Compatibility.BytesIO(Nested.read(pyc)))
   except (Nested.FileNotFound, ValueError, CodeMarshaller.InvalidCode) as e:
     with timed('Compiling %s because of %s' % (fullpath, e.__class__.__name__), at_level=2):
       py = Nested.read(fullpath)
       assert py is not None
       if Compatibility.PY3:
         py = py.decode('utf8')
       pyc_object = CodeMarshaller.from_py(py, fullpath)
   return submodname, is_package, fullpath, pyc_object.code
Exemple #3
0
 def add_source(self, filename, env_filename):
   self._chroot.link(filename, env_filename, "source")
   if filename.endswith('.py'):
     env_filename_pyc = os.path.splitext(env_filename)[0] + '.pyc'
     # with PEX.timed('Compiling %s' % env_filename_pyc):
     with open(filename) as fp:
       pyc_object = CodeMarshaller.from_py(fp.read(), env_filename)
     self._chroot.write(pyc_object.to_pyc(), env_filename_pyc, 'source')