Skip to content

Commit

Permalink
#2 Remove __pycache__ before rendering a template
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCapponi committed Mar 8, 2023
1 parent 094cf59 commit d2fd267
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ directory = coverage
[report]
exclude_lines =
if TYPE_CHECKING:
if dirname == "__pycache__":
9 changes: 8 additions & 1 deletion socon/core/management/templates.py
Original file line number Diff line number Diff line change
@@ -60,14 +60,21 @@ def handle(self, config: Config, name: str, target: Optional[str] = None) -> Non

template_dir = Path(socon.__path__[0], "conf", base_subdir)

for root, _, files in os.walk(template_dir):
for root, dirs, files in os.walk(template_dir):
relative_dir = str(Path(root).relative_to(template_dir))
relative_dir = relative_dir.replace(base_name, name)

# Make the target directory
target_dir = Path(top_dir, relative_dir)
os.makedirs(target_dir, exist_ok=True)

for dirname in dirs[:]:
# Remove __pycache__ as it's possible that when we execute a template
# command we try to read it's content with FileReshape. This might
# cause in the worst case a decode error.
if dirname == "__pycache__":
dirs.remove(dirname)

for filename in files:
old_path = Path(root, filename)
new_path = Path(top_dir, relative_dir, filename)

0 comments on commit d2fd267

Please sign in to comment.