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