paetzke / py-autopep8.el

py-autopep8.el integrates autopep8 into Emacs.
GNU General Public License v3.0
79 stars 21 forks source link

Code loss with autopep8! #5

Closed dmwelch closed 9 years ago

dmwelch commented 10 years ago

I installed autopep8 two weeks ago and I'm plagued by autopep8 removing valid code from my scripts. I use docopt and nipype, which have unique syntax but I'm stumped. Here's an example of code that is auto-removed:

#!/usr/bin/env python
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Usage:
  preprocessing.py [-h | --help]
  preprocessing.py [-f | --force] [-g | -b] [-F FORMAT | --format=FORMAT] (-n NAME| --name=NAME) SESSION...

Arguments:
  -n NAME, --name=NAME        experiment name
  SESSION                     one or more session IDs

Optional:
  -h, --help                  show this help message and exit
  -f, --force                 force DataSink rewriting
  -g                          global signal regression by masking gray matter
  -b                          whole brain
  -F FORMAT, --format=FORMAT  output format, values: afni, nifti, nifti_gz [default: nifti]

Example:
  preprocessing.py -n my_new_experiment 0001 0002 0003
  preprocessing.py -fgF nifti_gz --name new_experiment_w_gray_mask 00001 00002 00003
  preprocessing.py -bn my_new_experiment_brain_mask --format afni 0001 0002 0003
"""
# TODO: Modify virtualenv to include formatFMRI.sh
import os
import sys

import SEMTools as sem
from nipype.interfaces.ants.registration import Registration
from nipype.interfaces.ants import ApplyTransforms
from nipype.interfaces.afni.preprocess import *
from nipype.interfaces.freesurfer.preprocess import *
from nipype.interfaces.io import DataSink, DataGrabber
from nipype.interfaces.utility import Function, IdentityInterface, Rename, Select
from nipype.interfaces.utility import Merge as Merger
import nipype.pipeline.engine as pipe
import numpy

from utilities import *
...

Removing the #emacs ... and #vi:... lines stops this behavior, but I can't reproduce it now. It appears randomly!?! >:(

paetzke commented 10 years ago

Hi, I can't reproduce this neither. Could you try this script? It just needs 2 files (test.py and orig.py) with your example code. If py-autopep fails, you will see a diff.

#! /bin/bash

for i in `seq 4`; do
    echo $i
    emacs -nw test.py -f py-autopep8-before-save -f save-buffer -f save-buffers-kill-terminal
    diff orig.py test.py
done