dianfu commented on a change in pull request #11702:
URL: https://github.com/apache/flink/pull/11702#discussion_r411877184



##########
File path: 
flink-clients/src/main/java/org/apache/flink/client/cli/ProgramOptions.java
##########
@@ -184,10 +175,65 @@ public SavepointRestoreSettings 
getSavepointRestoreSettings() {
                return savepointSettings;
        }
 
-       /**
-        * Indicates whether the job is a Python job.
-        */
-       public boolean isPython() {
-               return isPython;
+       public void applyToConfiguration(Configuration configuration) {
+               if (getParallelism() != ExecutionConfig.PARALLELISM_DEFAULT) {
+                       
configuration.setInteger(CoreOptions.DEFAULT_PARALLELISM, getParallelism());
+               }
+
+               configuration.setBoolean(DeploymentOptions.ATTACHED, 
!getDetachedMode());
+               
configuration.setBoolean(DeploymentOptions.SHUTDOWN_IF_ATTACHED, 
isShutdownOnAttachedExit());
+               ConfigUtils.encodeCollectionToConfig(configuration, 
PipelineOptions.CLASSPATHS, getClasspaths(), URL::toString);
+               
SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(), 
configuration);
+       }
+
+       public static ProgramOptions create(CommandLine line) throws 
CliArgsException {
+               if (isPython(line) || containsPythonDependencyOptions(line)) {
+                       return createPythonPropramOptions(line);

Review comment:
       typo: createPythonPropramOptions  -> createPythonProgramOptions

##########
File path: 
flink-python/src/main/java/org/apache/flink/client/cli/PythonProgramOptions.java
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.client.cli;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.python.util.PythonDependencyUtils;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.apache.flink.client.cli.CliFrontendParser.ARGS_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.PYMODULE_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.PY_OPTION;
+
+/**
+ * The class for command line options that refer to a Python program or JAR 
program with Python command line options.
+ */
+public class PythonProgramOptions extends ProgramOptions {
+
+       private final Configuration pythonConfiguration;
+
+       private final boolean isPython;
+
+       public PythonProgramOptions(CommandLine line) throws CliArgsException {
+               super(line);
+               isPython = isPython(line);

Review comment:
       The name `isPython` is confusing. Considering the class 
`PythonProgramOptions` is specify for Python, should it always be true? I guess 
you mean `isEntryPointPython`? If so we should rename the variable `isPython` 
and the util method `isPython` to `isEntryPointPython`. What do you think?

##########
File path: 
flink-clients/src/main/java/org/apache/flink/client/cli/ProgramOptions.java
##########
@@ -184,10 +175,65 @@ public SavepointRestoreSettings 
getSavepointRestoreSettings() {
                return savepointSettings;
        }
 
-       /**
-        * Indicates whether the job is a Python job.
-        */
-       public boolean isPython() {
-               return isPython;
+       public void applyToConfiguration(Configuration configuration) {
+               if (getParallelism() != ExecutionConfig.PARALLELISM_DEFAULT) {
+                       
configuration.setInteger(CoreOptions.DEFAULT_PARALLELISM, getParallelism());
+               }
+
+               configuration.setBoolean(DeploymentOptions.ATTACHED, 
!getDetachedMode());
+               
configuration.setBoolean(DeploymentOptions.SHUTDOWN_IF_ATTACHED, 
isShutdownOnAttachedExit());
+               ConfigUtils.encodeCollectionToConfig(configuration, 
PipelineOptions.CLASSPATHS, getClasspaths(), URL::toString);
+               
SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(), 
configuration);
+       }
+
+       public static ProgramOptions create(CommandLine line) throws 
CliArgsException {
+               if (isPython(line) || containsPythonDependencyOptions(line)) {
+                       return createPythonPropramOptions(line);
+               } else {
+                       return new ProgramOptions(line);
+               }
+       }
+
+       static boolean isPython(CommandLine line) {

Review comment:
       Should we move these kinds of util methods to a class such as 
`ProgramOptionsUtils` to make `ProgramOptions` more clean?  What's your 
thought? @aljoscha 

##########
File path: 
flink-python/src/test/java/org/apache/flink/python/util/PythonDependencyUtilsTest.java
##########
@@ -184,20 +197,83 @@ public void testPythonExecutables() {
                verifyConfiguration(expectedConfiguration, actual);
        }
 
+       @Test
+       public void testCreateProgramOptionsWithPythonCommandLine() throws 
CliArgsException {

Review comment:
       What about create a PythonProgramOptionsTest and move this test case 
there.

##########
File path: 
flink-python/src/test/java/org/apache/flink/python/util/PythonDependencyUtilsTest.java
##########
@@ -184,20 +197,83 @@ public void testPythonExecutables() {
                verifyConfiguration(expectedConfiguration, actual);
        }
 
+       @Test
+       public void testCreateProgramOptionsWithPythonCommandLine() throws 
CliArgsException {
+               Options options = getPythonCommandLineOptions();
+               String[] parameters = {
+                       "-py", "test.py",
+                       "-pym", "test",
+                       "-pyfs", "test1.py,test2.zip,test3.egg,test4_dir",
+                       "-pyreq", "a.txt#b_dir",
+                       "-pyarch", "c.zip#venv,d.zip",
+                       "-pyexec", "bin/python",
+                       "userarg1", "userarg2"
+               };
+
+               CommandLine line = CliFrontendParser.parse(options, parameters, 
false);
+               PythonProgramOptions programOptions = (PythonProgramOptions) 
ProgramOptions.create(line);
+               Configuration config = new Configuration();
+               programOptions.applyToConfiguration(config);
+               assertEquals("test1.py,test2.zip,test3.egg,test4_dir", 
config.get(PythonOptions.PYTHON_FILES));
+               assertEquals("a.txt#b_dir", config.get(PYTHON_REQUIREMENTS));
+               assertEquals("c.zip#venv,d.zip", 
config.get(PythonOptions.PYTHON_ARCHIVES));
+               assertEquals("bin/python", config.get(PYTHON_EXECUTABLE));
+               assertArrayEquals(
+                       new String[] {"--python", "test.py", "--pyModule", 
"test", "userarg1", "userarg2"},
+                       programOptions.getProgramArgs());
+       }
+
+       @Test
+       public void testCreateProgramOptionsWithLongOptions() throws 
CliArgsException {

Review comment:
       ditto




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to