Skip to content

Commit

Permalink
feat: Improve pip packaging
Browse files Browse the repository at this point in the history
Address several issues with vendoring python deps caused by newer versions of pip
* Ensure pip bootstrap components are not included in the package
* Remove dual py2/py3 suport
* Ensure no lib object has +x
  • Loading branch information
rfaircloth-splunk committed Jun 12, 2021
1 parent 9858189 commit 9b0c494
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import argparse
import json
from defusedxml import cElementTree as defused_et
from pathlib import Path
import stat

from .uccrestbuilder.global_config import (
GlobalConfigBuilderSchema,
GlobalConfigPostProcessor,
Expand Down Expand Up @@ -299,23 +302,29 @@ def _install_libs(requirements, ucc_target, installer="python3"):
else:
logging.info(f" Not using common requirements")

if os.path.exists(os.path.join(path,"lib","py2", "requirements.txt")):
logging.info(f" Uses py2 requirements")
_install_libs(requirements=os.path.join(path,"lib","py2", "requirements.txt"), installer="python2", ucc_target=os.path.join(ucc_lib_target, "py2"))
elif os.path.exists(os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py2.txt")):
logging.info(f" Uses py2 requirements")
_install_libs(requirements=os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py2.txt"), installer="python2", ucc_target=os.path.join(ucc_lib_target, "py2"))
else:
logging.info(f" Not using py2 requirements")

if os.path.exists(os.path.join(path, "lib","py3","requirements.txt")):
logging.info(f" Uses py3 requirements")
_install_libs(requirements=os.path.join(path,"lib", "py3","requirements.txt"), ucc_target=os.path.join(ucc_lib_target, "py3"))
elif os.path.exists(os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py3.txt")):
logging.info(f" Uses py3 requirements")
_install_libs(requirements=os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements_py3.txt"), installer="python3", ucc_target=os.path.join(ucc_lib_target, "py2"))
else:
logging.info(f" Not using py3 requirements")

#Prevent certain packages from being included pip could be dangerous others are just wasted space
noshipdirs = ['setuptools', 'bin', 'pip', 'distribute', 'wheel']
p = Path(ucc_lib_target)
try:
for nsd in noshipdirs:
for o in p.glob(nsd + '*'):
if o.is_dir():
shutil.rmtree(o)
except FileNotFoundError:
pass

#Remove execute bit from any object in lib
NO_USER_EXEC = ~stat.S_IEXEC
NO_GROUP_EXEC = ~stat.S_IXGRP
NO_OTHER_EXEC = ~stat.S_IXOTH
NO_EXEC = NO_USER_EXEC & NO_GROUP_EXEC & NO_OTHER_EXEC

for o in p.rglob("*"):
if not o.is_dir() and os.access(o, os.X_OK):
logging.info(f" fixing {o} execute bit")
current_permissions = stat.S_IMODE(os.lstat(o).st_mode)
os.chmod(o, current_permissions & NO_EXEC)


def remove_files(path):
Expand Down

0 comments on commit 9b0c494

Please sign in to comment.