def __init__(self, func_name: str, doc_obj=None) -> None: self.func_name = func_name if doc_obj is None: doc_obj = get_doc_object(Validator._load_obj(func_name)) super().__init__(doc_obj)
def pandas_validate(func_name: str): """ Call the numpydoc validation, and add the errors specific to pandas. Parameters ---------- func_name : str Name of the object of the docstring to validate. Returns ------- dict Information about the docstring and the errors found. """ func_obj = Validator._load_obj(func_name) doc_obj = get_doc_object(func_obj) doc = PandasDocstring(func_name, doc_obj) result = validate(doc_obj) mentioned_errs = doc.mentioned_private_classes if mentioned_errs: result["errors"].append( pandas_error("GL04", mentioned_private_classes=", ".join(mentioned_errs))) if doc.see_also: for rel_name in doc.see_also: if rel_name.startswith("pandas."): result["errors"].append( pandas_error( "SA05", reference_name=rel_name, right_reference=rel_name[len("pandas."):], )) result["examples_errs"] = "" if doc.examples: result["examples_errs"] = doc.examples_errors if result["examples_errs"]: result["errors"].append( pandas_error("EX02", doctest_log=result["examples_errs"])) for error_code, error_message, error_count in doc.validate_pep8(): times_happening = f" ({error_count} times)" if error_count > 1 else "" result["errors"].append( pandas_error( "EX03", error_code=error_code, error_message=error_message, times_happening=times_happening, )) examples_source_code = "".join(doc.examples_source_code) for wrong_import in ("numpy", "pandas"): if f"import {wrong_import}" in examples_source_code: result["errors"].append( pandas_error("EX04", imported_library=wrong_import)) if doc.non_hyphenated_array_like(): result["errors"].append(pandas_error("GL05")) plt.close("all") return result
def spectrochempy_validate(func_name, exclude=[]): """ Call the numpydoc validation, and add the errors specific to spectrochempy. Parameters ---------- func_name : str Name of the object of the docstring to validate. exclude : list List of error code to exclude, e.g. ["SA01", ...]. Returns ------- dict Information about the docstring and the errors found. """ func_obj = Validator._load_obj(func_name) doc_obj = get_doc_object(func_obj) doc = SpectroChemPyDocstring(func_name, doc_obj) result = validate(doc_obj) errs = result["errors"] mentioned_errs = doc.mentioned_private_classes if mentioned_errs: errs.append( spectrochempy_error( "GL04", mentioned_private_classes=", ".join(mentioned_errs))) has_kwargs = doc.has_kwargs if has_kwargs: errs = remove_errors(errs, "PR02") if not doc.doc_other_parameters: errs.append(spectrochempy_error("GL11")) if exclude: errs = remove_errors(errs, exclude) if doc.see_also: for rel_name in doc.see_also: if rel_name.startswith("spectrochempy."): errs.append( spectrochempy_error( "SA05", reference_name=rel_name, right_reference=rel_name[len("spectrochempy."):], )) result["examples_errs"] = "" if doc.examples: result["examples_errs"] = doc.examples_errors if result["examples_errs"]: errs.append( spectrochempy_error("EX02", doctest_log=result["examples_errs"])) for error_code, error_message, error_count in doc.validate_pep8(): times_happening = f" ({error_count} times)" if error_count > 1 else "" errs.append( spectrochempy_error( "EX03", error_code=error_code, error_message=error_message, times_happening=times_happening, )) examples_source_code = "".join(doc.examples_source_code) for wrong_import in ("numpy", "spectrochempy"): if f"import {wrong_import}" in examples_source_code: errs.append( spectrochempy_error("EX04", imported_library=wrong_import)) if doc.non_hyphenated_array_like(): errs.append(spectrochempy_error("GL05")) # cases where docrep dedent was used if error("GL01") in errs and not doc.raw_doc.startswith(""): errs = remove_errors(errs, "GL01") if error("GL02") in errs and not doc.raw_doc.startswith(""): errs = remove_errors(errs, "GL02") # case of properties (we accept a single line summary) if hasattr(doc.code_obj, "fget"): errs = remove_errors(errs, "ES01") result["errors"] = errs plt.close("all") if result["file"] is None: # sometimes it is because the code_obj is a property if hasattr(doc.code_obj, "fget"): try: result["file"] = inspect.getsourcefile(doc.code_obj.fget) result["file_line"] = inspect.getsourcelines( doc.code_obj.fget)[-1] except (OSError, TypeError): pass return result