Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Fixes #41 (#72)
Browse files Browse the repository at this point in the history
* Fixes #41

* Added doc string and code changes

* Addressing changes

;
q'

* Correcting spelling
  • Loading branch information
a2batic authored and CuriousLearner committed May 14, 2016
1 parent 946f762 commit 6ba7334
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python:

# command to install dependencies
install: pip install -U pytest
install: pip install -U autopep8

# command to run tests
script: py.test
script: py.test
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
license='BSD',
packages=['pydsa'],
zip_safe=False,
install_requires=['autopep8'],
)
50 changes: 50 additions & 0 deletions white_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# !/usr/bin/env python
'''
This module automatically checks for pep8 format.
It scans the complete folder, searches for python files
(ignoring the virtual environment python files) and automatially
format it according to pep8 format using a python plugin 'autopep8'.
'''

import os
import autopep8
import sys


BASE_DIR = os.path.abspath(__file__)


def format_file(path):
'''
The function, using 'for' loop scans all the directories as well
as sub-directories of the folder for python file and checks
for pep8 format.
'''
p = ""
for dirpath, _, filenames in os.walk(path):
if(os.path.exists(os.path.join(dirpath, 'bin/activate'))):
p = dirpath
for f in filenames:
if f.endswith('.py'):
filename = os.path.abspath(os.path.join(dirpath, f))
if (not bool(p)):
if os.access(filename, os.W_OK):
try:
file1 = open(filename, 'r')
source_code = file1.read()
file1.seek(0)
file1 = open(filename, 'w')
file1.truncate()
file1.write(autopep8.fix_code(source_code))
file1.close()
except:
print(filename)
print(sys.exc_info()[0])


if __name__ == "__main__":
path_of_dir = [
os.path.dirname(BASE_DIR),
]
for x in path_of_dir:
format_file(x)

0 comments on commit 6ba7334

Please sign in to comment.