diff --git a/MANIFEST.in b/MANIFEST.in index fae74cbef848f98af068068a6563691294b63e09..95e8138ee3b2af9906bbe9d462baee1728cddae6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include LICENSE include README.md include CONTRIBUTORS.md -include snakehouse/templates/*.mako include requirements.txt diff --git a/snakehouse/requirements.py b/snakehouse/requirements.py index 4fce3ee9ae33f7b9a0cd17cd7affc0de62c4e859..dd317fd23e80f9911212a3f6c584cd4223cbd1f3 100644 --- a/snakehouse/requirements.py +++ b/snakehouse/requirements.py @@ -1,7 +1,7 @@ import typing as tp import warnings -from satella.files import read_lines, find_files +from .satella import read_lines, find_files def find_pyx(directory_path: str) -> tp.List[str]: diff --git a/snakehouse/satella.py b/snakehouse/satella.py index 636288a42183ca5f185154492d5bf7b641f1e8a3..08036443f656e68412a296f8126fe5a392895209 100644 --- a/snakehouse/satella.py +++ b/snakehouse/satella.py @@ -67,6 +67,23 @@ def find_files(path: str, wildcard: str = r'(.*)', if re.match(wildcard, fn_path): yield _cond_join(prefix_with, filename) +def read_lines(path: str, delete_empty_lines: bool = True, + encoding: str = 'utf-8') -> tp.List[str]: + """ + Read lines from a particular file, removing end-of-line characters and optionally + empty lines. Additionally whitespaces (and end-of-line characters) will be removed + from both ends of each line. + + :param path: path of file to read + :param delete_empty_lines: set to False if empty lines are not to be removed + :param encoding: encoding to read the file with + :return: each line as a separate entry + """ + with codecs.open(path, 'r', encoding) as f_in: + lines = [line.strip() for line in f_in.readlines()] + if delete_empty_lines: + lines = [line for line in lines if line] + return lines def split(path: str) -> tp.List[str]: """