diff options
author | hyukjinkwon <gurwls223@gmail.com> | 2017-01-02 15:23:19 +0000 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2017-01-02 15:23:19 +0000 |
commit | 46b212602428f1f11c184c836b4e09c150d0ee30 (patch) | |
tree | b30420dbdfe979f65c390edbfe2d103572c07501 /dev/create-release/generate-contributors.py | |
parent | f1330b1d9e7b1d5de611e59eecae1bf0b0616d81 (diff) | |
download | spark-46b212602428f1f11c184c836b4e09c150d0ee30.tar.gz spark-46b212602428f1f11c184c836b4e09c150d0ee30.tar.bz2 spark-46b212602428f1f11c184c836b4e09c150d0ee30.zip |
[SPARK-19002][BUILD][PYTHON] Check pep8 against all Python scripts
## What changes were proposed in this pull request?
This PR proposes to check pep8 against all other Python scripts and fix the errors as below:
```bash
./dev/create-release/generate-contributors.py
./dev/create-release/releaseutils.py
./dev/create-release/translate-contributors.py
./dev/lint-python
./python/docs/epytext.py
./examples/src/main/python/mllib/decision_tree_classification_example.py
./examples/src/main/python/mllib/decision_tree_regression_example.py
./examples/src/main/python/mllib/gradient_boosting_classification_example.py
./examples/src/main/python/mllib/gradient_boosting_regression_example.py
./examples/src/main/python/mllib/linear_regression_with_sgd_example.py
./examples/src/main/python/mllib/logistic_regression_with_lbfgs_example.py
./examples/src/main/python/mllib/naive_bayes_example.py
./examples/src/main/python/mllib/random_forest_classification_example.py
./examples/src/main/python/mllib/random_forest_regression_example.py
./examples/src/main/python/mllib/svm_with_sgd_example.py
./examples/src/main/python/streaming/network_wordjoinsentiments.py
./sql/hive/src/test/resources/data/scripts/cat.py
./sql/hive/src/test/resources/data/scripts/cat_error.py
./sql/hive/src/test/resources/data/scripts/doubleescapedtab.py
./sql/hive/src/test/resources/data/scripts/dumpdata_script.py
./sql/hive/src/test/resources/data/scripts/escapedcarriagereturn.py
./sql/hive/src/test/resources/data/scripts/escapednewline.py
./sql/hive/src/test/resources/data/scripts/escapedtab.py
./sql/hive/src/test/resources/data/scripts/input20_script.py
./sql/hive/src/test/resources/data/scripts/newline.py
```
## How was this patch tested?
- `./python/docs/epytext.py`
```bash
cd ./python/docs $$ make html
```
- pep8 check (Python 2.7 / Python 3.3.6)
```
./dev/lint-python
```
- `./dev/merge_spark_pr.py` (Python 2.7 only / Python 3.3.6 not working)
```bash
python -m doctest -v ./dev/merge_spark_pr.py
```
- `./dev/create-release/releaseutils.py` `./dev/create-release/generate-contributors.py` `./dev/create-release/translate-contributors.py` (Python 2.7 only / Python 3.3.6 not working)
```bash
python generate-contributors.py
python translate-contributors.py
```
- Examples (Python 2.7 / Python 3.3.6)
```bash
./bin/spark-submit examples/src/main/python/mllib/decision_tree_classification_example.py
./bin/spark-submit examples/src/main/python/mllib/decision_tree_regression_example.py
./bin/spark-submit examples/src/main/python/mllib/gradient_boosting_classification_example.py
./bin/spark-submit examples/src/main/python/mllib/gradient_boosting_regression_example.p
./bin/spark-submit examples/src/main/python/mllib/random_forest_classification_example.py
./bin/spark-submit examples/src/main/python/mllib/random_forest_regression_example.py
```
- Examples (Python 2.7 only / Python 3.3.6 not working)
```
./bin/spark-submit examples/src/main/python/mllib/linear_regression_with_sgd_example.py
./bin/spark-submit examples/src/main/python/mllib/logistic_regression_with_lbfgs_example.py
./bin/spark-submit examples/src/main/python/mllib/naive_bayes_example.py
./bin/spark-submit examples/src/main/python/mllib/svm_with_sgd_example.py
```
- `sql/hive/src/test/resources/data/scripts/*.py` (Python 2.7 / Python 3.3.6 within suggested changes)
Manually tested only changed ones.
- `./dev/github_jira_sync.py` (Python 2.7 only / Python 3.3.6 not working)
Manually tested this after disabling actually adding comments and links.
And also via Jenkins tests.
Author: hyukjinkwon <gurwls223@gmail.com>
Closes #16405 from HyukjinKwon/minor-pep8.
Diffstat (limited to 'dev/create-release/generate-contributors.py')
-rwxr-xr-x | dev/create-release/generate-contributors.py | 145 |
1 files changed, 90 insertions, 55 deletions
diff --git a/dev/create-release/generate-contributors.py b/dev/create-release/generate-contributors.py index db9c680a4b..131d81c8a7 100755 --- a/dev/create-release/generate-contributors.py +++ b/dev/create-release/generate-contributors.py @@ -33,14 +33,14 @@ PREVIOUS_RELEASE_TAG = os.environ.get("PREVIOUS_RELEASE_TAG", "v1.1.0") while not tag_exists(RELEASE_TAG): RELEASE_TAG = raw_input("Please provide a valid release tag: ") while not tag_exists(PREVIOUS_RELEASE_TAG): - print "Please specify the previous release tag." - PREVIOUS_RELEASE_TAG = raw_input(\ - "For instance, if you are releasing v1.2.0, you should specify v1.1.0: ") + print("Please specify the previous release tag.") + PREVIOUS_RELEASE_TAG = raw_input( + "For instance, if you are releasing v1.2.0, you should specify v1.1.0: ") # Gather commits found in the new tag but not in the old tag. # This filters commits based on both the git hash and the PR number. # If either is present in the old tag, then we ignore the commit. -print "Gathering new commits between tags %s and %s" % (PREVIOUS_RELEASE_TAG, RELEASE_TAG) +print("Gathering new commits between tags %s and %s" % (PREVIOUS_RELEASE_TAG, RELEASE_TAG)) release_commits = get_commits(RELEASE_TAG) previous_release_commits = get_commits(PREVIOUS_RELEASE_TAG) previous_release_hashes = set() @@ -62,17 +62,20 @@ if not new_commits: sys.exit("There are no new commits between %s and %s!" % (PREVIOUS_RELEASE_TAG, RELEASE_TAG)) # Prompt the user for confirmation that the commit range is correct -print "\n==================================================================================" -print "JIRA server: %s" % JIRA_API_BASE -print "Release tag: %s" % RELEASE_TAG -print "Previous release tag: %s" % PREVIOUS_RELEASE_TAG -print "Number of commits in this range: %s" % len(new_commits) +print("\n==================================================================================") +print("JIRA server: %s" % JIRA_API_BASE) +print("Release tag: %s" % RELEASE_TAG) +print("Previous release tag: %s" % PREVIOUS_RELEASE_TAG) +print("Number of commits in this range: %s" % len(new_commits)) print + + def print_indented(_list): - for x in _list: print " %s" % x + for x in _list: + print(" %s" % x) if yesOrNoPrompt("Show all commits?"): print_indented(new_commits) -print "==================================================================================\n" +print("==================================================================================\n") if not yesOrNoPrompt("Does this look correct?"): sys.exit("Ok, exiting") @@ -82,45 +85,76 @@ maintenance = [] reverts = [] nojiras = [] filtered_commits = [] + + def is_release(commit_title): - return re.findall("\[release\]", commit_title.lower()) or\ - "preparing spark release" in commit_title.lower() or\ - "preparing development version" in commit_title.lower() or\ - "CHANGES.txt" in commit_title + return re.findall("\[release\]", commit_title.lower()) or \ + "preparing spark release" in commit_title.lower() or \ + "preparing development version" in commit_title.lower() or \ + "CHANGES.txt" in commit_title + + def is_maintenance(commit_title): - return "maintenance" in commit_title.lower() or\ - "manually close" in commit_title.lower() + return "maintenance" in commit_title.lower() or \ + "manually close" in commit_title.lower() + + def has_no_jira(commit_title): return not re.findall("SPARK-[0-9]+", commit_title.upper()) + + def is_revert(commit_title): return "revert" in commit_title.lower() + + def is_docs(commit_title): - return re.findall("docs*", commit_title.lower()) or\ - "programming guide" in commit_title.lower() + return re.findall("docs*", commit_title.lower()) or \ + "programming guide" in commit_title.lower() + + for c in new_commits: t = c.get_title() - if not t: continue - elif is_release(t): releases.append(c) - elif is_maintenance(t): maintenance.append(c) - elif is_revert(t): reverts.append(c) - elif is_docs(t): filtered_commits.append(c) # docs may not have JIRA numbers - elif has_no_jira(t): nojiras.append(c) - else: filtered_commits.append(c) + if not t: + continue + elif is_release(t): + releases.append(c) + elif is_maintenance(t): + maintenance.append(c) + elif is_revert(t): + reverts.append(c) + elif is_docs(t): + filtered_commits.append(c) # docs may not have JIRA numbers + elif has_no_jira(t): + nojiras.append(c) + else: + filtered_commits.append(c) # Warn against ignored commits if releases or maintenance or reverts or nojiras: - print "\n==================================================================================" - if releases: print "Found %d release commits" % len(releases) - if maintenance: print "Found %d maintenance commits" % len(maintenance) - if reverts: print "Found %d revert commits" % len(reverts) - if nojiras: print "Found %d commits with no JIRA" % len(nojiras) - print "* Warning: these commits will be ignored.\n" + print("\n==================================================================================") + if releases: + print("Found %d release commits" % len(releases)) + if maintenance: + print("Found %d maintenance commits" % len(maintenance)) + if reverts: + print("Found %d revert commits" % len(reverts)) + if nojiras: + print("Found %d commits with no JIRA" % len(nojiras)) + print("* Warning: these commits will be ignored.\n") if yesOrNoPrompt("Show ignored commits?"): - if releases: print "Release (%d)" % len(releases); print_indented(releases) - if maintenance: print "Maintenance (%d)" % len(maintenance); print_indented(maintenance) - if reverts: print "Revert (%d)" % len(reverts); print_indented(reverts) - if nojiras: print "No JIRA (%d)" % len(nojiras); print_indented(nojiras) - print "==================== Warning: the above commits will be ignored ==================\n" + if releases: + print("Release (%d)" % len(releases)) + print_indented(releases) + if maintenance: + print("Maintenance (%d)" % len(maintenance)) + print_indented(maintenance) + if reverts: + print("Revert (%d)" % len(reverts)) + print_indented(reverts) + if nojiras: + print("No JIRA (%d)" % len(nojiras)) + print_indented(nojiras) + print("==================== Warning: the above commits will be ignored ==================\n") prompt_msg = "%d commits left to process after filtering. Ok to proceed?" % len(filtered_commits) if not yesOrNoPrompt(prompt_msg): sys.exit("Ok, exiting.") @@ -147,9 +181,9 @@ invalid_authors = {} # } # author_info = {} -jira_options = { "server": JIRA_API_BASE } -jira_client = JIRA(options = jira_options) -print "\n=========================== Compiling contributor list ===========================" +jira_options = {"server": JIRA_API_BASE} +jira_client = JIRA(options=jira_options) +print("\n=========================== Compiling contributor list ===========================") for commit in filtered_commits: _hash = commit.get_hash() title = commit.get_title() @@ -168,8 +202,9 @@ for commit in filtered_commits: # Parse components from the commit title, if any commit_components = find_components(title, _hash) # Populate or merge an issue into author_info[author] + def populate(issue_type, components): - components = components or [CORE_COMPONENT] # assume core if no components provided + components = components or [CORE_COMPONENT] # assume core if no components provided if author not in author_info: author_info[author] = {} if issue_type not in author_info[author]: @@ -182,17 +217,17 @@ for commit in filtered_commits: jira_issue = jira_client.issue(issue) jira_type = jira_issue.fields.issuetype.name jira_type = translate_issue_type(jira_type, issue, warnings) - jira_components = [translate_component(c.name, _hash, warnings)\ - for c in jira_issue.fields.components] + jira_components = [translate_component(c.name, _hash, warnings) + for c in jira_issue.fields.components] all_components = set(jira_components + commit_components) populate(jira_type, all_components) except Exception as e: - print "Unexpected error:", e + print("Unexpected error:", e) # For docs without an associated JIRA, manually add it ourselves if is_docs(title) and not issues: populate("documentation", commit_components) - print " Processed commit %s authored by %s on %s" % (_hash, author, date) -print "==================================================================================\n" + print(" Processed commit %s authored by %s on %s" % (_hash, author, date)) +print("==================================================================================\n") # Write to contributors file ordered by author names # Each line takes the format " * Author name -- semi-colon delimited contributions" @@ -215,8 +250,8 @@ for author in authors: # Otherwise, group contributions by issue types instead of modules # e.g. Bug fixes in MLlib, Core, and Streaming; documentation in YARN else: - contributions = ["%s in %s" % (issue_type, nice_join(comps)) \ - for issue_type, comps in author_info[author].items()] + contributions = ["%s in %s" % (issue_type, nice_join(comps)) + for issue_type, comps in author_info[author].items()] contribution = "; ".join(contributions) # Do not use python's capitalize() on the whole string to preserve case assert contribution @@ -226,11 +261,11 @@ for author in authors: # E.g. andrewor14/SPARK-3425/SPARK-1157/SPARK-6672 if author in invalid_authors and invalid_authors[author]: author = author + "/" + "/".join(invalid_authors[author]) - #line = " * %s -- %s" % (author, contribution) + # line = " * %s -- %s" % (author, contribution) line = author contributors_file.write(line + "\n") contributors_file.close() -print "Contributors list is successfully written to %s!" % contributors_file_name +print("Contributors list is successfully written to %s!" % contributors_file_name) # Prompt the user to translate author names if necessary if invalid_authors: @@ -241,8 +276,8 @@ if invalid_authors: # Log any warnings encountered in the process if warnings: - print "\n============ Warnings encountered while creating the contributor list ============" - for w in warnings: print w - print "Please correct these in the final contributors list at %s." % contributors_file_name - print "==================================================================================\n" - + print("\n============ Warnings encountered while creating the contributor list ============") + for w in warnings: + print(w) + print("Please correct these in the final contributors list at %s." % contributors_file_name) + print("==================================================================================\n") |