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

autopep8 not found, but it is in the PATH #1030

Closed
stinnux opened this issue Jun 24, 2016 · 14 comments
Closed

autopep8 not found, but it is in the PATH #1030

stinnux opened this issue Jun 24, 2016 · 14 comments

Comments

@stinnux
Copy link

stinnux commented Jun 24, 2016

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.

@prettydiff prettydiff added the bug label Jun 24, 2016
@ityshchenko
Copy link

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

@Glavin001
Copy link
Owner

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.

@matthewfeickert
Copy link

matthewfeickert commented Jun 18, 2017

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:

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

@Glavin001
Copy link
Owner

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!

@Glavin001 Glavin001 self-assigned this Jun 19, 2017
@Glavin001 Glavin001 added the bug label Jun 19, 2017
@Glavin001
Copy link
Owner

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

I'll need to add support for both.

@Glavin001
Copy link
Owner

Fixed. Release coming soon!

Glavin001 added a commit that referenced this issue Jun 19, 2017
@Glavin001
Copy link
Owner

Published patch to v0.30.1

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

@laluka
Copy link

laluka commented Jun 19, 2017

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 ^.^

@Glavin001
Copy link
Owner

@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.

@Glavin001
Copy link
Owner

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!

@laluka
Copy link

laluka commented Jun 19, 2017

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 ! ^.^

@matthewfeickert
Copy link

@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. 👍

@Glavin001
Copy link
Owner

Published fixes to v0.30.2

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

@laluka
Copy link

laluka commented Jun 20, 2017

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

kumekay added a commit to kumekay/atom-beautify that referenced this issue Jun 20, 2017
* master: (79 commits)
  Update changelog [skip ci]
  Prepare 0.30.2 release
  Fixes Glavin001#1030. Add support for alpha versions of autopep8
  Fixes Glavin001#1725. Fix version parsing of PHP executable
  Fixes Glavin001#1730. Correctly parse PHPCBF version and improve handling of Executable
  See Glavin001#1708. Re-generate documentation for Fortran file extension changes
  Prepare 0.30.1 release
  Prepare changelog for v0.30.1
  See Glavin001#1725. Update changelog
  Fixes Glavin001#1725. Improve PHP-CS-Fixer support with handling script path
  Update changelog. See Glavin001#1030.
  Fix Glavin001#1030. Autopep8 Executable did not handle older and newer versions
  Prepare 0.30.0 release
  See Glavin001#1687. Update README, remove note about Executables now that it is supported
  See Glavin001#1687. Update Changelog with info about Executables
  Add Greenkeeper badge
  See Glavin001#1687. Update README docs to include details about Executables and Docker support
  Add more dependencies to next-update and greenkeep ignore list
  See Glavin001#1687. Fix typos in Travis CI config
  See Glavin001#1687. Install Sass-convert and Uncrustify beautifiers via Docker for Linux Travis CI build
  ...

# Conflicts:
#	README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants