pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Pyreverse: working without without __init__.py files

Open azzamsa opened this issue 6 years ago • 11 comments

This ability already requested in https://github.com/PyCQA/pylint/issues/842, But I think it's only for Pylint, not Pyreverse.

With PEP 420 -- Implicit Namespace Packages I can work seamlessly without ever needed the __init__.py files. But when it comes to generating class diagram with Pyreverse, I have to add them unless it didn't work

My current dirty-solution is to add __init__.py to all my project folder temporarily, then stash them back and forth. Indeed it's not convenience experience.

Hope Pyreverse will work without __init__.py

Step to reproduce

With this directory structure

Myproject.py
├── Controllers
├── Model
├── Resources
│   ├── img
│   └── ui
└── Views

and $ pyreverse -my -A -o png -p myprojectname .

Thank you for Pyreverse.

azzamsa avatar Feb 22 '19 12:02 azzamsa

Sounds like a good suggestion, thanks for reporting it!

PCManticore avatar Feb 22 '19 16:02 PCManticore

We give a lot of hope to Pyreverse. Hope I can contribute back.

I don't know why in such tremendous amount of library in Python ecosystem, where choosing between them is so confusing. We have one and the only UML generating library that works. Other lib last release is years years ago.

azzamsa avatar Feb 23 '19 00:02 azzamsa

Thanks for the kind words @azzamsa If you want to open a PR, I'd be happy to review or offer suggestions.

PCManticore avatar Feb 27 '19 08:02 PCManticore

Is anyone still looking into this? Haven't spend much time on it yet but explicit namespacing seems to be enforced in the function defined here

https://github.com/PyCQA/pylint/blob/30b2ae713eb4453b305407772b29ea68d7c3d074/pylint/pyreverse/inspector.py#L332

More specifically in line:

https://github.com/PyCQA/pylint/blob/30b2ae713eb4453b305407772b29ea68d7c3d074/pylint/pyreverse/inspector.py#L354

Do you agree? I might be interested to pick up this issue

ThomasHagebols avatar Mar 13 '20 21:03 ThomasHagebols

Hello, is this still open ? Since it was referenced in commits ? But it doesn't seem to work :confused:

RobinLanglois avatar Nov 19 '21 13:11 RobinLanglois

The commit are from the pybuilder repository not pylint, no one worked on it yet :)

Pierre-Sassoulas avatar Nov 19 '21 14:11 Pierre-Sassoulas

Yah line 343 seems to be making the hard association to package folders being defined by the presence of __init__.py

https://github.com/PyCQA/pylint/blob/30b2ae713eb4453b305407772b29ea68d7c3d074/pylint/pyreverse/inspector.py#L340-L345

I wonder how things would work if that condition is simply removed. How's the testing on this project, I'm curious to tinker around with things with a simple deletion and running of unit tests and see how things go.

jxramos avatar Jun 02 '22 02:06 jxramos

Should this issue have the namespace-package label applied?

To help others with @azzamsa current dirty solution they can run find foo/bar -type d -exec touch {}/__init__.py \; to get going quickly if they are on a nix system.

jxramos avatar Jun 02 '22 05:06 jxramos

I'm curious to tinker around with things with a simple deletion and running of unit tests and see how things go.

You can check the contributor guide, please let us know if it's not clear. We did not invest a lot of time in it right now as we focussed on the user documentation for 2.14.

Pierre-Sassoulas avatar Jun 02 '22 10:06 Pierre-Sassoulas

How's the testing on this project, I'm curious to tinker around with things with a simple deletion and running of unit tests and see how things go.

You can find the existing tests under tests/pyreverse. A lot of the test data that is used there for all tests except test_pyreverse_functional.py is found under tests/data. As test_writer.py generates all possible diagrams with different output formats from this test data, you should be aware that adding e. g. a new subpackage without __init__.py there would mean that you have to update the expected output for the other tests as well. So for this feature I would probably go for creating a simple package structure dynamically in the test by using the tmpdir fixture.

Tests are run with pytest. After forking and cloning the repository you should run pip install -r requirements_test.txt to install all necessary dependencies. See also our documentation for more details.

Let me know if you need help!

DudeNr33 avatar Jun 02 '22 19:06 DudeNr33

Could someone confirm if #7153 fixes this issue for them?

astronasko avatar Mar 21 '24 15:03 astronasko