Bug 1679918 - Use print() function in both Python 2 and Python 3
Summary: Use print() function in both Python 2 and Python 3
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-sdk-python
Classification: oVirt
Component: General
Version: 4.3.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ovirt-4.3.3
: ---
Assignee: Joey Ma
QA Contact: Lukas Svaty
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-02-22 08:48 UTC by Sandro Bonazzola
Modified: 2019-04-16 13:58 UTC (History)
6 users (show)

Fixed In Version: ovirt-engine-sdk-4.3.1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-04-16 13:58:16 UTC
oVirt Team: Infra
Embargoed:
sbonazzo: ovirt-4.3?


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 98014 0 master MERGED Fix critial lint errors reported by flake8 in PY3 2019-02-25 11:55:52 UTC

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.


Note You need to log in before you can comment on or make changes to this bug.