-
Notifications
You must be signed in to change notification settings - Fork 36
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
feature: Add simple CLI #9
Conversation
With this, one can preview a UML diagram quickly:
|
hi @jjerphan, Excellent idea, thanks! I have some minor remarks and requirements (unit-testing, mainly) that I would like to address. I haven't proposed some contribution guidelines yet in this project (I didn't expect them:) but I am glad it becomes necessary to provide some conventions. I hope to get back to you this weekend. PS: we can keep on discussing in English (for other potential readers) or in French (for convenience), as you like 😃 |
Hi @lucsorel Thanks for your message.
I do agree. Let me know about the way you want it to be tested as there generally are several practices (for instance here are some good ones IMO).
I would suggest keeping our 🥖-ness aside for public discussions, and thus use English to be more inclusive. |
Forgive me for my lack of reactivity, weeks with very little spare time for this library. A few suggestions:
Le me know if you would like some help about the unit tests or other things. I hope I don't ask too much. |
Hi @lucsorel
It's fine. Please, don't feel in a hurry to respond. 🙂 I'll have a look at your suggestions. Being done with this PR, I'd be interested to work on #3 and/or #7 (which are closely related) as I think that this would push the project forward: I think this project have the potential to help document a lot of python libraries! |
As for your suggestion:
I'll add a section for it. With what I've done there. If
|
I just have added a simple test for consistency and will add some more. |
thank you for all the changes, I have just pushed some minor adjustments regarding the project version and CLI documentation: 37fb60a. I am working on how to make the CLI work with the python -m py2puml.cli way too, so that the unit test can pass without the package being installed at the system level (although it is the way to install a CLI command). If you have an idea of how to make this work, feel free to let me know. |
I modified the CLI script so that it can launched as python module as well. Can you tell me what you think about the 3 previous commits, please? Moreover, I was wrong about the Feel free to add some unit tests about the |
py2puml/cli.py
Outdated
# CLI end-point when py2puml is NOT installed at the system level | ||
if __name__ == '__main__': | ||
if len(argv) == 2 and argv[1] in ['-v', '--version']: | ||
print(f'{__description__} ({CLI_VERSION})') | ||
elif len(argv) == 3: | ||
print(''.join(py2puml(argv[1], argv[2]))) | ||
else: | ||
raise ValueError(f''' | ||
The CLI can be called in 2 ways: | ||
- version: python -m py2puml.cli -v or python -m py2puml.cli --version | ||
- plantuml documentation (2 mandatory arguments): `python py2puml.cli domain/path domain.module`: {PATH_ARG_HELP}, {MODULE_ARG_HELP} | ||
''') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me this is kind of convoluted and argparse
usually takes care of CLI mis-usage, be it installed on the system or not. 🙂
It might be possible to make the CLI accessible with a similar and conciser syntax, for instance :
$ python -m py2puml
by modifying py2pulm.__init__
to include:
from py2puml.cli import run
if __name__ == "__main__":
run()
This is to test though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I didn't feel right implementing the CLI twice with sys.argv
. Can you try modifying py2pulm.__init__
as you suggest and remove the convoluted code, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it.
Thanks for your useful additions! I left a few comments.
Yes, this is another (indirect) avantage of poetry, but we need to also have the test you just added. 🙂
Yes, I guess we could parametrised tests with both command/ entrypoints for conciseness and extendibility. |
thank you for the parametrized test, it is an interesting feature of pytest that I never used before 😃 I did some minor refactoring (dedicated test files for If you are ok with the state of this PR, I am ready to squash and merge it & update the version in PyPI. What do you think? Would you prefer adding some CLI unit tests about incomplete commands and the |
in the previous commit, I wanted to add in the README.md file the use case you suggested at the beginning of this PR (piping the puml model to a PlantUML server to generate/display an image) but I did not succeed in making it work 😞 Do you know how to fix the curl command? |
Yes, it looks like a good first version for the CLI.
I am not too concerned about the |
I agree about not testing the help and verbose commands. What about the documentation about piping the CLI output to a PlantUML server? |
You are faster than I am to reply 😁
In my case, I could previously use PlantUML's demo server with: $ py2puml py2pulm py2pulm | curl -X POST --data-binary @- http://www.plantuml.com/plantuml/svg/ --output - | display But with the latest changes for the setup with the toml file, I get errors which aren't related to requesting the server, e.g: $ py2puml py2puml py2puml
Traceback (most recent call last):
File "/home/jjerphan/.virtualenvs/py2puml/bin/py2puml", line 5, in <module>
from py2puml.cli import run
File "/home/jjerphan/.virtualenvs/py2puml/lib64/python3.9/site-packages/py2puml/__init__.py", line 21, in <module>
with open(join(PARENT_DIR, 'pyproject.toml')) as pyproject:
FileNotFoundError: [Errno 2] No such file or directory: '/home/jjerphan/.virtualenvs/py2puml/lib/python3.9/site-packages/pyproject.toml' We might want to adjust the setup to include |
It may be a typo while you copy-pasted the command (py2pu poetry run py2puml py2puml/domain py2puml.domain | curl -X POST --data-binary @- http://www.plantuml.com/plantuml/svg/ --output - | display
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 896 0 0 100 896 0 2185 --:--:-- --:--:-- --:--:-- 2185
display-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560. It looks like my linux distribution is missing come codec (searching the error message leads me to some issues with ImageMagick) 🤷 The following command yields an empty svg file: poetry run py2puml py2puml/domain py2puml.domain | curl -X POST --data-binary @- http://www.plantuml.com/plantuml/svg/ --output stuff.svg |
Try removing parts of the command just after the first pipe. |
|
I had the same error message but this was due to this latter error rather than the rendering with PlantUML's server. |
ok, thank you @jjerphan. So just to make sure: what do we need to do to finish this pull request, so that we can embark your contribution?
What do you think? |
Hum, it does seems that easy to embed the Other projects include the version number in the source code directly and get the metadata published on PyPi using I do understand that use a single source of truth (like |
@jjerphan I have just pushed a commit which:
What do you think? Does this commit fix the poetry run python -m py2puml py2puml/domain py2puml.domain | curl -X POST --data-binary @- https://www.plantuml.com/plantuml/png/ --output - | display
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 896 0 0 100 896 0 1315 --:--:-- --:--:-- --:--:-- 1315
display-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560. |
It runs (and has been) running with poetry and a PlantUML with a local host. I.e, The following commands work: poetry run python -m py2puml py2puml/domain py2puml.domain # Priorly ran to setup a local PlantUML server:
# docker run -d -p 8080:8080 plantuml/plantuml-server:jetty
poetry run python -m py2puml py2puml/domain py2puml.domain | curl -X POST --data-binary @- http://localhost:8080/svg/ --output - | display the following ones do not: poetry run python -m py2puml py2puml/domain py2puml.domain | curl -X POST --data-binary @- https://www.plantuml.com/plantuml/png/ --output - | display It looks like the global PlantUML instance does not support direct API calls (I naively though it would, but it doesn't, which is understandable). Personally, I would like the CLI to be working without using |
Yes, let's add a few notes for this.
This won't solve the problem, I think. The problem is linked to the way Though I am not a maintainer, a CI might be interesting to test various configuration for the project generally and could be introduced in another PR. 🙂 |
hi @jjerphan The last 2 commits:
If you are ok with the state of this PR, I am ready to merge it and publish the new version in PyPI 😃 |
Forgive me, I did not reply to this good suggestion, but I approve it. Launching unit tests with github actions would be a first step |
Hi @lucsorel I got busy those last days, thanks a lot for inspecting and fixing this for me: it works on my end!
It's completely fine. I might not have time in the coming days to work on it, so please feel free to do if you want to. |
your contribution is alive in https://pypi.org/project/py2puml/. Thank you so much for your contribution, dedication and patience 🙏 |
Hello there.
This is a simple proposition of a CLI, which makes this project even more usable.
For instance: