// Get the possible Python directories (don't include *dist-info and bin)
// NOTE: This is an esoteric fix for Zope being broken which breaks Twisted - https://github.com/kpdyer/fteproxy/issues/66
@Override
    public void buildFunctionIfNecessary(FunctionConf functionConf) {
        // Snapshot the directory before installing dependencies
        List<Path> beforeSnapshot = getDirectorySnapshot(functionConf);
        loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Copying Greengrass SDK");
        copySdk(log, functionConf, resourceHelper, ioHelper);
        if (hasDependencies(functionConf.getBuildDirectory())) {
            loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Installing Python dependencies");
            installDependencies(functionConf);
        }
        // Snapshot the directory after installing dependencies
        List<Path> afterSnapshot = getDirectorySnapshot(functionConf);
        List<Path> addedFiles = new ArrayList<>(afterSnapshot);
        addedFiles.removeAll(beforeSnapshot);
        loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Packaging function for AWS Lambda");
        File tempFile = Try.of(() -> ioHelper.getTempFile("python-lambda-build", "zip")).get();
        // Get the directories, longest named directories first
        List<Path> addedDirectories = addedFiles
                .stream()
                .filter(path -> path.toFile().isDirectory())
                .sorted(Comparator.comparingInt(path -> path.toString().length()).reversed())
                .collect(Collectors.toList());
        // Get the possible Python directories (don't include *dist-info and bin)
        // NOTE: This is an esoteric fix for Zope being broken which breaks Twisted - https://github.com/kpdyer/fteproxy/issues/66
        List<Path> possibleBrokenPythonDirectories = addedDirectories
                .stream()
                .filter(path -> !path.toString().endsWith(DIST_INFO))
                .filter(path -> !path.toString().endsWith(BIN))
                .filter(path -> !path.resolve(INIT_PY).toFile().exists())
                .collect(Collectors.toList());
        // "Touch" the file to fix this issue
        possibleBrokenPythonDirectories.stream()
                .map(path -> path.resolve(INIT_PY).toFile())
                .forEach(this::touchAndIgnoreExceptions);
        ZipUtil.pack(functionConf.getBuildDirectory().toFile(), tempFile);
        moveDeploymentPackage(functionConf, tempFile);
    }
.sorted(Comparator.comparingInt(path -> path.toString().length()).reversed())
.collect(Collectors.toList());
// Get the possible Python directories (don't include *dist-info and bin)
// NOTE: This is an esoteric fix for Zope being broken which breaks Twisted - https://github.com/kpdyer/fteproxy/issues/66
List<Path> possibleBrokenPythonDirectories = addedDirectories
.stream()
List<Path> addedFiles = new ArrayList<>(afterSnapshot);
addedFiles.removeAll(beforeSnapshot);
loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Packaging function for AWS Lambda");
File tempFile = Try.of(() -> ioHelper.getTempFile("python-lambda-build", "zip")).get();
// Get the directories, longest named directories first
List<Path> addedDirectories = addedFiles
.stream()
.filter(path -> path.toFile().isDirectory())
.sorted(Comparator.comparingInt(path -> path.toString().length()).reversed())
.collect(Collectors.toList());
// Get the possible Python directories (don't include *dist-info and bin)
// NOTE: This is an esoteric fix for Zope being broken which breaks Twisted - https://github.com/kpdyer/fteproxy/issues/66
List<Path> possibleBrokenPythonDirectories = addedDirectories
.stream()
.filter(path -> !path.toString().endsWith(DIST_INFO))
.filter(path -> !path.toString().endsWith(BIN))
.filter(path -> !path.resolve(INIT_PY).toFile().exists())
.collect(Collectors.toList());
// "Touch" the file to fix this issue
possibleBrokenPythonDirectories.stream()
.map(path -> path.resolve(INIT_PY).toFile())
.forEach(this::touchAndIgnoreExceptions);
// Snapshot the directory before installing dependencies
List<Path> beforeSnapshot = getDirectorySnapshot(functionConf);
loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Copying Greengrass SDK");
copySdk(log, functionConf, resourceHelper, ioHelper);
if (hasDependencies(functionConf.getBuildDirectory())) {
loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Installing Python dependencies");
installDependencies(functionConf);
}
// Snapshot the directory after installing dependencies
List<Path> afterSnapshot = getDirectorySnapshot(functionConf);
List<Path> addedFiles = new ArrayList<>(afterSnapshot);
addedFiles.removeAll(beforeSnapshot);
loggingHelper.logInfoWithName(log, functionConf.getFunctionName(), "Packaging function for AWS Lambda");
File tempFile = Try.of(() -> ioHelper.getTempFile("python-lambda-build", "zip")).get();
// Get the directories, longest named directories first
List<Path> addedDirectories = addedFiles
.stream()
.filter(path -> path.toFile().isDirectory())
.sorted(Comparator.comparingInt(path -> path.toString().length()).reversed())
.collect(Collectors.toList());
// Get the possible Python directories (don't include *dist-info and bin)
// NOTE: This is an esoteric fix for Zope being broken which breaks Twisted - https://github.com/kpdyer/fteproxy/issues/66
List<Path> possibleBrokenPythonDirectories = addedDirectories
.stream()
.filter(path -> !path.toString().endsWith(DIST_INFO))
.filter(path -> !path.toString().endsWith(BIN))
.filter(path -> !path.resolve(INIT_PY).toFile().exists())
.collect(Collectors.toList());
// "Touch" the file to fix this issue
possibleBrokenPythonDirectories.stream()
.map(path -> path.resolve(INIT_PY).toFile())
.forEach(this::touchAndIgnoreExceptions);
ZipUtil.pack(functionConf.getBuildDirectory().toFile(), tempFile);
moveDeploymentPackage(functionConf, tempFile);
}