Closed yogeshg closed 6 years ago
Merging #124 into master will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #124 +/- ##
=======================================
Coverage 85.37% 85.37%
=======================================
Files 33 33
Lines 1921 1921
Branches 44 44
=======================================
Hits 1640 1640
Misses 281 281
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update b09974b...8cc1679. Read the comment docs.
@MrBago Could you take another pass?
LGTM and merged it into master. Thanks!
In this PR, we
Motivation
Developers need to run several tasks and setting these up could be a hassle. These tasks include but are not limited to setting up the environment, running style checks, refactoring code based on best practices and running tests.
Tools like pylint, prospector etc. do a great job of giving users flexibility, but they are mostly run with a certain set of default values. They also do not give options like allowing to run on only currently touched files and similar heursitics. Documentation is needed for default values, environment required and so on for every tool per project. But we rarely read documentations, so an interactive script with default values and options to run these tools in a limited scope might be useful.
python/run.py
allows us to do most of the things we need for development cycle and also guide us through the process using "--help" and autocomplete options. It should also be easy for us to maintain such a script and to read it to see what goes on under the hood. Luckily for us pythonargh
package usesparseargs
andargscomplete
to expose python functions to shell with great help and autocompletion.Current Tools
pylint
is configured for variable names as bothsnake_case
andcamelCase
prospector
allows some other tests like pep8 conventions and code complexity; we generate suggestions using this but do not enforce them in CIyapf
patches code automatically to follow pep8 and is not a part of CI; it is configured with defaults in the scriptenvsetup
is a python function to allow setting environment for this project; see demo belownose
tests are currently used inrun-tests.sh
after setting some environment variables and specifying defaultsFuture scope
camelCase
while keeping everything elsesnake_case
. Public API can be defined as those considered public by sphinx by recursively using__all__
run.py
to allow maintainability, readability and add functionality.mypy
andpyannotate
toolsNotes
argh
.argh
also generates help files from python docstringsargcomplete
generates autocomplete -- we can bootstrap that configuration throughenvsetup
optionmypy
is a static type checker for Python. If you sprinkle your code with type annotations, mypy can type check your code and find common bugs. [mypy docs] For example:pyannotate
can help us generate these type annotations using testing. For example, assuming there's no type annotation currently intmp.py
, we can run the tests for it in followingtest_tmp.py
and use the file generated withpyannotate
to make the following patch.Demo of python/run.py
positional arguments: {pylint,prospector,yapf,envsetup} pylint ...(truncated for brevity)... prospector Wraps
prospector
and provides defaults. Runprospector --help
for more details. Trailing arguments are a list of files, packages or modules. if nothing is specified, default value is ./python/sparkdl yapf Wrapsyapf
and provides some defaults. Runyapf --help
for more details. envsetup ...(truncated for brevity)...optional arguments: -h, --help show this help message and exit
$ python/run.py envsetup -h usage: run.py envsetup [-h] [-d] [-i] [-m] [-c] [-v]
optional arguments: -h, --help show this help message and exit -d, --default False -i, --interactive False -m, --missing-only False -c, --completion False -v, --verbose False
$ python/run.py pylint -h usage: run.py pylint [-h] [--rcfile RCFILE] [--reports REPORTS] [args [args ...]]
positional arguments: args list of files,packages or modules. if nothing is specified, default value is sparkdl (default: -)
optional arguments: -h, --help show this help message and exit --rcfile RCFILE './python/.pylint/accepted.rc' --reports REPORTS 'y'