Commits

Henning Schröder committed 0190625 Merge

merge

Comments (0)

Files changed (2)

      * offer to add import-statement if name is found in module database
      * offer to add function if name is called (method if dotted-name)
      * offer to add variable if name is not called (attribute if dotted-name)
+     * offer rename if similar name is found (fuzzy string compare)
    * formatting
      * autopep8
+     * strip lines with spaces if not inside expression
+     * remove empty lines at bottom of file
    * Python 2/3 syntax differences: 2to3
    * tabs to spaces
    * spelling corrections
    * close parentheses/brackets/braces
    * space after comma
    * after "from FOO " append "import "
+   * add args after a star in function header, add kwargs after two stars
    * add documentation stub based on signature
+ * more smart editing
+   * regular expressions in code should be highlighted and validated
+   * spell check comments and strings
  * correctly load/save source files according to encoding hint at the header
  * project settings
    * source root folder

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__":