Make sure the provided value for --single is a path to an existing .rst/.ipynb file, or a pandas object that can be imported. For example, categorial.rst or pandas.DataFrame.head. For the latter, return the corresponding file path (e.g. reference/api/pandas.
(self, single_doc)
| 70 | self.single_doc_html = f"reference/api/pandas.{single_doc}.html" |
| 71 | |
| 72 | def _process_single_doc(self, single_doc): |
| 73 | """ |
| 74 | Make sure the provided value for --single is a path to an existing |
| 75 | .rst/.ipynb file, or a pandas object that can be imported. |
| 76 | |
| 77 | For example, categorial.rst or pandas.DataFrame.head. For the latter, |
| 78 | return the corresponding file path |
| 79 | (e.g. reference/api/pandas.DataFrame.head.rst). |
| 80 | """ |
| 81 | base_name, extension = os.path.splitext(single_doc) |
| 82 | if extension in (".rst", ".ipynb"): |
| 83 | if os.path.exists(os.path.join(SOURCE_PATH, single_doc)): |
| 84 | return single_doc |
| 85 | else: |
| 86 | raise FileNotFoundError(f"File {single_doc} not found") |
| 87 | |
| 88 | elif single_doc.startswith("pandas."): |
| 89 | try: |
| 90 | obj = pandas # noqa: F821 |
| 91 | for name in single_doc.split("."): |
| 92 | obj = getattr(obj, name) |
| 93 | except AttributeError as err: |
| 94 | raise ImportError(f"Could not import {single_doc}") from err |
| 95 | else: |
| 96 | return single_doc[len("pandas.") :] |
| 97 | else: |
| 98 | raise ValueError( |
| 99 | f"--single={single_doc} not understood. " |
| 100 | "Value should be a valid path to a .rst or .ipynb file, " |
| 101 | "or a valid pandas object " |
| 102 | "(e.g. categorical.rst or pandas.DataFrame.head)" |
| 103 | ) |
| 104 | |
| 105 | @staticmethod |
| 106 | def _run_os(*args) -> None: |
no test coverage detected