Skip to content

Commit

Permalink
Fix Python2 compatibility issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
wenLiangcan committed Feb 21, 2024
1 parent 67f529c commit cad0293
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.8 (2024-02-21)
- Fix Python2 compatibility issue.


## 0.3.7 (2024-02-21)
- Fix determining known licenses according to [RFC16](https://rfc.archlinux.page/0016-spdx-license-identifiers/) by [@hseg](https://github.com/hseg).

Expand Down
16 changes: 11 additions & 5 deletions pip2pkgbuild/pip2pkgbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import tarfile
import zipfile

if sys.version_info.major == 2:
IS_PY2 = sys.version_info.major == 2
if IS_PY2:
from cStringIO import StringIO as BytesIO
from urllib2 import urlopen, HTTPError
else:
Expand All @@ -24,7 +25,7 @@

META = {
'name': 'pip2pkgbuild',
'version': '0.3.7',
'version': '0.3.8',
'description': 'Generate PKGBUILD file for a Python module from PyPI',
}

Expand Down Expand Up @@ -103,9 +104,14 @@ def known_licenses():
"""
:rtype: list[str]
"""
args = {}
if IS_PY2:
args['openhook'] = fileinput.hook_encoded('utf-8')
else:
args['encoding'] = 'utf-8'
return fileinput.input(
files=('/usr/share/licenses/known_spdx_license_identifiers.txt'),
encoding='utf-8')
**args)


# Licenses we're allowed to skip installing, if this becomes desired
Expand Down Expand Up @@ -415,7 +421,7 @@ def __init__(self, module, python=None, depends=None, py2_depends=None,
self.email = email
self.pep517 = module.pep517

self.python = 'python2' if sys.version_info.major == 2 else 'python'
self.python = 'python2' if IS_PY2 else 'python'
if python in ['python', 'python2', 'multi']:
self.python = python

Expand Down Expand Up @@ -686,7 +692,7 @@ def main():
LOG.error('Must supply either both email and name or neither.')
sys.exit(1)
if args.pep517 and (
(args.python is None and sys.version_info.major == 2)
(args.python is None and IS_PY2)
or args.python == 'multi' or args.python == 'python2'
):
LOG.error('PEP517 based installation supports Python 3 packages only.')
Expand Down

0 comments on commit cad0293

Please sign in to comment.