Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4fcfd012 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Improve errors when compiling python code" into main

parents 3520b948 5a8f533a
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import argparse
import py_compile
import os
@@ -63,11 +64,23 @@ def main():
    parser.add_argument('dst_zip')
    args = parser.parse_args()

    errors = []
    with open(args.dst_zip, 'wb') as outf, open(args.src_zip, 'rb') as inf:
        with zipfile.ZipFile(outf, mode='w') as outzip, zipfile.ZipFile(inf, mode='r') as inzip:
            for name in inzip.namelist():
                with inzip.open(name, mode='r') as inzipf:
                    try:
                        process_one_file(name, inzipf, outzip)
                    except py_compile.PyCompileError as e:
                        errors.append(e)

    if errors:
        for i, error in enumerate(errors):
            # Print an empty line in between each error
            if i > 0:
                print(file=sys.stderr)
            print(str(error).strip(), file=sys.stderr)
        sys.exit(1)


if __name__ == "__main__":