Jelajahi Sumber

Try updating to python3 (#48367)

* Try updating to python3

* Fix submods

* Print syntax

* More

* More fixups

* Fix iteritems

* Headers
William Godbe 2 tahun lalu
induk
melakukan
6c662536e5

+ 1 - 1
eng/docker/bionic.Dockerfile

@@ -14,7 +14,7 @@ RUN apt-get update && \
         jq \
         wget \
         locales \
-        python \
+        python3 \
         fakeroot \
         debhelper \
         build-essential \

+ 3 - 3
src/Installers/Debian/tools/build.sh

@@ -126,7 +126,7 @@ validate_inputs(){
 }
 
 parse_config_and_set_env_vars(){
-    extract_base_cmd="python $SCRIPT_DIR/scripts/extract_json_value.py"
+    extract_base_cmd="python3 $SCRIPT_DIR/scripts/extract_json_value.py"
 
     # Arguments Take Precedence over Config
     [ -z "$PACKAGE_VERSION" ] && PACKAGE_VERSION="$($extract_base_cmd $CONFIG "release.package_version")"
@@ -232,7 +232,7 @@ package_install_scripts(){
 
 ## Generation Functions ##
 generate_config_templates(){
-    python ${SCRIPT_DIR}/scripts/config_template_generator.py $CONFIG $SCRIPT_DIR/templates/debian $DEBIAN_DIR $PACKAGE_NAME $PACKAGE_VERSION
+    python3 ${SCRIPT_DIR}/scripts/config_template_generator.py $CONFIG $SCRIPT_DIR/templates/debian $DEBIAN_DIR $PACKAGE_NAME $PACKAGE_VERSION
 }
 
 generate_manpages(){
@@ -240,7 +240,7 @@ generate_manpages(){
         mkdir -p $DOCS_DIR
 
         # Generate the manpages from json spec
-        python ${SCRIPT_DIR}/scripts/manpage_generator.py ${DOCS_JSON_PATH} ${DOCS_DIR}
+        python3 ${SCRIPT_DIR}/scripts/manpage_generator.py ${DOCS_JSON_PATH} ${DOCS_DIR}
     fi
 }
 

+ 5 - 5
src/Installers/Debian/tools/scripts/config_template_generator.py

@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Copyright (c) .NET Foundation and contributors. All rights reserved.
 # Licensed under the MIT license. See LICENSE file in the project root for full license information.
@@ -47,7 +47,7 @@ def generate_and_write_all(config_data, template_dir, output_dir, package_name=N
         symlink_contents = generate_symlinks(config_data, package_name=package_name)
         rules_contents = generate_rules(config_data, template_dir)
     except Exception as exc:
-      print exc
+      print(exc)
       help_and_exit("Error: Generation Failed, check your config file.")
 
     write_file(changelog_contents, output_dir, FILE_CHANGELOG)
@@ -157,7 +157,7 @@ def generate_symlinks(config_data, package_name=None):
 
     symlink_data = config_data.get("symlinks", dict())
 
-    for package_rel_path, symlink_path in symlink_data.iteritems():
+    for package_rel_path, symlink_path in iter(symlink_data.items()):
 
         package_abs_path = os.path.join(package_root_path, package_rel_path)
 
@@ -222,11 +222,11 @@ def write_file(contents, output_dir, name):
 
 # Tool Functions
 def help_and_exit(msg):
-    print msg
+    print(msg)
     sys.exit(1)
 
 def print_usage():
-    print "Usage: config_template_generator.py [config file path] [template directory path] [output directory] (package name) (package version)"
+    print("Usage: config_template_generator.py [config file path] [template directory path] [output directory] (package name) (package version)")
 
 def parse_and_validate_args():
     if len(sys.argv) < 4:

+ 5 - 5
src/Installers/Debian/tools/scripts/extract_json_value.py

@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Copyright (c) .NET Foundation and contributors. All rights reserved.
 # Licensed under the MIT license. See LICENSE file in the project root for full license information.
@@ -12,13 +12,13 @@ import sys
 import json
 
 def print_usage():
-	print """
+	print("""
 		Usage: extract_json_value.py [json file path] [key of value to extract]
 		For nested keys, use . separator
-	"""
+	""")
 
 def help_and_exit(msg=None):
-	print msg
+	print(msg)
 	print_usage()
 	sys.exit(1)
 
@@ -60,5 +60,5 @@ def execute():
 	return value
 
 if __name__ == "__main__":
-	print execute()
+	print(execute())
 

+ 4 - 4
src/Installers/Debian/tools/scripts/manpage_generator.py

@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Copyright (c) .NET Foundation and contributors. All rights reserved.
 # Licensed under the MIT license. See LICENSE file in the project root for full license information.
@@ -271,8 +271,8 @@ def _option_string_helper(specifier_short, specifier_long, parameter, include_br
 
 
 def print_usage():
-    print "Usage: argv[1] = path to docs.json; argv[2] = output path"
-    print "Example: manpage_generator.py ../docs.json ./dotnet-1.0/debian"
+    print("Usage: argv[1] = path to docs.json; argv[2] = output path")
+    print("Example: manpage_generator.py ../docs.json ./dotnet-1.0/debian")
 
 def parse_args():
     doc_path = sys.argv[1]
@@ -296,7 +296,7 @@ def execute_command_line():
         generate_man_pages(doc_path, output_dir)
 
     except Exception as exc:
-        print "Error: ", exc
+        print("Error: ", exc)
         print_usage()
 
 if __name__ == "__main__":

+ 1 - 1
src/Installers/Debian/tools/test/test_assets/test_package_layout/debian_config.json

@@ -31,7 +31,7 @@
         "curl": {
             "package_version" : "0.5.3"                         
         },
-        "python":{}
+        "python3":{}
     }, 
 
     "symlinks": {                                               

+ 1 - 1
src/Installers/Debian/tools/test/unit_tests/test_scripts.bats

@@ -14,7 +14,7 @@ setup(){
 @test "manpage generation is identical to lkg file" {
     # Output is file "tool1.1"
     # LKG file is "lkgtestman.1"
-    python $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets
+    python3 $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets
 
     # Test Output existence
     [ -f $PACKAGIFY_DIR/test/test_assets/tool1.1 ]