PyBites-Open-Source / pybites-carbon

MIT License
87 stars 11 forks source link

Less code by using more feature of argparse #1

Closed GreatBahram closed 3 years ago

GreatBahram commented 3 years ago

HI @bbelderbos,

I added ArgumentDefaultsHelpFormatter as it helps to see the default values. Also, I saved the output of different ways you get the code (env, clipboard, file) into one attribute (code) and move the code inside get_code into argparse' type keyword, which allows execution of a custom function.

I also changed this line: CHROMEDRIVER_PATH = os.environ.get("CHROMEDRIVER_PATH", "") Because for someone like me who does not have the chrome driver, it throws an exception, probably it is a good idea to handle these edges and print a user-friendly error message. Maybe it is a good idea to move the code inside the __main__ module to cli, I mean the main function because I think cli should be the main command-line endpoint and __main__ should call the cli.main function, not vice versa (but maybe it is just matter of taste).

Thanks for your wonderful project

bbelderbos commented 3 years ago

Nice @GreatBahram looks great, thanks a lot, I appreciate you jumping in making it better.

Feel free to add the user-friendly message if CHROMEDRIVER_PATH is not set.

Also could you check the tests? Seems they break because you now need to do create_code_image(ONE_LINE_SNIPPET, **options) where options is:

options = {
    "language": "python",
    "background": "#ABB8C3",
    "theme": "seti",
}

Before defaults were set in this function. With the move of defaults to argparse the tests break, but it's probably an easy fix by passing these kwargs in for each instance of create_code_image in the tests.

Thanks Bob

bbelderbos commented 3 years ago

Fixed tests. Another issue I hit:

$ make typing
mypy carbon tests
carbon/carbon.py:24: error: Argument 1 to "quote_plus" has incompatible type "Optional[str]"; expected "str"
carbon/carbon.py:26: error: Argument 1 to "quote_plus" has incompatible type "Optional[str]"; expected "str"
carbon/carbon.py:27: error: Argument 1 to "quote_plus" has incompatible type "Optional[str]"; expected "str"
Found 3 errors in 1 file (checked 6 source files)

So I made the options passed in required: https://github.com/PyBites-Open-Source/pybites-carbon/commit/f6f8d831722de5937a41142ec36f679748021269

bbelderbos commented 3 years ago

@GreatBahram Github Actions works now as well: https://github.com/PyBites-Open-Source/pybites-carbon/actions

GreatBahram commented 3 years ago

Sounds great, Bob! I really enjoyed that you used Tesseract to read characters from the generated images; that was a brilliant idea!

bbelderbos commented 3 years ago

Thanks, it doesn't work perfectly but enough to prove that the image with code was created! I love finding creative ways to increase test coverage :)