Skip to content
Snippets Groups Projects
Commit 323f0199 authored by Jan Caron's avatar Jan Caron
Browse files

PEP8 Compliance for scripts and tests

setup.py: Final cleanup
deleted initpyximport, compare_method_errors and get_revision (now in setup.py)
parent ee36c1d6
No related branches found
No related tags found
No related merge requests found
...@@ -12,4 +12,3 @@ from pyramid.phasemap import PhaseMap ...@@ -12,4 +12,3 @@ from pyramid.phasemap import PhaseMap
import os import os
os.chdir('C:\Users\Jan\Daten\PhD Thesis\Pyramid\output') os.chdir('C:\Users\Jan\Daten\PhD Thesis\Pyramid\output')
# TODO: Path not hard-coded!!!
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Create random magnetic distributions.""" """Create random magnetic distributions."""
import random as rnd import random as rnd
import pdb, traceback, sys import pdb
import traceback
import sys
import numpy as np import numpy as np
from numpy import pi from numpy import pi
...@@ -26,19 +29,19 @@ def reconstruct_random_distribution(): ...@@ -26,19 +29,19 @@ def reconstruct_random_distribution():
# Input parameters: # Input parameters:
n_pixel = 5 n_pixel = 5
dim = (1, 16, 16) dim = (1, 16, 16)
b_0 = 1 # in T b_0 = 1 # in T
res = 10.0 # in nm res = 10.0 # in nm
rnd.seed(18) rnd.seed(18)
threshold = 0 threshold = 0
# Create lists for magnetic objects: # Create lists for magnetic objects:
mag_shape_list = np.zeros((n_pixel,) + dim) mag_shape_list = np.zeros((n_pixel,) + dim)
phi_list = np.zeros(n_pixel) phi_list = np.zeros(n_pixel)
magnitude_list = np.zeros(n_pixel) magnitude_list = np.zeros(n_pixel)
for i in range(n_pixel): for i in range(n_pixel):
pixel = (rnd.randrange(dim[0]), rnd.randrange(dim[1]), rnd.randrange(dim[2])) pixel = (rnd.randrange(dim[0]), rnd.randrange(dim[1]), rnd.randrange(dim[2]))
mag_shape_list[i,...] = mc.Shapes.pixel(dim, pixel) mag_shape_list[i, ...] = mc.Shapes.pixel(dim, pixel)
phi_list[i] = 2*pi*rnd.random() phi_list[i] = 2 * pi * rnd.random()
magnitude_list[i] = rnd.random() magnitude_list[i] = rnd.random()
# Create magnetic distribution: # Create magnetic distribution:
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list) magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list)
...@@ -54,7 +57,7 @@ def reconstruct_random_distribution(): ...@@ -54,7 +57,7 @@ def reconstruct_random_distribution():
x_mask = abs(x_mag) > threshold x_mask = abs(x_mag) > threshold
y_mask = abs(y_mag) > threshold y_mask = abs(y_mag) > threshold
mask = np.logical_or(np.logical_or(x_mask, y_mask), z_mask) mask = np.logical_or(np.logical_or(x_mask, y_mask), z_mask)
# Reconstruct the magnetic distribution: # Reconstruct the magnetic distribution:
mag_data_rec = rc.reconstruct_simple_leastsq(phase_map, mask, b_0) mag_data_rec = rc.reconstruct_simple_leastsq(phase_map, mask, b_0)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """Setup for testing, building, distributing and installing the 'Pyramid'-package"""
Created on Fri May 03 10:27:04 2013
@author: Jan
"""
# Build extensions: 'python setup.py build_ext -i clean'
# Install package: 'python setup.py install clean'
import numpy import numpy
import os import os
import sys import sys
import sysconfig import sysconfig
#import glob import subprocess
#from distutils.core import setup
from distutils.command.build import build from distutils.command.build import build
#from distutils.extension import Extension
from Cython.Distutils import build_ext from Cython.Distutils import build_ext
from setuptools import setup
from setuptools import find_packages
from setuptools.extension import Extension
from setuptools import setup, find_packages
from setuptools.extension import Extension class custom_build(build):
'''Custom build command'''
def make_hgrevision(self, target):
output = subprocess.Popen(["hg", "id", "-i"], stdout=subprocess.PIPE).communicate()[0]
hgrevision_cc = file(str(target), "w")
hgrevision_cc.write('HG_Revision = "{0}"\n'.format(output.strip()))
hgrevision_cc.close()
def run(self):
build.run(self)
print 'creating hg_revision.txt'
self.make_hgrevision(os.path.join('build', get_build_path('lib'), 'hg_revision.txt'))
def make_hgrevision(target, source, env): def get_build_path(dname):
import subprocess as sp '''Returns the name of a distutils build directory'''
output = sp.Popen(["hg", "id", "-i"], stdout=sp.PIPE).communicate()[0] path = "{dirname}.{platform}-{version[0]}.{version[1]}"
hgrevision_cc = file(str(target[0]), "w") return path.format(dirname=dname, platform=sysconfig.get_platform(), version=sys.version_info)
hgrevision_cc.write('HG_Revision = "{0}"\n'.format(output.strip()))
hgrevision_cc.close()
print '\n------------------------------------------------------------------------------'
def get_files(rootdir):
'''Returns a list of .py-files inside rootdir'''
filepaths = []
for root, dirs, files in os.walk(rootdir):
for filename in files:
if filename.endswith('.py'):
filepaths.append(os.path.join(root, filename))
return filepaths
print '\n-------------------------------------------------------------------------------'
setup( setup(
name = 'Pyramid', name = 'Pyramid',
...@@ -44,21 +54,23 @@ setup( ...@@ -44,21 +54,23 @@ setup(
author = 'Jan Caron', author = 'Jan Caron',
author_email = 'j.caron@fz-juelich.de', author_email = 'j.caron@fz-juelich.de',
packages = find_packages(exclude=['test']),#['pyramid', 'pyramid.numcore', 'test', 'scripts'], packages = find_packages(exclude=['tests']),
include_dirs = [numpy.get_include()], include_dirs = [numpy.get_include()],
requires = ['numpy', 'matplotlib'], requires = ['numpy', 'matplotlib'],
scripts = ['scripts/create_logo.py'], scripts = get_files('scripts'),
test_suite = 'test',
test_suite = 'tests',
cmdclass = {'build_ext': build_ext},
cmdclass = {'build_ext': build_ext, 'build': custom_build},
ext_package = 'pyramid/numcore', ext_package = 'pyramid/numcore',
ext_modules = [ ext_modules = [
Extension('phase_mag_real', ['pyramid/numcore/phase_mag_real.pyx'], Extension('phase_mag_real', ['pyramid/numcore/phase_mag_real.pyx'],
include_dirs = [numpy.get_include(), numpy.get_numarray_include()], include_dirs = [numpy.get_include(), numpy.get_numarray_include()],
extra_compile_args=["-march=native", "-mtune=native"] extra_compile_args=['-march=native', '-mtune=native']
) )
] ]
) )
print '------------------------------------------------------------------------------\n' print '-------------------------------------------------------------------------------\n'
import unittest
from test_compliance import TestCaseCompliance
from test_magcreator import TestCaseMagCreator
from test_magdata import TestCaseMagData
from test_projector import TestCaseProjector
from test_phasemapper import TestCasePhaseMapper
from test_phasemap import TestCasePhaseMap
from test_holoimage import TestCaseHoloImage
from test_analytic import TestCaseAnalytic
from test_reconstructor import TestCaseReconstructor
def load_suite():
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTest(loader.loadTestsFromTestCase(TestCaseCompliance))
suite.addTest(loader.loadTestsFromTestCase(TestCaseMagCreator))
suite.addTest(loader.loadTestsFromTestCase(TestCaseMagData))
suite.addTest(loader.loadTestsFromTestCase(TestCaseProjector))
suite.addTest(loader.loadTestsFromTestCase(TestCasePhaseMapper))
suite.addTest(loader.loadTestsFromTestCase(TestCasePhaseMap))
suite.addTest(loader.loadTestsFromTestCase(TestCaseHoloImage))
suite.addTest(loader.loadTestsFromTestCase(TestCaseAnalytic))
suite.addTest(loader.loadTestsFromTestCase(TestCaseReconstructor))
return suite
...@@ -10,9 +10,7 @@ import pep8 ...@@ -10,9 +10,7 @@ import pep8
class TestCaseCompliance(unittest.TestCase): class TestCaseCompliance(unittest.TestCase):
""" """Class for checking compliance of pyramid.""" # TODO: Docstring
Class for checking compliance of pyjurassic.
""" # TODO: Docstring
def setUp(self): def setUp(self):
pass pass
...@@ -24,15 +22,16 @@ class TestCaseCompliance(unittest.TestCase): ...@@ -24,15 +22,16 @@ class TestCaseCompliance(unittest.TestCase):
filepaths = [] filepaths = []
for root, dirs, files in os.walk(rootdir): for root, dirs, files in os.walk(rootdir):
for filename in files: for filename in files:
if filename.endswith('.py') or filename.endswith('.pyx'): if ((filename.endswith('.py') or filename.endswith('.pyx'))
and root != os.path.join('scripts', 'gui')):
filepaths.append(os.path.join(root, filename)) filepaths.append(os.path.join(root, filename))
return filepaths return filepaths
def test_pep8(self): def test_pep8(self):
# TODO: Docstring # TODO: Docstring
files = self.get_files_to_check('pyramid') \ files = self.get_files_to_check('pyramid') \
+ self.get_files_to_check('scripts') \ + self.get_files_to_check('scripts') \
+ self.get_files_to_check('test') + self.get_files_to_check('tests')
ignores = ('E226', 'E128') ignores = ('E226', 'E128')
pep8.MAX_LINE_LENGTH = 99 pep8.MAX_LINE_LENGTH = 99
pep8style = pep8.StyleGuide(quiet=False) pep8style = pep8.StyleGuide(quiet=False)
...@@ -48,6 +47,8 @@ class TestCaseCompliance(unittest.TestCase): ...@@ -48,6 +47,8 @@ class TestCaseCompliance(unittest.TestCase):
result = pep8style.check_files(files) result = pep8style.check_files(files)
if result.total_errors == 0: if result.total_errors == 0:
print 'No Warnings or Errors detected!' print 'No Warnings or Errors detected!'
else:
print '\n{} Warnings and Errors detected!'.format(result.total_errors)
sys.stdout = stdout_buffer sys.stdout = stdout_buffer
error_message = 'Found %s Errors and Warnings!' % result.total_errors error_message = 'Found %s Errors and Warnings!' % result.total_errors
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment