Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge 104734b into 0426dc5
Browse files Browse the repository at this point in the history
  • Loading branch information
shssf committed Aug 1, 2019
2 parents 0426dc5 + 104734b commit f9fb520
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 3 deletions.
53 changes: 53 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
Language: Cpp
Standard: Cpp11

AccessModifierOffset: -4

AlignConsecutiveDeclarations: false
AlignConsecutiveAssignments: false
AlignTrailingComments: true

AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline

AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true

BinPackArguments: false
BinPackParameters: false

BreakBeforeBraces: Allman
BreakConstructorInitializersBeforeComma: true

ColumnLimit: 120
CommentPragmas: '.*'

IndentCaseLabels: false
IndentWrappedFunctionNames: true

KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: All

PointerAlignment: Left
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

SortIncludes: false
ReflowComments: true

IncludeCategories:
- Regex: '^".*'
Priority: 3
- Regex: '^<.*'
Priority: 2
SortIncludes: true
159 changes: 156 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
from setuptools import setup, Extension, find_packages
import platform, os
# *****************************************************************************
# Copyright (c) 2019, Intel Corporation All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

from setuptools import setup, Extension, find_packages, Command
import platform
import os

# Note we don't import Numpy at the toplevel, since setup.py
# should be able to run without Numpy for pip to discover the
Expand Down Expand Up @@ -288,6 +315,132 @@ def readme():
if _has_xenon:
_ext_mods.append(ext_xenon_wrapper)

# Custom build commands
#
# These commands extends standart setuptools build procedure
#
hpat_build_commands = versioneer.get_cmdclass()


class style(Command):
""" Command to check and adjust code style
Usage:
To check style: python ./setup.py style
To fix style: python ./setup.py style -a
"""
user_options = [
('apply', 'a', 'Apply codestyle changes to sources.')
]
description = "Code style check and apply (with -a)"
boolean_options = []

_result_marker = "Result:"
_project_directory_excluded = ['build', '.git']

_c_formatter = 'clang-format-6.0'
_c_formatter_install_msg = 'pip install clang'
_c_formatter_command_line = [_c_formatter, '-style=file']
_c_file_extensions = ['.h', '.c', '.hpp', '.cpp']

_py_checker = 'pycodestyle'
_py_formatter = 'autopep8'
_py_formatter_install_msg = 'pip install --upgrade autopep8\npip install --upgrade pycodestyle'
# E265 and W503 excluded because I didn't find a way to apply changes automatically
_py_checker_command_line = [_py_checker, '--ignore=E265,W503']
_py_formatter_command_line = [_py_formatter, '--in-place', '--aggressive', '--aggressive']
_py_file_extensions = ['.py']

def _get_file_list(self, path, search_extentions):
""" Return file list to be adjusted or checked
path - is the project base path
search_extentions - list of strings with files extension to search recurcivly
"""
files = []
exluded_directories_full_path = [os.path.join(path, excluded_dir)
for excluded_dir in self._project_directory_excluded]

# r=root, d=directories, f = files
for r, d, f in os.walk(path):
# match exclude pattern in current directory
found = False
for excluded_dir in exluded_directories_full_path:
if r.find(excluded_dir) >= 0:
found = True

if found:
continue

for file in f:
filename, extention = os.path.splitext(file)
if extention in search_extentions:
files.append(os.path.join(r, file))

return files

def initialize_options(self):
self.apply = 0

def finalize_options(self):
pass

def run(self):
root_dir = versioneer.get_root()
print("Project directory is: %s" % root_dir)

if self.apply:
self._c_formatter_command_line += ['-i']
else:
self._c_formatter_command_line += ['-output-replacements-xml']

import subprocess

bad_style_file_names = []

# C files handling
c_files = self._get_file_list(root_dir, self._c_file_extensions)
try:
for f in c_files:
command_output = subprocess.Popen(self._c_formatter_command_line + [f], stdout=subprocess.PIPE)
command_cout, command_cerr = command_output.communicate()
if not self.apply:
if command_cout.find(b'<replacement ') > 0:
bad_style_file_names.append(f)
except BaseException as original_error:
print("%s is not installed.\nPlease use: %s" % (self._c_formatter, self._c_formatter_install_msg))
print("Original error message is:\n", original_error)
exit(1)

# Python files handling
py_files = self._get_file_list(root_dir, self._py_file_extensions)
try:
for f in py_files:
if not self.apply:
command_output = subprocess.Popen(
self._py_checker_command_line + [f])
returncode = command_output.wait()
if returncode != 0:
bad_style_file_names.append(f)
else:
command_output = subprocess.Popen(
self._py_formatter_command_line + [f])
command_output.wait()
except BaseException as original_error:
print("%s is not installed.\nPlease use: %s" % (self._py_formatter, self._py_formatter_install_msg))
print("Original error message is:\n", original_error)
exit(1)

if bad_style_file_names:
print("Following files style need to be adjusted:")
for line in bad_style_file_names:
print(line)
print("%s Style check failed" % self._result_marker)
else:
print("%s Style check passed" % self._result_marker)


hpat_build_commands.update({'style': style})

setup(name='hpat',
version=versioneer.get_version(),
description='compiling Python code for clusters',
Expand All @@ -308,5 +461,5 @@ def readme():
package_data={'hpat.tests': ['*.bz2'],},
install_requires=['numba'],
extras_require={'HDF5': ["h5py"], 'Parquet': ["pyarrow"]},
cmdclass=versioneer.get_cmdclass(),
cmdclass=hpat_build_commands,
ext_modules = _ext_mods)

0 comments on commit f9fb520

Please sign in to comment.