Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/org.python.pydev.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Export-Package: org.python.copiedfromeclipsesrc,
org.python.pydev.core.log,
org.python.pydev.core.logging,
org.python.pydev.core.nature,
org.python.pydev.core.package_manager,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get java.lang.NoClassDefFoundError: org/python/pydev/core/package_manager/PoetryPackageManager when this is removed?

org.python.pydev.core.parser,
org.python.pydev.core.partition,
org.python.pydev.core.performanceeval,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
<key>DJANGO_MANAGE_LOCATION</key>
<value>manage.py</value>
</pydev_variables_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>

<pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">

<key>DJANGO_MANAGE_LOCATION</key>

<value>manage.py</value>

</pydev_variables_property>

<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">

<path>/${PROJECT_DIR_NAME}</path>

</pydev_pathproperty>

<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>

<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>

</pydev_project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
* Base package manager
*
* Using either poetry or uv, manage the commands available to apply to a project.
*
* @author Martin Whitehouse
*/
package org.python.pydev.core.package_manager;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.python.pydev.core.log.Log;

/**
* Using ProcessBuilder, runs the commands to achieve e.g. `poetry install
* package_name`.
*/
abstract public class BasePackageManager {
public enum Commands {
INSTALL("install"), ENV("env"), LOCK("lock"), SYNC("sync"), UPDATE("update");

private String command;

private Commands(String command) {
this.command = command;
}

public String command() {
return this.command;
}
}

/**
* Argument to use for changing to the project directory.
*/
private String chDirArg;

/**
* Name of the task
*/
protected String taskName;

/**
* Path to the project directory
*/
private String projectRoot;

/**
* Path to the binary
*/
private String binPath;

/**
* Title to use when binary can't be found.
*/
private String errorTitle;
/**
* Message to display.
*/
private String errorMsg;

public BasePackageManager(String projectRoot, String name, String prefsName, String chDirAarg) {
this.projectRoot = projectRoot;
this.chDirArg = chDirAarg;
binPath = Platform.getPreferencesService().getString("org.python.pydev", prefsName, null, null);
File f = null;
if (binPath != null) {
f = new File(binPath);
}
if (binPath == null | !(f != null && f.exists() && !f.isDirectory())) {
errorTitle = name + " not configured";
errorMsg = "The path to " + name + "could not be found.\n";
errorMsg += "Please configure the path to " + name;
}
}

private Boolean checkError() {
if (errorMsg != null) {
Log.log(errorTitle + "\n" + errorMsg);
return false;
}
return true;
}

protected ArrayList<String> getCommandArgs(String args) {
return new ArrayList<String>(Arrays.asList(args));
}

protected ArrayList<String> getCommandArgs(String[] args) {
ArrayList<String> parsedArgs = new ArrayList<String>();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrays.asList?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use Arrays.asList

for (String arg : args) {
parsedArgs.add(arg);
}
return parsedArgs;
}

public String add(String appName) {
List<String> args = getCommandArgs("add");
String[] apps = appName.split(" ");
for (String app : apps) {
args.add(app);
}
return runCommand(args);
}

public String lock() {
return runCommand(getCommandArgs("lock"));
}

public String sync() {
return runCommand(getCommandArgs("sync"));
}

public String remove(String appName) {
List<String> args = getCommandArgs("remove");
for (String app : appName.split(" ")) {
args.add(app);
}
return runCommand(args);
}

/**
* Returns the output of running `poetry args...`
*
* @param args List of arguments to pass to binPath e.g. "[poetry] env info"
* @return The command output
*/
public String runCommand(List<String> args) {
String output = null;
if (!checkError()) {
return output;
}
ArrayList<String> commandArgs = new ArrayList<String>();

commandArgs.add(binPath);
commandArgs.add(chDirArg);
commandArgs.add(projectRoot);

for (String arg : args) {
commandArgs.add(arg);
}

ProcessBuilder pb = new ProcessBuilder(commandArgs);
Process p;

try {
p = pb.start();
output = new String(p.getInputStream().readAllBytes()).strip();
} catch (IOException e) {
Log.log(e);
}

return output;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.python.pydev.core.package_manager;

import java.util.ArrayList;

public class PoetryPackageManager extends BasePackageManager {
final public static String PREFS_NAME = "POETRY_BIN";
private String pythonPath;

public PoetryPackageManager(String projectRoot) {
super(projectRoot, "poetry", PREFS_NAME, "-C");
}

public String install() {
return runCommand(getCommandArgs("install"));
}

@Override
public String add(String appName) {
ArrayList<String> args = getCommandArgs("add");
String[] apps = appName.split(" ");
for (String app : apps) {
args.add(app);
}
return runCommand(args);
}

public String update() {
return runCommand(getCommandArgs("update"));
}

/**
* Returns the path to the python executable of a pyproject virtual environment.
*
* @return the path to python
*/
public String getPython() {
if (pythonPath == null) {
pythonPath = runCommand(getCommandArgs(new String[] { "env", "info", "-e" }));
}
return pythonPath;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.python.pydev.core.package_manager;

public class UVPackageManager extends BasePackageManager {
final public static String PREFS_NAME = "UV_BIN";
private String pythonPath;

public UVPackageManager(String projectRoot) {
super(projectRoot, "uv", PREFS_NAME, "--directory");
}

/**
* Returns the path to the python executable of a pyproject virtual environment.
*
* @return the path to python
*/
public String getPython() {
if (pythonPath == null) {
pythonPath = runCommand(getCommandArgs(new String[] { "python", "find" }));
}
return pythonPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ JAVA_LOCATION=/usr/bin/java

#/usr/bin/cygpath.exe
#CYGWIN_UNIX_CYGPATH_LOCATION=null

Binary file added plugins/org.python.pydev/icons/PythonPoetry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions plugins/org.python.pydev/icons/PythonPoetry.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions plugins/org.python.pydev/icons/uv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading