Skip to content

Commit c12c925

Browse files
committed
new pre-commit hooks, add background spark job
1 parent 04c3106 commit c12c925

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ repos:
44
hooks:
55
- id: black
66
language_version: python3.6
7+
- repo: https://github.com/asottile/blacken-docs
8+
rev: v1.0.0-1
9+
hooks:
10+
- id: blacken-docs
11+
additional_dependencies: [black]
12+
- repo: https://github.com/asottile/reorder_python_imports
13+
rev: v1.5.0
14+
hooks:
15+
- id: reorder-python-imports

issho/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
32
"""Top-level package for issho."""
43

54
__author__ = """Michael Bilow"""
@@ -21,9 +20,9 @@
2120
-------------
2221
Here are a few of the things that issho (should) do well:
2322
- execute commands on a remote box
24-
- run commands in the background on a remote box easily
2523
- transfer files to and from a remote easily
2624
- set up an SSH tunnel through a remote
25+
- run Hive & Spark jobs
2726
2827
TODOs
2928
---------

issho/issho.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
# -*- coding: utf-8 -*-
2-
32
"""
43
Implementation for the ``Issho`` class, which implements
54
a connection and some simple commands over ``ssh``, using
65
``keyring`` to manage secrets locally.
76
"""
8-
9-
import paramiko
10-
import keyring
11-
from sshtunnel import SSHTunnelForwarder
12-
from issho.helpers import (
13-
default_sftp_path,
14-
get_pkey,
15-
issho_pw_name,
16-
get_user,
17-
clean_spark_options,
18-
)
19-
from issho.config import read_issho_conf, read_ssh_profile
207
import sys
218
import time
229
from shutil import copyfile
10+
2311
import humanize
12+
import keyring
13+
import paramiko
14+
from sshtunnel import SSHTunnelForwarder
15+
16+
from issho.config import read_issho_conf
17+
from issho.config import read_ssh_profile
18+
from issho.helpers import clean_spark_options
19+
from issho.helpers import default_sftp_path
20+
from issho.helpers import get_pkey
21+
from issho.helpers import get_user
22+
from issho.helpers import issho_pw_name
2423

2524

2625
class Issho:
@@ -198,9 +197,10 @@ def spark_submit(
198197
jars="",
199198
files="",
200199
driver_class_path="",
201-
app_class="",
200+
application_class="",
202201
application="",
203202
application_args="",
203+
bg=False,
204204
):
205205
"""
206206
Submit a spark job.
@@ -210,35 +210,45 @@ def spark_submit(
210210
:param jars: syntactic sugar for the --jars spark option
211211
:param files: syntactic sugar for the --files spark option
212212
:param driver_class_path: syntactic sugar for the --driver-class-path spark option
213-
:param app_class: syntactic sugar for the --class spark option
213+
:param application_class: syntactic sugar for the --class spark option
214214
:param application: the application to submit
215215
:param application_args: any arguments to be passed to the spark application
216+
:param bg: True to run in the background, False otherwise
216217
:return:
217218
"""
218219
assert application
219220
if not spark_options:
220221
spark_options = {}
221222
for k, v in locals().items():
222-
if k in {"spark_options", "application", "application_args"}:
223+
if k in {"spark_options", "application", "application_args", "self", "bg"}:
223224
continue
225+
clean_keys = {"application_class": "class"}
226+
clean_k = clean_keys.get(k, k)
224227
if v:
225-
spark_options[k] = v
228+
spark_options[clean_k] = v
226229

227230
cleaned_spark_options = clean_spark_options(spark_options)
228231
spark_options_str = " ".join(
229-
map(lambda k, v: "{} {}".format(k, v), cleaned_spark_options.values())
232+
(
233+
"{} {}".format(k, v)
234+
for k, v in sorted(cleaned_spark_options.items(), key=lambda x: x[0])
235+
)
230236
)
231237
spark_cmd = "spark-submit {} {} {}".format(
232238
spark_options_str, application, application_args
233239
)
234-
self.exec(spark_cmd)
240+
print(spark_cmd)
241+
self.exec(spark_cmd, bg=bg)
235242

236243
def spark(self, *args, **kwargs):
237244
"""
238245
Syntactic sugar for spark_submit
239246
"""
240247
self.spark_submit(*args, **kwargs)
241248

249+
def spark_bg(self, *args, **kwargs):
250+
self.spark_submit(bg=True, *args, **kwargs)
251+
242252
def _connect(self):
243253
"""
244254
Uses paramiko to connect to the remote specified

0 commit comments

Comments
 (0)