Skip to content

Commit

Permalink
fix(tdk): Fix TDK watch mode errors after descriptor change
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Jan 18, 2024
1 parent 8b7c522 commit 0753ae9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/dsw-tdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix `watch` mode errors after descriptor change


## [4.2.1]

Expand Down
2 changes: 0 additions & 2 deletions packages/dsw-tdk/dsw/tdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,6 @@ def extract_package(ctx, template_package, output, force: bool):
force=force,
)
except Exception as e:
import traceback
traceback.print_exc()
ClickPrinter.failure('Failed to extract the package')
ClickPrinter.error(f'> {e}')
exit(1)
Expand Down
9 changes: 7 additions & 2 deletions packages/dsw-tdk/dsw/tdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
ChangeItem = Tuple[watchfiles.Change, pathlib.Path]


def _change(item: ChangeItem, root: pathlib.Path) -> str:
return f'{item[0].name.upper()}[{item[1].relative_to(root).as_posix()}]'


class TDKProcessingError(RuntimeError):

def __init__(self, message: str, hint: str):
Expand Down Expand Up @@ -267,7 +271,7 @@ async def _create_template_file(self, tfile: TemplateFile, project_update: bool
if project_update and result is not None:
self.safe_project.update_template_file(result)
except Exception as e:
self.logger.error(f'Failed to store remote {tfile.remote_type.value} {tfile.filename.as_posix()}: {e}')
self.logger.error(f'Failed to store remote {tfile.remote_type.value} {tfile.filename.as_posix()}: {str(e)}')

async def store_remote_files(self):
for tfile in self.safe_project.safe_template.files.values():
Expand Down Expand Up @@ -471,7 +475,7 @@ async def _process_file_changes(self):
deleted = set()
updated = set()
for file_change in self.file_changes:
self.tdk.logger.debug(f'Processing {file_change}')
self.tdk.logger.debug(f'Processing: {_change(file_change, self.tdk.safe_project.template_dir)}')
change_type = file_change[0]
filepath = file_change[1]
if change_type == watchfiles.Change.deleted and filepath not in deleted:
Expand Down Expand Up @@ -514,6 +518,7 @@ async def _update_descriptor(self):
if self.readme_change is not None or self.descriptor_change is not None:
self.tdk.logger.debug('Updating template descriptor (metadata)')
await self.tdk._update_descriptor()
self.tdk.safe_project.template = self.tdk.safe_template

async def process_changes(self, changes: List[ChangeItem], force: bool):
self._split_changes(changes)
Expand Down

0 comments on commit 0753ae9

Please sign in to comment.