use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.
the class PythonUtils method getPythonSources.
//
// @CheckForNull
// public static PackageJson getPackageJson(Lookup context) {
// return getProjectAndPackageJson(context).second();
// }
//
// @CheckForNull
// public static Project getPackageJsonProject(Lookup context) {
// return getProjectAndPackageJson(context).first();
// }
//
// public static Pair<Project, PackageJson> getProjectAndPackageJson(Lookup context) {
// Project project = context.lookup(Project.class);
// PackageJson packageJson = null;
// if (project != null) {
// // project action
// packageJson = new PackageJson(project.getProjectDirectory());
// } else {
// // package.json directly
// FileObject file = context.lookup(FileObject.class);
// if (file == null) {
// DataObject dataObject = context.lookup(DataObject.class);
// if (dataObject != null) {
// file = dataObject.getPrimaryFile();
// }
// }
// if (file != null) {
// packageJson = new PackageJson(file.getParent());
// project = FileOwnerQuery.getOwner(file);
// }
// }
// if (project == null) {
// return Pair.of(null, null);
// }
// if (packageJson == null) {
// return Pair.of(null, null);
// }
// if (!packageJson.exists()) {
// return Pair.of(null, null);
// }
// assert project != null;
// assert packageJson != null;
// return Pair.of(project, packageJson);
// }
@CheckForNull
public static File getPythonSources(Project project) {
PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
if (preferences.isDefaultPython()) {
// default python
String pythonSources = PythonOptions.getInstance().getPythonSources();
if (pythonSources != null) {
return new File(pythonSources);
}
PythonExecutable python = PythonExecutable.getDefault(project, false);
if (python == null) {
return null;
}
Version version = python.getVersion();
if (version == null) {
return null;
}
return getPythonSources(version);
}
// custom python
String pythonSources = preferences.getPythonSources();
if (pythonSources != null) {
return new File(pythonSources);
}
PythonExecutable python = PythonExecutable.forProject(project, false);
if (python == null) {
return null;
}
Version version = python.getVersion();
if (version == null) {
return null;
}
return PythonUtils.getPythonSources(project);
}
Aggregations