use of com.jetbrains.python.sdk.PythonSdkAdditionalData in project intellij-community by JetBrains.
the class PySdkFlavorTest method createMockSdk.
// TODO: Add tests for MayaPy and IronPython SDK flavors
@NotNull
private static Sdk createMockSdk(@NotNull PythonSdkFlavor flavor, @NotNull String versionOutput) {
final String versionString = flavor.getVersionStringFromOutput(versionOutput);
final ProjectJdkImpl sdk = new ProjectJdkImpl("Test", PythonSdkType.getInstance(), "/path/to/sdk", versionString);
sdk.setSdkAdditionalData(new PythonSdkAdditionalData(flavor));
return sdk;
}
use of com.jetbrains.python.sdk.PythonSdkAdditionalData in project intellij-community by JetBrains.
the class PythonCommandLineState method getAddedPaths.
public static List<String> getAddedPaths(Sdk pythonSdk) {
List<String> pathList = new ArrayList<>();
final SdkAdditionalData sdkAdditionalData = pythonSdk.getSdkAdditionalData();
if (sdkAdditionalData instanceof PythonSdkAdditionalData) {
final Set<VirtualFile> addedPaths = ((PythonSdkAdditionalData) sdkAdditionalData).getAddedPathFiles();
for (VirtualFile file : addedPaths) {
addToPythonPath(file, pathList);
}
}
return pathList;
}
use of com.jetbrains.python.sdk.PythonSdkAdditionalData in project intellij-community by JetBrains.
the class PythonGenerateProjectCallback method consume.
@Override
public void consume(@Nullable ProjectSettingsStepBase step) {
if (!(step instanceof ProjectSpecificSettingsStep))
return;
final ProjectSpecificSettingsStep settingsStep = (ProjectSpecificSettingsStep) step;
final DirectoryProjectGenerator generator = settingsStep.getProjectGenerator();
Sdk sdk = settingsStep.getSdk();
if (sdk instanceof PyDetectedSdk) {
sdk = addDetectedSdk(settingsStep, sdk);
}
if (generator instanceof PythonProjectGenerator) {
final BooleanFunction<PythonProjectGenerator> beforeProjectGenerated = ((PythonProjectGenerator) generator).beforeProjectGenerated(sdk);
if (beforeProjectGenerated != null) {
final boolean result = beforeProjectGenerated.fun((PythonProjectGenerator) generator);
if (!result) {
Messages.showWarningDialog("Project can not be generated", "Error in Project Generation");
return;
}
}
}
final Project newProject = generateProject(settingsStep);
if (generator instanceof PythonProjectGenerator && sdk == null && newProject != null) {
final PyNewProjectSettings settings = (PyNewProjectSettings) ((PythonProjectGenerator) generator).getProjectSettings();
((PythonProjectGenerator) generator).createAndAddVirtualEnv(newProject, settings);
sdk = settings.getSdk();
}
if (newProject != null && generator instanceof PythonProjectGenerator) {
SdkConfigurationUtil.setDirectoryProjectSdk(newProject, sdk);
final List<Sdk> sdks = PythonSdkType.getAllSdks();
for (Sdk s : sdks) {
final SdkAdditionalData additionalData = s.getSdkAdditionalData();
if (additionalData instanceof PythonSdkAdditionalData) {
((PythonSdkAdditionalData) additionalData).reassociateWithCreatedProject(newProject);
}
}
}
}
use of com.jetbrains.python.sdk.PythonSdkAdditionalData in project intellij-community by JetBrains.
the class PyTestSdkTools method generateTempSkeletonsOrPackages.
/**
* Adds installed eggs to SDK, generates skeletons (optionally) and associates it with module.
*
* @param sdk sdk to process
* @param addSkeletons add skeletons or only packages
* @param module module to associate with (if provided)
* @throws InvalidSdkException bas sdk
* @throws IOException failed to read eggs
*/
public static void generateTempSkeletonsOrPackages(@NotNull final Sdk sdk, final boolean addSkeletons, @Nullable final Module module) throws InvalidSdkException, IOException {
Project project = null;
if (module != null) {
project = module.getProject();
final Project finalProject = project;
// Associate with module
ModuleRootModificationUtil.setModuleSdk(module, sdk);
EdtTestUtil.runInEdtAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManager.getInstance(finalProject).setProjectSdk(sdk)));
}
final SdkModificator modificator = sdk.getSdkModificator();
modificator.removeRoots(OrderRootType.CLASSES);
modificator.setSdkAdditionalData(new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(sdk)));
for (final String path : PythonSdkType.getSysPathsFromScript(sdk.getHomePath())) {
addTestSdkRoot(modificator, path);
}
if (!addSkeletons) {
EdtTestUtil.runInEdtAndWait(modificator::commitChanges);
return;
}
final String skeletonsPath = PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath());
addTestSdkRoot(modificator, skeletonsPath);
EdtTestUtil.runInEdtAndWait(modificator::commitChanges);
PySkeletonRefresher.refreshSkeletonsOfSdk(project, null, skeletonsPath, sdk);
}
use of com.jetbrains.python.sdk.PythonSdkAdditionalData in project intellij-community by JetBrains.
the class PyStudyDirectoryProjectGenerator method createAndAddVirtualEnv.
public void createAndAddVirtualEnv(Project project, PyNewProjectSettings settings) {
final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
final String baseSdk = getBaseSdk(project);
if (baseSdk != null) {
final PyPackageManager packageManager = PyPackageManager.getInstance(new PyDetectedSdk(baseSdk));
try {
final String path = packageManager.createVirtualEnv(project.getBasePath() + "/.idea/VirtualEnvironment", false);
AbstractCreateVirtualEnvDialog.setupVirtualEnvSdk(path, true, new AbstractCreateVirtualEnvDialog.VirtualEnvCallback() {
@Override
public void virtualEnvCreated(Sdk createdSdk, boolean associateWithProject) {
settings.setSdk(createdSdk);
model.addSdk(createdSdk);
try {
model.apply();
} catch (ConfigurationException exception) {
LOG.error("Error adding created virtual env " + exception.getMessage());
}
if (associateWithProject) {
SdkAdditionalData additionalData = createdSdk.getSdkAdditionalData();
if (additionalData == null) {
additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(createdSdk.getHomePath()));
((ProjectJdkImpl) createdSdk).setSdkAdditionalData(additionalData);
}
((PythonSdkAdditionalData) additionalData).associateWithNewProject();
}
}
});
} catch (ExecutionException e) {
LOG.warn("Failed to create virtual env " + e.getMessage());
}
}
}
Aggregations