Closed INF800 closed 2 years ago
You are already close!
You need to specify the fully qualified name, so you need:
pyreverse -o png -c sklearn.linear_model._base.LinearRegression linear_model
That should create a sklearn.linear_model._base.LinearRegression.png
file.
Trying it!
Hey @DudeNr33, I doesn't seem to work :(
@INF800 ➜ /workspaces/scikit-learn (main ✗) $ pwd
/workspaces/scikit-learn
@INF800 ➜ /workspaces/scikit-learn (main ✗) $ ls
asv_benchmarks build_tools classes_SKLPNG.png CONTRIBUTING.md examples Makefile packages_SKLMMD.mmd README.rst setup.py
azure-pipelines.yml classes_SKLDOTC.dot CODE_OF_CONDUCT.md COPYING lgtm.yml MANIFEST.in packages_SKLPNG.png SECURITY.md sklearn
benchmarks classes_SKLMMD.mmd conftest.py doc maint_tools packages_SKLDOTC.dot pyproject.toml setup.cfg
@INF800 ➜ /workspaces/scikit-learn (main ✗) $ pyreverse -o png -c sklearn.linear_model._base.LinearRegression linear_model
Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
Traceback (most recent call last):
File "/home/codespace/.python/current/bin/pyreverse", line 8, in <module>
sys.exit(run_pyreverse())
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/__init__.py", line 44, in run_pyreverse
PyreverseRun(argv or sys.argv[1:])
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/main.py", line 213, in __init__
sys.exit(self.run(args))
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/main.py", line 221, in run
project = project_from_files(
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/inspector.py", line 313, in project_from_files
fpath = astroid.modutils.file_from_modpath(something.split("."))
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/modutils.py", line 300, in file_from_modpath
return file_info_from_modpath(modpath, path, context_file).location
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/modutils.py", line 350, in file_info_from_modpath
return _spec_from_modpath(modpath, path, context)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/modutils.py", line 569, in _spec_from_modpath
found_spec = spec.find_spec(modpath, path)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/interpreter/_import/spec.py", line 368, in find_spec
finder, spec = _find_spec_with_path(
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/interpreter/_import/spec.py", line 337, in _find_spec_with_path
raise ImportError(f"No module named {'.'.join(module_parts)}")
ImportError: No module named linear_model
You are not in the same directory as in your starting post. You need to cd into sklearn if you want to use the command as is.
When I run from inside directory, I get
@INF800 ➜ /workspaces/scikit-learn/sklearn (main ✗) $ pwd
/workspaces/scikit-learn/sklearn
@INF800 ➜ /workspaces/scikit-learn/sklearn (main ✗) $ ls
base.py _config.py dummy.py impute _loss naive_bayes.py random_projection.py
_build_utils conftest.py ensemble __init__.py manifold neighbors semi_supervised
calibration.py covariance exceptions.py inspection metrics neural_network setup.py
__check_build cross_decomposition experimental isotonic.py _min_dependencies.py packages_TMPC.png svm
classes_TMPC.png datasets externals _isotonic.pyx mixture packages_TMP.png tests
classes_TMP.png decomposition feature_extraction kernel_approximation.py model_selection pipeline.py tree
cluster discriminant_analysis.py feature_selection kernel_ridge.py multiclass.py preprocessing utils
compose _distributor_init.py gaussian_process linear_model multioutput.py __pycache__
@INF800 ➜ /workspaces/scikit-learn/sklearn (main ✗) $ pyreverse -o png -c sklearn.linear_model._base.LinearRegression linear_model
Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
parsing linear_model/__init__.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_logistic.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_coordinate_descent.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_perceptron.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_theil_sen.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_linear_loss.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_sag.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_ridge.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_omp.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_base.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_stochastic_gradient.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_passive_aggressive.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_huber.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/setup.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_quantile.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_bayes.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/__init__.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_ransac.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_least_angle.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_glm/glm.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_glm/__init__.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_glm/tests/test_glm.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/_glm/tests/__init__.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_perceptron.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_quantile.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_sparse_coordinate_descent.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_ridge.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_bayes.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_sgd.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_passive_aggressive.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_linear_loss.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_ransac.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_logistic.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_common.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_omp.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_base.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/__init__.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_theil_sen.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_least_angle.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_sag.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_coordinate_descent.py...
parsing /workspaces/scikit-learn/sklearn/linear_model/tests/test_huber.py...
Traceback (most recent call last):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/inference_tip.py", line 37, in _inference_tip_cached
result = _cache[func, node]
KeyError: (<function infer_numpy_ndarray at 0x7fee7be11a20>, <Attribute.ndarray l.5 at 0x7fed7e3265f0>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 35, in cached
return cache[func]
KeyError: <bound method ClassDef._get_assign_nodes of <ClassDef.ndarray l.2 at 0x7fed7e085a80>>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 35, in cached
return cache[func]
KeyError: <bound method MultiLineBlockMixin._get_assign_nodes of <FunctionDef.__init__ l.3 at 0x7fed7de03c70>>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 35, in cached
return cache[func]
KeyError: <bound method Assign._get_assign_nodes of <Assign l.6 at 0x7fed7de03880>>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/codespace/.python/current/bin/pyreverse", line 8, in <module>
sys.exit(run_pyreverse())
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/__init__.py", line 44, in run_pyreverse
PyreverseRun(argv or sys.argv[1:])
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/main.py", line 213, in __init__
sys.exit(self.run(args))
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/main.py", line 228, in run
diadefs = handler.get_diadefs(project, linker)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 217, in get_diadefs
diagrams.append(generator.class_diagram(project, klass))
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 188, in class_diagram
self.extract_classes(klass, anc_level, association_level)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 105, in extract_classes
self.extract_classes(ancestor, anc_level - 1, association_level)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 108, in extract_classes
self.extract_classes(node, anc_level, association_level - 1)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 108, in extract_classes
self.extract_classes(node, anc_level, association_level - 1)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 108, in extract_classes
self.extract_classes(node, anc_level, association_level - 1)
[Previous line repeated 931 more times]
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 102, in extract_classes
self.add_class(klass_node)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/diadefslib.py", line 72, in add_class
self.linker.visit(node)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/utils.py", line 202, in visit
methods[0](node)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/inspector.py", line 181, in visit_classdef
self.handle_assignattr_type(assignattr, node)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/inspector.py", line 243, in handle_assignattr_type
current | utils.infer_node(node)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/utils.py", line 259, in infer_node
ann = get_annotation(node)
File "/home/codespace/.python/current/lib/python3.10/site-packages/pylint/pyreverse/utils.py", line 237, in get_annotation
default, *_ = node.infer()
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 168, in infer
yield from self._infer(context=context, **kwargs)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
yield next(generator)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 105, in wrapped
for res in _func(node, context, **kwargs):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/bases.py", line 134, in _infer_stmts
for inf in stmt.infer(context=context):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 182, in infer
for i, result in enumerate(generator):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
yield next(generator)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 105, in wrapped
for res in _func(node, context, **kwargs):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/inference.py", line 236, in infer_call
for callee in self.func.infer(context):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 158, in infer
results = list(self._explicit_inference(self, context, **kwargs))
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/inference_tip.py", line 44, in _inference_tip_cached
result = _cache[func, node] = list(func(*args, **kwargs))
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/brain/brain_numpy_ndarray.py", line 147, in infer_numpy_ndarray
node = extract_node(ndarray)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/builder.py", line 423, in extract_node
tree = parse(code, module_name=module_name)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/builder.py", line 281, in parse
return builder.string_build(code, modname=module_name, path=path)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/builder.py", line 140, in string_build
return self._post_build(module, builder, "utf-8")
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/builder.py", line 156, in _post_build
self.delayed_assattr(delayed)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/builder.py", line 226, in delayed_assattr
for inferred in node.expr.infer():
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 168, in infer
yield from self._infer(context=context, **kwargs)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
yield next(generator)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 105, in wrapped
for res in _func(node, context, **kwargs):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/bases.py", line 134, in _infer_stmts
for inf in stmt.infer(context=context):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 182, in infer
for i, result in enumerate(generator):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
yield next(generator)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 105, in wrapped
for res in _func(node, context, **kwargs):
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/inference.py", line 954, in infer_assign
stmts = list(self.assigned_stmts(context=context))
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/protocols.py", line 334, in _arguments_infer_argname
functype = self.parent.type
File "/home/codespace/.python/current/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 1505, in type
for decorator in self.extra_decorators:
File "/home/codespace/.python/current/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 1468, in extra_decorators
for assign in frame._get_assign_nodes():
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 37, in cached
cache[func] = result = func(*args, **kwargs)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 3112, in _get_assign_nodes
return list(itertools.chain.from_iterable(children_assign_nodes))
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 3110, in <genexpr>
child_node._get_assign_nodes() for child_node in self.body
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 37, in cached
cache[func] = result = func(*args, **kwargs)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/mixins.py", line 156, in _get_assign_nodes
return list(itertools.chain.from_iterable(children_assign_nodes))
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/mixins.py", line 152, in <genexpr>
child_node._get_assign_nodes()
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 37, in cached
cache[func] = result = func(*args, **kwargs)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_classes.py", line 1205, in _get_assign_nodes
return [self] + list(self.value._get_assign_nodes())
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/decorators.py", line 31, in cached
cache = getattr(instance, "__cache", None)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/nodes/node_classes.py", line 1951, in __getattr__
return super().__getattr__(name)
File "/home/codespace/.python/current/lib/python3.10/site-packages/astroid/bases.py", line 111, in __getattr__
return getattr(self._proxied, name)
RecursionError: maximum recursion depth exceeded while calling a Python object
Am I doing something wrong here?
cc @DudeNr33 @Pierre-Sassoulas
This looks a lot like the bug reported in #3602.
You can limit the number of associated classes shown in the diagram to 1, by including -s1
in the command:
(tmp396) scikit-learn [main●] % pwd
/Users/andreas/programming/tmp/scikit-learn
(tmp396) scikit-learn [main●] % pyreverse -o png -s1 -c sklearn.linear_model._base.LinearRegression sklearn/linear_model
Wokring thanks!
Please keep the issue open. I am going to generate these diagrams for other classes too throughout the year
Glad it worked!
While I'm not against keeping this issue open per se, I'm curious what would be the benefit?
The general question (what is the necessary format for the class name in the -c
option) is answered, and for the RecursionError
we have the original ticket #3602.
Keep in mind that you can always revisit the ticket and the discussion even after it is closed (just search the closed tickets or make yourself a bookmark). And of course you are always welcome to open a new ticket if you stumble upon any new problems or have questions!
If we can close this it's one ticket less the maintainers have to revisit to check if there really is an open issue, i.e. bug or missing feature.
Makes sense! We can close the issue, if I get any new issue wrt sklearn, I will post here and we can re-open it.
Question
How to generate UML diagram using pyreverse for only
LinearRegression
class. The diagram must not include any other class likeHuberRegression
orLogisticRegression
.Documentation for future user
Probably in
pyreverse -h
Additional context
Currently I am doing:
To generate
But I need only the classes related to
sklearn.linear_model.LinearRegression
present in the diagram. For that I am using:which results in error:
I also tried
which causes
I even tried
which causes