analyst.utils package¶
Submodules¶
analyst.utils.jupyformatter module¶
Format Python script downloaded from Jupyter Notebook to a clearer layout according to the rules in append_valid_line.
Example usage:
import analyst as a; a.jupyformatter() #$Or use it as a standalone file located under the same directory:
from jupyformatter import jupyformatter; jupyformatter(do_setup=True) #$Set do_deletion to False if is used to format this script itself. do_deletion will not affect #$ delete below.
Todo
- More logging information, integrated with -v verbose option in argparse.
- Implement #$ delete from, #$ delete to commands using continue in edit.
- Automatically insert current date
-
analyst.utils.jupyformatter.
append_valid_line
(output_ls, line, do_deletion)[source]¶ Append line to the list of lines for output according to customed rules.
- Called by:
- edit
- Calls:
- wrap_markdown
-
analyst.utils.jupyformatter.
clean_line
(line)[source]¶ Clean line string with customed rules.
- Arg:
- line (string)
Returns: line (string) - Called by:
- edit
-
analyst.utils.jupyformatter.
convert_heading
(input_ls)[source]¶ Convert personal standard Notebook heading to script docstring.
- Return:
- converted_input_ls (list)
- Called by:
- edit
- Calls:
- wrap_markdown
After effect: the header part of the list of lines will have one line fewer comparing to the original list.
- For example, convert the head of the script from
- to
Mar 23, 2018: note that scripts downloaded from the Linux platform have one extra blank line after `# In[d]:
`.
-
analyst.utils.jupyformatter.
edit
(input_ls, do_deletion)[source]¶ Loop over each line for editing.
- Arg:
- input_ls (list):
- a list of lines readed from the input text file.
Returns: a list of lines going to write to the output. Return type: output_ls (list) - Called by:
- main
- Calls:
- convert_heading clean_line warn_line append_valid_line
-
analyst.utils.jupyformatter.
get_notebook_name
()[source]¶ Return the name of the current jupyter notebook.
References
https://github.com/jupyter/notebook/issues/1000#issuecomment-359875246 https://stackoverflow.com/a/13055551
-
analyst.utils.jupyformatter.
in_ipynb
()[source]¶ Return True if this code is running in a Jupyter Notebook environment.
-
analyst.utils.jupyformatter.
parse_args
()[source]¶ Parse command line arguments to get input and output directories.
- Called by:
- main
-
analyst.utils.jupyformatter.
read_input
(filename)[source]¶ Given filename (directory), return a list of lines of the input text file.
-
analyst.utils.jupyformatter.
warn_line
(line, line_num, do_deletion)[source]¶ Log with customed rules.
- Called by:
- edit
-
analyst.utils.jupyformatter.
wrap_markdown
(line, wrap_at=79)[source]¶ Wrap Markdown heading/comment (starts with # `) at `wrap_at.
- Args:
- line (string) wrap_at (int, default to 79)
- Return:
- line_wrapped_ls (list): a list of line string(s) if the original
- line needs to be wrapped. Every line string in the list is a line ends with a new line character `
`.
- Called by:
- append_valid_line
analyst.utils.logging_init module¶
Setup logging module’s configuration for Jupyter notebook or iPython environment.
- Example usage:
- import logging from utils import logging_init
-
analyst.utils.logging_init.
config_logging
(level='info', format_='%(asctime)s [%(levelname)s] %(message)s', datefmt='%H:%M')[source]¶ Parameters: level (str, in {‘debug’, ‘info’, ‘warning’, ‘error’, ‘critical’})
-
analyst.utils.logging_init.
in_ipynb
()[source]¶ Return True if this code is running in a Jupyter Notebook environment.