Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add python code style lint and format #147

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make lint will only lint the newly added and changed parts of python files here.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make format will only format newly added python files and sort imports for both newly added and changed python files.

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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yapf style is based on pep8 here.

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'
]
)