Beispiel #1
0
  /**
   * Change the pythonpath (used for both: system and project)
   *
   * @param project: may be null
   * @param defaultSelectedInterpreter: may be null
   */
  public void changePythonPath(
      String pythonpath, final IProject project, IProgressMonitor monitor) {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }

    pythonPathHelper.setPythonPath(pythonpath);
    ModulesFoundStructure modulesFound = pythonPathHelper.getModulesFoundStructure(monitor);

    PyPublicTreeMap<ModulesKey, ModulesKey> keys = buildKeysFromModulesFound(monitor, modulesFound);
    onChangePythonpath(keys);

    synchronized (modulesKeysLock) {
      // assign to instance variable
      this.modulesKeys.clear();
      this.modulesKeys.putAll(keys);
    }
  }
Beispiel #2
0
  /**
   * Change the pythonpath (used for both: system and project)
   *
   * @param project: may be null
   * @param defaultSelectedInterpreter: may be null
   */
  public void changePythonPath(
      String pythonpath, final IProject project, IProgressMonitor monitor) {
    pythonPathHelper.setPythonPath(pythonpath);
    ModulesFoundStructure modulesFound = pythonPathHelper.getModulesFoundStructure(monitor);

    // now, on to actually filling the module keys
    ModulesKeyTreeMap<ModulesKey, ModulesKey> keys =
        new ModulesKeyTreeMap<ModulesKey, ModulesKey>();
    int j = 0;

    FastStringBuffer buffer = new FastStringBuffer();
    // now, create in memory modules for all the loaded files (empty modules).
    for (Iterator<Map.Entry<File, String>> iterator =
            modulesFound.regularModules.entrySet().iterator();
        iterator.hasNext() && monitor.isCanceled() == false;
        j++) {
      Map.Entry<File, String> entry = iterator.next();
      File f = entry.getKey();
      String m = entry.getValue();

      if (j % 15 == 0) {
        // no need to report all the time (that's pretty fast now)
        buffer.clear();
        monitor.setTaskName(buffer.append("Module resolved: ").append(m).toString());
        monitor.worked(1);
      }

      if (m != null) {
        // we don't load them at this time.
        ModulesKey modulesKey = new ModulesKey(m, f);

        // no conflict (easy)
        if (!keys.containsKey(modulesKey)) {
          keys.put(modulesKey, modulesKey);
        } else {
          // we have a conflict, so, let's resolve which one to keep (the old one or this one)
          if (PythonPathHelper.isValidSourceFile(f.getName())) {
            // source files have priority over other modules (dlls) -- if both are source, there is
            // no real way to resolve
            // this priority, so, let's just add it over.
            keys.put(modulesKey, modulesKey);
          }
        }
      }
    }

    for (ZipContents zipContents : modulesFound.zipContents) {
      if (monitor.isCanceled()) {
        break;
      }
      for (String filePathInZip : zipContents.foundFileZipPaths) {
        String modName = StringUtils.stripExtension(filePathInZip).replace('/', '.');
        if (DEBUG_ZIP) {
          System.out.println("Found in zip:" + modName);
        }
        ModulesKey k = new ModulesKeyForZip(modName, zipContents.zipFile, filePathInZip, true);
        keys.put(k, k);

        if (zipContents.zipContentsType == ZipContents.ZIP_CONTENTS_TYPE_JAR) {
          // folder modules are only created for jars (because for python files, the __init__.py is
          // required).
          for (String s :
              new FullRepIterable(
                  FullRepIterable.getWithoutLastPart(
                      modName))) { // the one without the last part was already added
            k = new ModulesKeyForZip(s, zipContents.zipFile, s.replace('.', '/'), false);
            keys.put(k, k);
          }
        }
      }
    }

    onChangePythonpath(keys);

    // assign to instance variable
    this.setModules(keys);
  }