dianfu commented on a change in pull request #11448: [FLINK-16666][python][table] Support new Python dependency configuration options in flink-table. URL: https://github.com/apache/flink/pull/11448#discussion_r404622369
########## File path: flink-clients/src/main/java/org/apache/flink/client/cli/PythonProgramOptions.java ########## @@ -0,0 +1,182 @@ +/* + * 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.annotation.VisibleForTesting; +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.ConfigOptions; +import org.apache.flink.configuration.Configuration; + +import org.apache.commons.cli.CommandLine; + +import javax.annotation.Nullable; + +import static org.apache.flink.client.cli.CliFrontendParser.PYARCHIVE_OPTION; +import static org.apache.flink.client.cli.CliFrontendParser.PYEXEC_OPTION; +import static org.apache.flink.client.cli.CliFrontendParser.PYFILES_OPTION; +import static org.apache.flink.client.cli.CliFrontendParser.PYMODULE_OPTION; +import static org.apache.flink.client.cli.CliFrontendParser.PYREQUIREMENTS_OPTION; +import static org.apache.flink.client.cli.CliFrontendParser.PY_OPTION; + +/** + * The command line options refer to a Python program. + */ +public class PythonProgramOptions { + + /** + * Internal Python config options used to store the path of the entry point script. It would be read in + * "PythonDriver#main(String[] args)". + */ + public static final ConfigOption<String> PYTHON_ENTRY_POINT_SCRIPT = + ConfigOptions.key("python.internal.entry-point.script").stringType().noDefaultValue(); + + /** + * Internal Python config options used to store the entry point module. It would be read in + * "PythonDriver#main(String[] args)". + */ + public static final ConfigOption<String> PYTHON_ENTRY_POINT_MODULE = + ConfigOptions.key("python.internal.entry-point.module").stringType().noDefaultValue(); + + @VisibleForTesting + static final ConfigOption<String> PYTHON_FILES = + ConfigOptions.key("python.files").stringType().noDefaultValue(); + + @VisibleForTesting + static final ConfigOption<String> PYTHON_REQUIREMENTS = + ConfigOptions.key("python.requirements").stringType().noDefaultValue(); + + @VisibleForTesting + static final ConfigOption<String> PYTHON_ARCHIVES = + ConfigOptions.key("python.archives").stringType().noDefaultValue(); + + @VisibleForTesting + static final ConfigOption<String> PYTHON_EXECUTABLE = + ConfigOptions.key("python.executable").stringType().noDefaultValue(); + + @Nullable + private final String pyEntryPointScript; + + @Nullable + private final String pyEntryPointModule; + + @Nullable + private final String pyFiles; + + @Nullable + private final String pyRequirements; + + @Nullable + private final String pyExecutable; + + @Nullable + private final String pyArchives; + + public PythonProgramOptions( + String pyFiles, + String pyRequirements, + String pyArchives, + String pyExecutable, + String pyEntryPointScript, + String pyEntryPointModule) { + this.pyFiles = pyFiles; + this.pyRequirements = pyRequirements; + this.pyArchives = pyArchives; + this.pyExecutable = pyExecutable; + this.pyEntryPointScript = pyEntryPointScript; + this.pyEntryPointModule = pyEntryPointModule; + } + + public void writeToConfiguration(Configuration config) { + if (pyFiles != null) { + config.set(PYTHON_FILES, pyFiles); + } + + if (pyRequirements != null) { + config.set(PYTHON_REQUIREMENTS, pyRequirements); + } + + if (pyArchives != null) { + config.set(PYTHON_ARCHIVES, pyArchives); + } + + if (pyExecutable != null) { + config.set(PYTHON_EXECUTABLE, pyExecutable); + } + + if (pyEntryPointScript != null) { + config.set(PYTHON_ENTRY_POINT_SCRIPT, pyEntryPointScript); + } + + if (pyEntryPointModule != null) { + config.set(PYTHON_ENTRY_POINT_MODULE, pyEntryPointModule); + } + } + + public static PythonProgramOptions parse(CommandLine commandLine) { + final String pyFiles; + if (commandLine.hasOption(PYFILES_OPTION.getOpt())) { + pyFiles = commandLine.getOptionValue(PYFILES_OPTION.getOpt()); + } else { + pyFiles = null; + } + + final String pyRequirements; + if (commandLine.hasOption(PYREQUIREMENTS_OPTION.getOpt())) { + pyRequirements = commandLine.getOptionValue(PYREQUIREMENTS_OPTION.getOpt()); + } else { + pyRequirements = null; + } + + final String pyArhives; Review comment: typo: pyArhives -> pyArchives ---------------------------------------------------------------- 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] With regards, Apache Git Services
