Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pack recipe compatible with py2 & py3 #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/infi/recipe/python/pack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
__import__("pkg_resources").declare_namespace(__name__)

import sys

from infi.os_info import get_platform_string, get_version_from_git


PY2 = sys.version_info[0] == 2


def _get_version():
return "%s-%s" % (get_version_from_git(), get_platform_string())


class Recipe(object):
""" This recipe packs the 'dist' directory to python-<version>-<arch>.tar.gz
it honor the following options:
include_list: list of paths to add to the archive
exclide_list: list of paths that match the include list but should be excluded
exclude_list: list of paths that match the include list but should be excluded

note that each path should start with dist
"""
Expand Down Expand Up @@ -64,7 +71,11 @@ def install(self):
def _write_archive(self):
import tarfile
archive = tarfile.open(name=self.destination_file, mode='w:gz')
archive.add(name=self.source, arcname='python', exclude=self._tarfile_exclude)
if PY2:
kwargs = dict(exclude=self._tarfile_exclude)
else:
kwargs = dict(filter=self._tarfile_filter)
archive.add(name=self.source, arcname='python', **kwargs)

def _build_include_list(self):
self._include_list = [path.strip() for path in self._options.get("include_list", '').splitlines()]
Expand All @@ -86,5 +97,11 @@ def _tarfile_exclude(self, path):
return False
return True

def _tarfile_filter(self, tarinfo):
if self._tarfile_exclude(tarinfo.path):
return tarinfo
else:
return None

def update(self):
pass