shidarin / cdl_convert

Converts between common ASC Color Decision List (CDL) formats
Other
59 stars 17 forks source link

Requiring user input after an exception in cdl_convert.py can break automation tools #40

Closed gregcotten closed 9 years ago

gregcotten commented 9 years ago

https://github.com/shidarin/cdl_convert/blob/857313041448061fc6b92e602169423e90cf590a/cdl_convert/cdl_convert.py#L291

Not sure how I just found this but it's hard to have an automation tool that is running cdl_convert press enter for itself if cdl_convert errors out!

shidarin commented 9 years ago

Absolutely correct. Will remove enter stop.

gregcotten commented 9 years ago

Might I also suggest doing:

def printError(*objs):
    import sys
    print(*objs, file=sys.stderr)

if __name__ == '__main__':  # pragma: no cover
    try:
        main()
    except Exception as err:  # pylint: disable=W0703
        import traceback
        printError('Unexpected error encountered:')
        printError(err)
        printError(traceback.format_exc())
        exit(1)

This will correctly print the error to stderr and do an "exit with error".

shidarin commented 9 years ago

Actually, it's not even possible to run cdl_convert/cdl_convert.py directly because of the relative imports.

We need a stub file which will do a straight import cdl_convert then run main. I've created said file (./cdl_convert.py, which has fromcdl_convert.cdl_convert import main), so it's possible to run cdl_convert without installing. It then uses your suggested code to print the errors to stderror, and raise an exit status of 1, so thank you.

Right now, the recommended approach is to install cdl_convert via setuptools or pip, which will create that stub file automatically since it has the following lines in setup.py:

    # To provide executable scripts, use entry points in preference to the
    # "scripts" keyword. Entry points provide cross-platform support and allow
    # pip to create the appropriate form of executable for the target platform.
    entry_points={
        'console_scripts': [
            'cdl_convert=cdl_convert.cdl_convert:main',
        ],
    },
gregcotten commented 9 years ago

I normally just cd to the folder above the cdl_convert directory then:

python -m cdl_convert.cdl_convert [args]