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

Incompatibility with windows: module 'os' has no attribute 'EX_NOINPUT' #48

Closed
stefanjcollier opened this issue Dec 14, 2017 · 6 comments · Fixed by #55
Closed

Incompatibility with windows: module 'os' has no attribute 'EX_NOINPUT' #48

stefanjcollier opened this issue Dec 14, 2017 · 6 comments · Fixed by #55

Comments

@stefanjcollier
Copy link

stefanjcollier commented Dec 14, 2017

Hi there,
I'm trying to run this on windows and get this error on the commands:
vladiate
vladiate vlads
vladiate mymain.py

C:path\to\project> vladiate
Could not find any vladfile! Ensure file ends in '.py' and see --help for available options.
Traceback (most recent call last):
  File "c:\users\scollier\appdata\local\programs\python\python36-32\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\scollier\appdata\local\programs\python\python36-32\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\scollier\Envs\virtualenv\Scripts\vladiate.exe\__main__.py", line 9, in <module>
  File "c:\users\scollier\envs\virtualenv\lib\site-packages\vladiate\main.py", line 173, in main
    return os.EX_NOINPUT
AttributeError: module 'os' has no attribute 'EX_NOINPUT'

This seems to all stem from: https://github.com/di/vladiate/blob/master/vladiate/main.py:main()
All the os.EX_* values are UNIX only.

def main():
    arguments = parse_args()
    logger = logs.logger

    if arguments.show_version:
        print("Vladiate %s" % (get_distribution('vladiate').version, ))
        return os.EX_OK

    vladfile = find_vladfile(arguments.vladfile)
    if not vladfile:
        logger.error(
            "Could not find any vladfile! Ensure file ends in '.py' and see "
            "--help for available options."
        )
        return os.EX_NOINPUT

    docstring, vlads = load_vladfile(vladfile)

    if arguments.list_commands:
        logger.info("Available vlads:")
        for name in vlads:
            logger.info("    " + name)
        return os.EX_OK

    if not vlads:
        logger.error("No vlad class found!")
        return os.EX_NOINPUT

    # make sure specified vlad exists
    if arguments.vlads:
        missing = set(arguments.vlads) - set(vlads.keys())
        if missing:
            logger.error("Unknown vlad(s): %s\n" % (", ".join(missing)))
            return os.EX_UNAVAILABLE
        else:
            names = set(arguments.vlads) & set(vlads.keys())
            vlad_classes = [vlads[n] for n in names]
    else:
        vlad_classes = vlads.values()

    # validate all the vlads, and collect the validations for a good exit
    # return code
    if arguments.processes == 1:
        for vlad in vlad_classes:
            vlad(source=vlad.source).validate()

    else:
        proc_pool = Pool(
            arguments.processes
            if arguments.processes <= len(vlad_classes)
            else len(vlad_classes)
        )
        proc_pool.map(_vladiate, vlad_classes)
        try:
            if not result_queue.get_nowait():
                return os.EX_DATAERR
        except Empty:
            pass
        return os.EX_OK

Would you be able to change this to a more windows-friendly return value?

@di
Copy link
Owner

di commented Dec 14, 2017

Thanks for the report @stefanjcollier!

I'm not very familiar with Windows -- do you happen to know what would be the 'right' values to return here on that platform? Does Windows even have a notion of exit codes?

@stefanjcollier
Copy link
Author

I'm honestly not sure myself, however I'm just about to do a PR that will mimic the UNIX ones (but not use the missing attributes). If a wiser person comes along they can point it out. 😄

@di
Copy link
Owner

di commented Dec 14, 2017

Yup, I think it'd be totally fine to define some constants like:

EX_OK = 0
EX_DATAERR = 65
EX_NOINPUT = 66
EX_UNAVAILABLE = 69

And use those instead. Thanks!

@stefanjcollier
Copy link
Author

I thought it would be best to keep the os.EX_* attributes. Just in case they are different for non obvious systems like Red Hat or other UNIX distros.

@stefanjcollier
Copy link
Author

Check it out for yourself:
#49

di pushed a commit that referenced this issue Feb 23, 2018
@di di closed this as completed in #55 Feb 23, 2018
di added a commit that referenced this issue Feb 23, 2018
* Allow windows exit codes. Fixes #48

* Fixes tests for fix #49

* change final os.EX_OK

* Simplify exit codes

* Correct exit codes when vladiate fails

* Move tests

* Don't lint ./dist
@di
Copy link
Owner

di commented Feb 23, 2018

This is fixed in v 0.0.20.

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

Successfully merging a pull request may close this issue.

2 participants