Commits

Ali Gholami Rudi  committed 9ef5738

Deprecated PyCore.create_module() and create_package()

  • Participants
  • Parent commits 60076fb

Comments (0)

Files changed (6)

File docs/dev/todo.txt

 * Split tuple assignment refactoring
 
 
-* Inlining a single occurrence
-
-
 * An option to decide whether to use froms or normal imports for back
   imports
 
 > Public Release 0.7.2
 
 
-* Performing refactorings across multiple projects
+* Inlining a single occurrence

File docs/done.txt

 ===========
 
 
+- Performing refactorings across multiple projects : November 29, 2007
+
+
 > Public Release 0.7.1 : November 28, 2007
 
 

File docs/library.txt

   >>> mod1 = project.root.create_file('mod1.py')
   >>> mod1.write('a_var = 10\n')
 
-  # Alternatively you can use `PyCore` objects.
-  # Creating modules and packages using `PyCore` objects
+  # Alternatively you can use `generate` module.
+  # Creating modules and packages using `generate` module
+  >>> from rope.contrib import generate
   >>> pycore = project.get_pycore()
-  >>> pkg = pycore.create_package(project.root, 'pkg')
-  >>> mod2 = pycore.create_module(pkg, 'mod2')
+  >>> pkg = generate.create_package(project, 'pkg')
+  >>> mod2 = generate.create_module(project, 'mod2', pkg)
   >>> mod2.write('import mod1\nprint mod1.a_var\n')
 
   # We can use `PyCore.find_module` for finding modules, too

File rope/base/pycore.py

 import bisect
 import difflib
 import sys
+import warnings
 
 import rope.base.oi.objectinfer
 import rope.base.oi.objectinfo
         for observer in self.cache_observers:
             observer(resource)
 
-    def create_module(self, src_folder, new_module):
-        """Creates a module and returns a `rope.project.File`"""
-        packages = new_module.split('.')
-        parent = src_folder
+    def create_module(self, sourcefolder, name, warn=True):
+        if warn:
+            warnings.warn('Use `rope.contrib.generate.create_module()`',
+                          DeprecationWarning, stacklevel=2)
+        packages = name.split('.')
+        parent = sourcefolder
         for package in packages[:-1]:
             parent = parent.get_child(package)
         return parent.create_file(packages[-1] + '.py')
 
-    def create_package(self, src_folder, new_package):
-        """Creates a package and returns a `rope.project.Folder`"""
-        packages = new_package.split('.')
-        parent = src_folder
+    def create_package(self, sourcefolder, name, warn=True):
+        if warn:
+            warnings.warn('Use `rope.contrib.generate.create_package()`',
+                          DeprecationWarning, stacklevel=2)
+        packages = name.split('.')
+        parent = sourcefolder
         for package in packages[:-1]:
             parent = parent.get_child(package)
         made_packages = parent.create_folder(packages[-1])

File rope/contrib/generate.py

     return generate(project, resource, offset)
 
 
+def create_module(project, name, sourcefolder=None):
+    """Creates a module and returns a `rope.base.resources.File`"""
+    if sourcefolder is None:
+        sourcefolder = project.root
+    return project.pycore.create_module(sourcefolder, name, warn=False)
+
+def create_package(project, name, sourcefolder=None):
+    """Creates a package and returns a `rope.base.resources.Folder`"""
+    if sourcefolder is None:
+        sourcefolder = project.root
+    return project.pycore.create_package(sourcefolder, name, warn=False)
+
+
 class _Generate(object):
 
     def __init__(self, project, resource, offset):

File ropetest/testutils.py

 import sys
 
 import rope.base.project
+from rope.contrib import generate
 
 
 def sample_project(root=None, foldername=None, **kwds):
     project = rope.base.project.Project(root, **prefs)
     return project
 
+create_module = generate.create_module
+create_package = generate.create_package
 
 def remove_project(project):
     project.close()