Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when trying to run on current directory #29

Open
rianwouters opened this issue Apr 14, 2022 · 9 comments
Open

TypeError when trying to run on current directory #29

rianwouters opened this issue Apr 14, 2022 · 9 comments

Comments

@rianwouters
Copy link

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.

@lucsorel
Copy link
Owner

lucsorel commented Apr 14, 2022

hi @rianwouters
Thank you for giving py2puml a try 😃

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 #21 (comment)

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

@PanderMusubi
Copy link

Also looking forward to support for this. Thanks.

@lucsorel
Copy link
Owner

lucsorel commented Aug 23, 2022

I am working on another feature request right now (#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 😃

@PanderMusubi
Copy link

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

@lucsorel
Copy link
Owner

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.

@PanderMusubi
Copy link

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

@stvdb914
Copy link

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

@rianwouters
Copy link
Author

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?

@lucsorel
Copy link
Owner

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" 😃), bu I need to triage requests and prioritize issues.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants