Atom-beautify: autopep8 not found, but it is in the PATH

Created on 24 Jun 2016  路  14Comments  路  Source: Glavin001/atom-beautify

Description

I am using anaconda on a windows terminal server as python distribution. autopep8 is installed and is in the path (where.exe finds it and i can run autopep8.exe from the command prompt).

However, atom-beautify does not find it.

Only after changing the autopep8.coffee script to include the full path to autpep8 beautifier works.

bug published waiting-for-user-information

All 14 comments

Maybe we should look for an "autopep8", but open "python -m autopep8" or "python3 -m autopep8"?

Please follow the issue template provided. More specifically, adding a link to the required debug.md Gist which includes debugging information that answers our most commonly asked questions.
Thank you.

Description

Beautification with autopep8 fails even though autopep8 is installed and working properly.

Input Before Beautification

This is what the code looked like before:

"""
Reference: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.ks_2samp.html
"""
from scipy import stats
import numpy as np


def main():
    np.random.seed(   12345678  )
    n1 = 200
    n2 = 300

    # Generate random variates from a normal distribution
    rvs1 = stats.norm.rvs(loc=0, scale=1, size=n1)
    rvs2 = stats.norm.rvs(loc=0.5, scale=1.5, size=n2)

    print(stats.ks_2samp(rvs1, rvs2))

if __name__ == '__main__':
    main()

Expected Output

The beautified code should have looked like this:

"""
Reference: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.ks_2samp.html
"""
from scipy import stats
import numpy as np


def main():
    np.random.seed(12345678)
    n1 = 200
    n2 = 300

    # Generate random variates from a normal distribution
    rvs1 = stats.norm.rvs(loc=0, scale=1, size=n1)
    rvs2 = stats.norm.rvs(loc=0.5, scale=1.5, size=n2)

    print(stats.ks_2samp(rvs1, rvs2))

if __name__ == '__main__':
    main()

Actual Output

Beautification fails with error message:

Could not find 'autopep8'. The program may not be installed.
See https://github.com/hhatto/autopep8#installation for program installation instructions.
You can configure Atom Beautify with the absolute path to 'autopep8' by setting 'Executable - autopep8 - Path' in the Atom Beautify package settings.
Your program is properly installed if running 'which autopep8' in your Terminal returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable.
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=autopep8&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.

For reference:

$ which autopep8
/home/mcf/anaconda3/bin/autopep8

and

$ autopep8 --in-place example.py

where example.py is the trivial example in "Input Before Beautification" produces the output in "Expected Output"

Steps to Reproduce

  1. Add code to Atom editor
  2. Run command Atom Beautify: Beautify Editor
  3. This beautified code does not look right!

Debug

Here is a link to the debug.md Gist: https://gist.github.com/matthewfeickert/44199a1c4c09cfbb72c75205ca0ff2dd

Checklist

I have:

  • [x] Tried uninstalling and reinstalling Atom Beautify to ensure it installed properly
  • [x] Reloaded (or restarted) Atom to ensure it is not a caching issue
  • [x] Searched through existing Atom Beautify Issues at https://github.com/Glavin001/atom-beautify/issues
    so I know this is not a duplicate issue
  • [x] Filled out the Input, Expected, and Actual sections above or have edited/removed them in a way that fully describes the issue.
  • [x] Generated debugging information by executing Atom Beautify: Help Debug Editor command in Atom and added link for debug.md Gist to this issue

Hi @matthewfeickert. I have found what I think is the bug from your logs:

2017-06-18T14:06:56.661Z - debug: [] spawn done 0  autopep8 1.3.2 (pycodestyle: 2.3.1)

2017-06-18T14:06:56.661Z - verbose: [] spawn result, returnCode 0
2017-06-18T14:06:56.661Z - verbose: [] spawn result, stdout autopep8 1.3.2 (pycodestyle: 2.3.1)

2017-06-18T14:06:56.661Z - verbose: [] spawn result, stderr
2017-06-18T14:06:56.661Z - error: []  TypeError: Cannot read property '1' of null
    at HybridExecutable.parse [as versionParse] (/home/mcf/.atom/packages/atom-beautify/src/beautifiers/autopep8.coffee:19:65)
    at /home/mcf/.atom/packages/atom-beautify/src/beautifiers/executable.coffee:92:18

Basically when autopep8 --version is run and the version is attempted to be parsed.
However, I look at the version parsing (https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/autopep8.coffee#L21) and notice it's using the stderr response (because of returnStderr flag).

So instead of parsing line:

2017-06-18T14:06:56.661Z - verbose: [] spawn result, stdout autopep8 1.3.2 (pycodestyle: 2.3.1)

It is parsing:

2017-06-18T14:06:56.661Z - verbose: [] spawn result, stderr

Which is empty string, and of course fails.

I'm going to try and fix this now. Thank you for bringing this bug to my attention!

To make matters stranger, stderr is being used for autopep 1.1.1:
image

I'll need to add support for both.

Fixed. Release coming soon!

Published patch to v0.30.1

Please provide the above information if the latest release does not improve things for you. Thanks!

Currently using the v0.30.1 on Arch (Manjaro) :

which autopep8

/usr/bin/autopep8

autopep8 --version

autopep8 2.0a0

Error: Could not find 'autopep8'. The program may not be installed.
at Function.Executable.commandNotFoundError (/home/loukajc/.atom/packages/atom-beautify/src/beautifiers/executable.coffee:272:14)
at HybridExecutable.Executable.commandNotFoundError (/home/loukajc/.atom/packages/atom-beautify/src/beautifiers/executable.coffee:264:18)
at /home/loukajc/.atom/packages/atom-beautify/src/beautifiers/executable.coffee:115:25
at tryCatcher (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:689:18)
at Async._drainQueue (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:143:10)
at Async.drainQueues (/home/loukajc/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:17:14)
at process._tickCallback (internal/process/next_tick.js:103:7)

Thank your for working on that ^.^

@TheLaluka: Please follow the issue template provided. More specifically, adding a link to the required debug.md Gist which includes debugging information that answers our most commonly asked questions.
Thank you.

autopep8 --version
autopep8 2.0a0

Looks like this versioning format may not be supported. Is there a stable release you could use instead? The Executable (see https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/autopep8.coffee#L19 ) expects it to be looking like 2.0.0 (proper semver format).

I will try to fix this and publish a release ASAP. Thanks!

Well, quite busy atm so i'll work on something else and wait for a fix (or just write tabs by hand, we're too lazy duh)
Have a great day sir ! ^.^

@Glavin001 I can confirm that things are (mostly) working on my end now. Thanks for the speedy fix!

I say mostly as occasionally executing the keyboard shortcut ctrl-alt-b will cause Atom to lockup (only for Beautification with autopep8, Beautification with uncrustify is fine for C++ files) and need me to manually kill it from the command line.

freezing

contents of keymap.cson:

# Ensure that Atom Beautify is mapped to Ctrl + Alt + b
'.platform-linux atom-workspace, .platform-linux atom-text-editor, .platform-win32 atom-workspace, .platform-win32 atom-text-editor':
  'ctrl-alt-b': 'atom-beautify:beautify-editor'

However, I can't reproduce this enough to say what this bug would be, so for the time being I think everything is good to go. :+1:

Published fixes to v0.30.2

@TheLaluka should work now. If not, I will need a debug.md Gist link.

Works like a charm, thank you for the quick support !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

opikhidayat picture opikhidayat  路  4Comments

bartocc picture bartocc  路  5Comments

CorentinAndre picture CorentinAndre  路  4Comments

jcollum picture jcollum  路  4Comments

callmeyesh picture callmeyesh  路  3Comments