-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b8310c
commit 47a6a51
Showing
7 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
|
||
from igittigitt import IgnoreParser | ||
from rich.console import Console | ||
|
||
from norma2.config.config_class import Config | ||
|
||
|
||
def from_gitignore(console: Console, conf_path: str = ".") -> Config: | ||
full_path = os.path.join(conf_path, ".gitignore") | ||
full_path = os.path.abspath(full_path) | ||
parser = IgnoreParser() | ||
parser.parse_rule_file(full_path) | ||
matches = parser.match | ||
conf = Config(console) | ||
conf.gitignore_matches = matches | ||
return conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
import os | ||
from typing import List | ||
|
||
from norma2.config.config_class import GITIGNORE_MATCHES_TYPE | ||
|
||
def _can_add_file(file: str, exts: List[str], folder_out: List[str]): | ||
|
||
def _can_add_file( | ||
file: str, | ||
full_file: str, | ||
exts: List[str], | ||
folder_out: List[str], | ||
gitignore_matches: GITIGNORE_MATCHES_TYPE, | ||
): | ||
for ext in exts: | ||
if file.endswith(ext): | ||
return False | ||
splited = file.split(os.path.sep) | ||
splited = full_file.split(os.path.sep) | ||
for dirr in splited: | ||
for fold in folder_out: | ||
if dirr == fold: | ||
return False | ||
return True | ||
if gitignore_matches is None: | ||
return True | ||
return not gitignore_matches(full_file) | ||
|
||
|
||
def get_all_files( | ||
folder_or_file_path: str, | ||
folder_exclude: List[str], | ||
file_ext_exclude: List[str], | ||
gitignore_matches: GITIGNORE_MATCHES_TYPE, | ||
) -> List[str]: | ||
if os.path.isfile(folder_or_file_path): | ||
return [folder_or_file_path] | ||
if os.path.isdir(folder_or_file_path): | ||
res = [] | ||
for root, _, files in os.walk(folder_or_file_path): | ||
for file in files: | ||
if not _can_add_file(file, file_ext_exclude, folder_exclude): | ||
full_file = os.path.join(root, file) | ||
if not _can_add_file( | ||
file, full_file, file_ext_exclude, folder_exclude, gitignore_matches | ||
): | ||
continue | ||
res.append(os.path.join(root, file)) | ||
res.append(full_file) | ||
return res | ||
raise os.error(f"Invalid path: {folder_or_file_path}") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters