Commits

Henning Schröder committed 725f049

more work on project importers

Comments (0)

Files changed (1)

pycode/project.py

 
 
 class ProjectImporter(object):
-    pass
+
+    def guess_source_folders(self, root):
+        src_folder = os.path.join(root, "src")
+        if os.path.isdir(src_folder):
+            return [src_folder]
+        else:
+            # XXX: use heuristic to find packages?
+            return [root]
+
+
+    def settings(self, filename):
+        prefs = {}
+        prefs["project_name"] = self.project_name(filename)
+        prefs["project_root"] = self.project_root(filename)
+        parsed = self.load(filename)
+        prefs.update(self.evaluate(parsed))
+        prefs["source_folders"] = prefs.get(
+            "source_folders", None) or self.guess_source_folders(prefs["project_root"])
+        prefs["interpreter"] = Interpreter()
+        return prefs
 
 
 class ProjectDirectoryImporter(ProjectImporter):
 
     directory = None
 
+    def project_root(self, path):
+        return os.path.dirname(path)
+
+
+    def project_name(self, path):
+        return os.path.basename(os.path.dirname(path))
+
 
     def discover(self, path):
         filename = os.path.join(path, self.directory)
         if os.path.exists(filename):
             if self.validate(filename):
-                return [(os.path.basename(path), filename)]
+                return [filename]
 
 
     def validate(self, path):
     filename = None
 
 
+    def project_root(self, filename):
+        return os.path.dirname(filename)
+
+
+    def project_name(self, path):
+        return os.path.basename(os.path.dirname(path))
+
+
     def discover(self, path):
         filename = os.path.join(path, self.filename)
         if os.path.exists(filename):
-            return [os.path.basename(path), filename]
+            if self.validate(filename):
+                return [filename]
 
 
     def validate(self, path):
         return not os.path.isdir(path)
 
 
+    def project_root(self, filename):
+        return os.path.dirname(filename)
+
+
+    def project_name(self, filename):
+        return os.path.splitext(os.path.basename(filename))[0]
+
+
 
 
 class RopeProjectImporter(ProjectDirectoryImporter):
 
     def load(self, filename):
         #xml = etree(filename)
-        pass
+        return {}
 
     def evaluate(self, prefs):
         return {}
 
 
 
-class AnyProjectImporter(object):
+class AnyProjectImporter(ProjectImporter):
     classes = [PyCodeProjectImporter,
                PyCharmProjectImporter, NinjaIdeProjectImporter, RopeProjectImporter, SpyderProjectImporter]
 
                 return found
 
 
+    def project_name(self, filename):
+        return self.prj.project_name(filename)
+
+
+    def project_root(self, filename):
+        return self.prj.project_root(filename)
+
+
     def load(self, filename):
         return self.prj.load(filename)
 
     def __init__(self):
         self.executeable = sys.executable
         self.python_path = sys.path
-        self.version = sys.version
+        self.version = sys.version_info
+
+    def __repr__(self):
+        version = ".".join(map(str, tuple(self.version)))
+        return "<%s %s (%s)>" % (self.__class__.__name__, self.executeable, version)
 
 
 class VirtualEnvInterpreter(object):
         found = prj.discover(path)
         if not found:
             continue
-        name, settings_filename = found[0]
-        print "found", name, settings_filename
-        prefs = prj.load(settings_filename)
-        return prefs
+        for settings_filename in found:
+            print "found", settings_filename
+            return prj.settings(settings_filename)
 
 
 if __name__ == "__main__":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.