Skip to content

Commit

Permalink
NIFI-12959: Addressed review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
markap14 committed Apr 4, 2024
1 parent 709e983 commit 0a4f5b2
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ private String generateAuthToken() {
return Base64.getEncoder().encodeToString(bytes);
}

private boolean isUseVirtualEnv() {
return !packagedWithDependencies;
private boolean isPackagedWithDependencies() {
return packagedWithDependencies;
}

private Process launchPythonProcess(final int listeningPort, final String authToken) throws IOException {
Expand All @@ -240,7 +240,7 @@ private Process launchPythonProcess(final int listeningPort, final String authTo

final List<String> commands = new ArrayList<>();
commands.add(pythonCommand);
if (!isUseVirtualEnv()) {
if (isPackagedWithDependencies()) {
// If not using venv, we will not launch a separate virtual environment, so we need to use the -S
// flag in order to prevent the Python process from using the installation's site-packages. This provides
// proper dependency isolation to the Python process.
Expand All @@ -249,9 +249,12 @@ private Process launchPythonProcess(final int listeningPort, final String authTo

String pythonPath = pythonApiDirectory.getAbsolutePath();
final String absolutePath = virtualEnvHome.getAbsolutePath();
final File dependenciesDir = new File(new File(absolutePath), "NAR-INF/bundled-dependencies");
pythonPath = pythonPath + File.pathSeparator + absolutePath;
pythonPath = pythonPath + File.pathSeparator + dependenciesDir.getAbsolutePath();

if (isPackagedWithDependencies()) {
final File dependenciesDir = new File(new File(absolutePath), "NAR-INF/bundled-dependencies");
pythonPath = pythonPath + File.pathSeparator + dependenciesDir.getAbsolutePath();
}

if (processConfig.isDebugController() && "Controller".equals(componentId)) {
commands.add("-m");
Expand Down Expand Up @@ -283,7 +286,7 @@ private Process launchPythonProcess(final int listeningPort, final String authTo
// Visible for testing
String resolvePythonCommand() throws IOException {
// If pip is disabled, we will not create separate virtual environments for each Processor and thus we will use the configured Python command
if (!isUseVirtualEnv()) {
if (!isPackagedWithDependencies()) {
return processConfig.getPythonCommand();
}

Expand Down Expand Up @@ -311,8 +314,8 @@ String resolvePythonCommand() throws IOException {
private void setupEnvironment() throws IOException {
// Environment creation is only necessary if using PIP. Otherwise, the Process requires no outside dependencies, other than those
// provided in the package and thus we can simply include those packages in the PYTHON_PATH.
if (!isUseVirtualEnv()) {
logger.debug("Will not create Python Virtual Environment because PIP is disabled in nifi.properties");
if (!isPackagedWithDependencies()) {
logger.debug("Will not create Python Virtual Environment because Python Processor packaged with dependencies");
return;
}

Expand Down

0 comments on commit 0a4f5b2

Please sign in to comment.