Skip to content

Commit

Permalink
add python code style lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
Lynch Wu committed Mar 20, 2019
1 parent a3fd0e3 commit e1e7929
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]
# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.py]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ SMALL ?= 'tests/small'
MEDIUM ?= 'tests/medium'
LARGE ?= 'tests/large'
XLARGE ?= 'tests/xlarge'
NEWLY_ADDED_PY_FILES = $(shell git ls-files -o --exclude-standard | grep -E '\.py$$')
CHANGED_ADDED_PY_FILES = $(shell git ls-files -mo --exclude-standard | grep -E '\.py$$')

.PHONY: tests
.PHONY: tests, lint, format

all: egg

Expand Down Expand Up @@ -101,3 +103,24 @@ docs:

build_spl: clean
python -m splunk_eventgen build --destination ./

lint:
ifeq ($(NEWLY_ADDED_PY_FILES), )
@echo 'No newly added python files. Skip...'
else
@flake8 $(NEWLY_ADDED_PY_FILES) || true
endif
@git diff -U0 -- '*.py' | flake8 --diff || true

format:
ifeq ($(CHANGED_ADDED_PY_FILES), )
@echo 'No changed python files. Skip...'
else
@isort $(CHANGED_ADDED_PY_FILES)
endif
ifeq ($(NEWLY_ADDED_PY_FILES), )
@echo 'No newly added python files. Skip...'
else
@yapf -i $(NEWLY_ADDED_PY_FILES)
endif

7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[flake8]
exclude = .git,.tox,__pycache__,env,venv
exclude = .git,.tox,__pycache__,env,venv,build,dist,docs
max-line-length = 120

[metadata]
description-file = README.md
version-from-file: __init__.py

[yapf]
based_on_style = pep8
spaces_before_comment = 4
split_before_logical_operator = true
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
except(IOError, ImportError):
long_description = open('README.md').read()


def readme():
with open('README.md') as f:
return f.read()


setup(
name='splunk_eventgen',
version=VERSION,
Expand All @@ -38,18 +40,21 @@ def readme():
packages=find_packages(),
package_data={"splunk_eventgen": ['*.sh', '*.txt', '*.yml'], '': ['*.sh', '*.txt', '*.yml']},
install_requires=[
'pytest>=3.0.0', # Required to test functional tests in eventgen.
'pytest>=3.0.0', # Required to test functional tests in eventgen.
'boto3',
'requests>=2.18.4',
'requests[security]',
'logutils>=0.3.4.1',
'futures>=3.0.5',
'ujson>=1.35', # way faster implementation of JSON processing
'ujson>=1.35', # way faster implementation of JSON processing
'pyyaml',
'httplib2',
'jinja2',
'pyrabbit==1.1.0',
'urllib3==1.23',
'pyOpenSSL'
'pyOpenSSL',
'flake8>=3.7.7',
'yapf>=0.26.0',
'isort>=4.3.15'
]
)

0 comments on commit e1e7929

Please sign in to comment.