rope.base.resources =================== .. py:module:: rope.base.resources .. autoapi-nested-parse:: Files and folders in a project are represented as resource objects. Files and folders are access through `Resource` objects. `Resource` has two subclasses: `File` and `Folder`. What we care about is that refactorings and `rope.base.change.Change`s use resources. There are two options to create a `Resource` for a path in a project. Note that in these examples `path` is the path to a file or folder relative to the project's root. A project's root folder is represented by an empty string. 1) Use the `rope.base.Project.get_resource()` method. E.g.: myresource = myproject.get_resource(path) 2) Use the `rope.base.libutils` module. `libutils` has a function named `path_to_resource()`. It takes a project and a path: from rope.base import libutils myresource = libutils.path_to_resource(myproject, path) Once we have a `Resource`, we can retrieve information from it, like getting the path relative to the project's root (via `path`), reading from and writing to the resource, moving the resource, etc. Classes ------- .. autoapisummary:: rope.base.resources.Resource rope.base.resources.File rope.base.resources.Folder Module Contents --------------- .. py:class:: Resource(project, path) Bases: :py:obj:`os.PathLike` Represents files and folders in a project .. py:attribute:: project .. py:method:: move(new_location) Move resource to `new_location` .. py:method:: remove() Remove resource from the project .. py:method:: is_dir() Alias for `is_folder()` .. py:method:: is_folder() Return True if the resource is a Folder .. py:method:: create() Create this resource .. py:method:: exists() .. py:property:: parent .. py:property:: path :type: str Return the path of this resource relative to the project root The path is the list of parent directories separated by '/' followed by the resource name. .. py:property:: name :type: str Return the name of this resource .. py:property:: real_path :type: str .. py:property:: pathlib :type: pathlib.Path Return the file as a pathlib path. .. py:class:: File(project, name) Bases: :py:obj:`Resource` Represents a file .. py:attribute:: newlines :value: None .. py:method:: read() .. py:method:: read_bytes() .. py:method:: write(contents) .. py:method:: is_folder() Return True if the resource is a Folder .. py:method:: create() Create this resource .. py:attribute:: project .. py:method:: move(new_location) Move resource to `new_location` .. py:method:: remove() Remove resource from the project .. py:method:: is_dir() Alias for `is_folder()` .. py:method:: exists() .. py:property:: parent .. py:property:: path :type: str Return the path of this resource relative to the project root The path is the list of parent directories separated by '/' followed by the resource name. .. py:property:: name :type: str Return the name of this resource .. py:property:: real_path :type: str .. py:property:: pathlib :type: pathlib.Path Return the file as a pathlib path. .. py:class:: Folder(project, path) Bases: :py:obj:`Resource` Represents a folder .. py:method:: is_folder() Return True if the resource is a Folder .. py:method:: get_children() Return the children of this folder .. py:method:: create_file(file_name) .. py:method:: create_folder(folder_name) .. py:method:: get_child(name) .. py:method:: has_child(name) .. py:method:: get_files() .. py:method:: get_folders() .. py:method:: contains(resource) .. py:method:: create() Create this resource .. py:attribute:: project .. py:method:: move(new_location) Move resource to `new_location` .. py:method:: remove() Remove resource from the project .. py:method:: is_dir() Alias for `is_folder()` .. py:method:: exists() .. py:property:: parent .. py:property:: path :type: str Return the path of this resource relative to the project root The path is the list of parent directories separated by '/' followed by the resource name. .. py:property:: name :type: str Return the name of this resource .. py:property:: real_path :type: str .. py:property:: pathlib :type: pathlib.Path Return the file as a pathlib path.