Skip to content

Commit

Permalink
feat: pip causing app inspect failures and NOTICE (#224)
Browse files Browse the repository at this point in the history
* feat: Improve pip packaging

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

* fixup

Add logging

* Correct order of try/for
  • Loading branch information
Ryan Faircloth authored Jun 14, 2021
1 parent 1bddfd6 commit d83b687
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion 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 @@ -297,7 +300,34 @@ def _install_libs(requirements, ucc_target, installer="python3"):
logging.info(f" Uses common requirements")
_install_libs(requirements=os.path.join(os.path.abspath(os.path.join(path, os.pardir)), "requirements.txt"), ucc_target=ucc_lib_target)
else:
logging.info(f" Not using common requirements")
logging.info(f" Not using common 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)
for nsd in noshipdirs:
try:
#Glob can return FileNotFoundError exception if no match
for o in p.glob(nsd + '*'):
if o.is_dir():
logging.info(f" removing directory {o} from output must not ship")
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 d83b687

Please sign in to comment.