Skip to content

Commit 12ddc22

Browse files
committed
A update on my Spark learning
A update on my Spark learning
1 parent 5fd0253 commit 12ddc22

File tree

1,478 files changed

+341860
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,478 files changed

+341860
-6
lines changed

01-HelloSpark/HelloSpark.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
if __name__ == "__main__":
77
conf = get_spark_app_config()
88

9-
spark = SparkSession \
10-
.builder \
11-
.appName("HelloSpark") \
12-
.master("local[2]") \
13-
.getOrCreate()
9+
spark = SparkSession.builder.appName("HelloSpark").master("local[2]").getOrCreate()
1410

1511
logger = Log4j(spark)
1612

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
__all__ = ["__version__"]
2+
3+
try:
4+
from ._version import version as __version__
5+
except ImportError:
6+
# broken installation, we don't even try
7+
# unknown only works because we do poor mans version compare
8+
__version__ = "unknown"
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""allow bash-completion for argparse with argcomplete if installed
2+
needs argcomplete>=0.5.6 for python 3.2/3.3 (older versions fail
3+
to find the magic string, so _ARGCOMPLETE env. var is never set, and
4+
this does not need special code.
5+
6+
Function try_argcomplete(parser) should be called directly before
7+
the call to ArgumentParser.parse_args().
8+
9+
The filescompleter is what you normally would use on the positional
10+
arguments specification, in order to get "dirname/" after "dirn<TAB>"
11+
instead of the default "dirname ":
12+
13+
optparser.add_argument(Config._file_or_dir, nargs='*'
14+
).completer=filescompleter
15+
16+
Other, application specific, completers should go in the file
17+
doing the add_argument calls as they need to be specified as .completer
18+
attributes as well. (If argcomplete is not installed, the function the
19+
attribute points to will not be used).
20+
21+
SPEEDUP
22+
=======
23+
The generic argcomplete script for bash-completion
24+
(/etc/bash_completion.d/python-argcomplete.sh )
25+
uses a python program to determine startup script generated by pip.
26+
You can speed up completion somewhat by changing this script to include
27+
# PYTHON_ARGCOMPLETE_OK
28+
so the the python-argcomplete-check-easy-install-script does not
29+
need to be called to find the entry point of the code and see if that is
30+
marked with PYTHON_ARGCOMPLETE_OK
31+
32+
INSTALL/DEBUGGING
33+
=================
34+
To include this support in another application that has setup.py generated
35+
scripts:
36+
- add the line:
37+
# PYTHON_ARGCOMPLETE_OK
38+
near the top of the main python entry point
39+
- include in the file calling parse_args():
40+
from _argcomplete import try_argcomplete, filescompleter
41+
, call try_argcomplete just before parse_args(), and optionally add
42+
filescompleter to the positional arguments' add_argument()
43+
If things do not work right away:
44+
- switch on argcomplete debugging with (also helpful when doing custom
45+
completers):
46+
export _ARC_DEBUG=1
47+
- run:
48+
python-argcomplete-check-easy-install-script $(which appname)
49+
echo $?
50+
will echo 0 if the magic line has been found, 1 if not
51+
- sometimes it helps to find early on errors using:
52+
_ARGCOMPLETE=1 _ARC_DEBUG=1 appname
53+
which should throw a KeyError: 'COMPLINE' (which is properly set by the
54+
global argcomplete script).
55+
"""
56+
import argparse
57+
import os
58+
import sys
59+
from glob import glob
60+
from typing import Any
61+
from typing import List
62+
from typing import Optional
63+
64+
65+
class FastFilesCompleter:
66+
"Fast file completer class"
67+
68+
def __init__(self, directories: bool = True) -> None:
69+
self.directories = directories
70+
71+
def __call__(self, prefix: str, **kwargs: Any) -> List[str]:
72+
"""only called on non option completions"""
73+
if os.path.sep in prefix[1:]:
74+
prefix_dir = len(os.path.dirname(prefix) + os.path.sep)
75+
else:
76+
prefix_dir = 0
77+
completion = []
78+
globbed = []
79+
if "*" not in prefix and "?" not in prefix:
80+
# we are on unix, otherwise no bash
81+
if not prefix or prefix[-1] == os.path.sep:
82+
globbed.extend(glob(prefix + ".*"))
83+
prefix += "*"
84+
globbed.extend(glob(prefix))
85+
for x in sorted(globbed):
86+
if os.path.isdir(x):
87+
x += "/"
88+
# append stripping the prefix (like bash, not like compgen)
89+
completion.append(x[prefix_dir:])
90+
return completion
91+
92+
93+
if os.environ.get("_ARGCOMPLETE"):
94+
try:
95+
import argcomplete.completers
96+
except ImportError:
97+
sys.exit(-1)
98+
filescompleter = FastFilesCompleter() # type: Optional[FastFilesCompleter]
99+
100+
def try_argcomplete(parser: argparse.ArgumentParser) -> None:
101+
argcomplete.autocomplete(parser, always_complete_options=False)
102+
103+
104+
else:
105+
106+
def try_argcomplete(parser: argparse.ArgumentParser) -> None:
107+
pass
108+
109+
filescompleter = None
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
""" python inspection/code generation API """
2+
from .code import Code # noqa
3+
from .code import ExceptionInfo # noqa
4+
from .code import filter_traceback # noqa
5+
from .code import Frame # noqa
6+
from .code import getrawcode # noqa
7+
from .code import Traceback # noqa
8+
from .source import compile_ as compile # noqa
9+
from .source import getfslineno # noqa
10+
from .source import Source # noqa

0 commit comments

Comments
 (0)