Convert uri to absolute filepath Parameters ---------- uri : string URI of python module to return path for Returns ------- path : None or string Returns None if there is no valid path for this URI Otherwise retur
(self, uri)
| 156 | 'get/set package_name') |
| 157 | |
| 158 | def _uri2path(self, uri): |
| 159 | ''' Convert uri to absolute filepath |
| 160 | |
| 161 | Parameters |
| 162 | ---------- |
| 163 | uri : string |
| 164 | URI of python module to return path for |
| 165 | |
| 166 | Returns |
| 167 | ------- |
| 168 | path : None or string |
| 169 | Returns None if there is no valid path for this URI |
| 170 | Otherwise returns absolute file system path for URI |
| 171 | |
| 172 | Examples |
| 173 | -------- |
| 174 | >>> docwriter = ApiDocWriter('sphinx') |
| 175 | >>> import sphinx |
| 176 | >>> modpath = sphinx.__path__[0] |
| 177 | >>> res = docwriter._uri2path('sphinx.builder') |
| 178 | >>> res == os.path.join(modpath, 'builder.py') |
| 179 | True |
| 180 | >>> res = docwriter._uri2path('sphinx') |
| 181 | >>> res == os.path.join(modpath, '__init__.py') |
| 182 | True |
| 183 | >>> docwriter._uri2path('sphinx.does_not_exist') |
| 184 | |
| 185 | ''' |
| 186 | if uri == self.package_name: |
| 187 | return os.path.join(self.root_path, '__init__.py') |
| 188 | path = uri.replace('.', os.path.sep) |
| 189 | path = path.replace(self.package_name + os.path.sep, '') |
| 190 | path = os.path.join(self.root_path, path) |
| 191 | # XXX maybe check for extensions as well? |
| 192 | if os.path.exists(path + '.py'): # file |
| 193 | path += '.py' |
| 194 | elif os.path.exists(os.path.join(path, '__init__.py')): |
| 195 | path = os.path.join(path, '__init__.py') |
| 196 | else: |
| 197 | return None |
| 198 | return path |
| 199 | |
| 200 | def _path2uri(self, dirpath): |
| 201 | ''' Convert directory path to uri ''' |
no outgoing calls
no test coverage detected