Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .git folder exclusion and file counter #7

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
20 changes: 11 additions & 9 deletions scitree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
import seedir as sd

from scitree.styling import DATA_COLOR
from scitree.styling import README_COLOR
from scitree.styling import SCRIPT_COLOR
from scitree.styling import FIGURE_COLOR
from scitree.styling import SERIAL_COLOR
from scitree.styling import DATA_ICON
from scitree.styling import README_ICON
from scitree.styling import SCRIPT_ICON
from scitree.styling import FIGURE_COLOR
from scitree.styling import FIGURE_ICON
from scitree.styling import FOLDER_ICON
from scitree.styling import README_COLOR
from scitree.styling import README_ICON
from scitree.styling import SCRIPT_COLOR
from scitree.styling import SCRIPT_ICON
from scitree.styling import SERIAL_COLOR
from scitree.styling import SERIAL_ICON

from scitree.styling import natsort_scitree_style


def _file_count(d, n_files=0, n_folders=0, mask=None, exclude_folders=[]):

for f in Path(d).iterdir():

if mask is None or not mask(str(f)):
if mask is None or mask(str(f)):
if f.is_file():
n_files += 1
else:
Expand All @@ -47,7 +46,7 @@ def scitree(
formatter=natsort_scitree_style,
gitignore=True,
first="files",
exclude_folders=[".git"],
exclude_folders=[],
icons=False,
**kwargs
):
Expand All @@ -56,6 +55,9 @@ def scitree(
gi_matcher = gitignorefile.parse(Path(p, ".gitignore"))

def gi_mask(x):
for f in exclude_folders:
if x == str(Path(p).absolute()) + "\\" + f:
return False
return not gi_matcher(x)

else:
Expand Down