Bug 1679918

Summary: Use print() function in both Python 2 and Python 3
Product: [oVirt] ovirt-engine-sdk-python Reporter: Sandro Bonazzola <sbonazzo>
Component: GeneralAssignee: Joey Ma <majunjiev>
Status: CLOSED CURRENTRELEASE QA Contact: Lukas Svaty <lsvaty>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 4.3.0CC: bugs, juan.hernandez, lsvaty, majunjiev, mperina, omachace
Target Milestone: ovirt-4.3.3Keywords: CodeChange
Target Release: ---Flags: sbonazzo: ovirt-4.3?
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ovirt-engine-sdk-4.3.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-04-16 13:58:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Sandro Bonazzola 2019-02-22 08:48:00 UTC
Initially reported in https://github.com/oVirt/ovirt-engine-sdk/issues/15 by cclauss

Quoting:
"""
Legacy **print** statements are syntax errors in Python 3 but **print()** function works as expected in both Python 2 and Python 3.

[flake8](http://flake8.pycqa.org) testing of https://github.com/oVirt/ovirt-engine-sdk on Python 3.7.1

$ **flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics**

```
./automation/build.py:155:68: F821 undefined name 'version'
        print("SDK version \"%s\" doesn't match format \"%s\"." % (version, version_re.pattern))
                                                                   ^
./sdk/setup.py:52:13: F821 undefined name 'VERSION'
    version=VERSION,
            ^
./sdk/examples/add_vm_snapshot.py:36:7: F821 undefined name 'logger'
  log=logger.getLogger(),
      ^
./sdk/examples/upload_disk_snapshots.py:137:23: E999 SyntaxError: invalid syntax
                print r.status, r.reason, "Completed", "{:.0%}".format(pos / float(size))
                      ^
./sdk/examples/attach_nfs_data_storage_domain.py:38:9: F821 undefined name 'logger'
    log=logger.getLogger(),
        ^
./sdk/examples/download_disk_snapshots.py:93:40: E999 SyntaxError: invalid syntax
    print "Downloading disk snapshot %s" % disk_snapshot.id
                                       ^
./sdk/examples/download_disk.py:131:35: F821 undefined name 'HttpException'
        except (EnvironmentError, HttpException):
                                  ^
2     E999 SyntaxError: invalid syntax
5     F821 undefined name 'version'
7
```
**E901,E999,F821,F822,F823** are the "_showstopper_" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.

* F821: undefined name `name`
* F822: undefined name `name` in `__all__`
* F823: local variable name referenced before assignment
* E901: SyntaxError or IndentationError
* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree


"""

Comment 1 Joey Ma 2019-02-24 14:38:06 UTC
In ./sdk/setup.py, the var `VERSION` is defined previously by the `exec()` function at line 36. So with regards to the issue reporting "./sdk/setup.py:52:13: F821 undefined name 'VERSION'", we could probably ignore it. A patch was posted to fix the others.

Comment 2 Sandro Bonazzola 2019-04-16 13:58:16 UTC
This bugzilla is included in oVirt 4.3.3 release, published on April 16th 2019.

Since the problem described in this bug report should be
resolved in oVirt 4.3.3 release, it has been closed with a resolution of CURRENT RELEASE.

If the solution does not work for you, please open a new bug report.