py2puml icon indicating copy to clipboard operation
py2puml copied to clipboard

TypeError when trying to run on current directory

Open rianwouters opened this issue 3 years ago • 9 comments

I installed with python -m pip install py2puml

I run py2puml . . in a directory containing my python files.

I get the following error:

TypeError: the 'package' argument is required to perform a relative import for '..bk'

Tried many things but cannot get it to work.

rianwouters avatar Apr 14 '22 10:04 rianwouters

hi @rianwouters Thank you for giving py2puml a try :smiley:

Using py2puml with . . arguments is not supported for now. The command must be run from the root of the project's directory against a folder containing modules, be it the folder containing the production code. Having python modules directly at the root of the git directory is officially discouraged: it cannot be packaged to PyPI and most of the project management tools create a sub-directory for the production code (poetry, pipenv). See https://github.com/lucsorel/py2puml/issues/21#issuecomment-953281653

However, I plan to develop the possibility to call py2puml against a specific module but no deadline are set yet.

lucsorel avatar Apr 14 '22 12:04 lucsorel

Also looking forward to support for this. Thanks.

PanderMusubi avatar Aug 14 '22 15:08 PanderMusubi

I am working on another feature request right now (https://github.com/lucsorel/py2puml/issues/32), then I plan to work on this one by the end of the year.

I am sorry for the delay, I work on this library on my free time - any help is welcome 😃

lucsorel avatar Aug 23 '22 09:08 lucsorel

Any progress on this issue? I hope soon. 😊🙏

PanderMusubi avatar Nov 21 '22 10:11 PanderMusubi

unfortunately no; family issues are taking precedence over the priorities. I am sorry :/ but I am still aware of this use-case expected by several people.

The workaround for now is to structure your project as expected: with a root folder storing the code (see https://docs.python-guide.org/writing/structure/#sample-repository). I know you don't always have this freedom, but it helps separating production code, from automated tests code, from documentation and so on.

lucsorel avatar Nov 21 '22 11:11 lucsorel

Thanks for your reply and workaround. Take care and we'll commits later.

PanderMusubi avatar Nov 21 '22 11:11 PanderMusubi

I have been looking into this issue as part of a university assignment.

I believe that this issue is with the file inspectpackage.py when the call to walk_packages is made and the . for domain path and . for domain module is used. When called this program will try and walk before the root node.

I think that it is poor practice to have your class files at the root so the best solution to the problem that I have found is to just add an if statement to alert the user of the program that it is poor practice and abort the program.

This is my intended fix for this program

from importlib import import_module from pkgutil import walk_packages from types import ModuleType from typing import Dict, List

from py2puml.domain.umlitem import UmlItem from py2puml.domain.umlrelation import UmlRelation from py2puml.inspection.inspectmodule import inspect_module

def inspect_package( domain_path: str, domain_module: str, domain_items_by_fqn: Dict[str, UmlItem], domain_relations: List[UmlRelation] ): if (domain_path == "." and domain_module == "."): print('Cant start at the root directory') else: for _, name, is_pkg in walk_packages([domain_path], f'{domain_module}.'): if not is_pkg: domain_item_module: ModuleType = import_module(name) inspect_module( domain_item_module, domain_module, domain_items_by_fqn, domain_relations )

Cheers, Sharon

stvdb914 avatar May 21 '23 21:05 stvdb914

As there is no requirement whatsoever in Python to put modules in a subpackage I believe the solution proposed by @stvdb914 is insufficient.

There may be best practice but should the program not just work correctly for my one and only HelloWorld class in the root directory?

rianwouters avatar May 22 '23 09:05 rianwouters

thank you @stvdb914 and @rianwouters for exchanging views about this issue.

There may be best practice but should the program not just work correctly for my one and only HelloWorld class in the root directory?

I wrote this tool to document projects involving business domains made of several data structures scattered in different files. All these projects (the ones of my clients) have always been structured following the best practices (https://docs.python-guide.org/writing/structure/#sample-repository); therefore I prefer using the little free time I can spend on py2puml to add features that help documenting projects that do need this documentation rather than complying with hello-world projects. I don't mean to be condescendant (or not more than the "There may be best practice but should the program not just work correctly" :smiley:), bu I need to triage requests and prioritize issues.

I would like to handle this use-case one day.

lucsorel avatar May 22 '23 21:05 lucsorel