From 1bf04481c0761cdce2a326d1dab9c11238d6a870 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 11 Mar 2023 11:04:59 +0100 Subject: [PATCH 1/3] Bugfix reverse command and binary files --- manageprojects/cookiecutter_generator.py | 17 ++++++++++++----- pyproject.toml | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/manageprojects/cookiecutter_generator.py b/manageprojects/cookiecutter_generator.py index bd5058a..fb933b0 100644 --- a/manageprojects/cookiecutter_generator.py +++ b/manageprojects/cookiecutter_generator.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from bx_py_utils.path import assert_is_dir @@ -46,12 +47,18 @@ def copy_replaced(src_path, dst_path, reverse_info): dst_parent = dst_path.parent dst_parent.mkdir(parents=True, exist_ok=True) - content = src_path.read_text(encoding='UTF-8') - - for src_str, dst_str in reverse_info: - content = content.replace(src_str, dst_str) + try: + content = src_path.read_text(encoding='UTF-8') + except UnicodeDecodeError as err: + # XXX: Detect binary files in a other way + print(f'[yellow]Warning: {err} for file {src_path}') + print('copy as binary file') + shutil.copy2(src_path, dst_path) + else: + for src_str, dst_str in reverse_info: + content = content.replace(src_str, dst_str) - dst_path.write_text(content, encoding='UTF-8') + dst_path.write_text(content, encoding='UTF-8') def create_cookiecutter_template( diff --git a/pyproject.toml b/pyproject.toml index 10abb06..3b1b974 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "manageprojects" -version = "0.9.4" +version = "0.9.5" description = "Manage Python / Django projects" readme = "README.md" authors = [ From e033c3ac2c37cb8a75dafceaaa697c5bb4d73113 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sun, 12 Mar 2023 19:15:04 +0100 Subject: [PATCH 2/3] Fix #68 Handle if there are no git tags while publishing --- .../tests/test_utilities_publish.py | 21 +++++++++++++++++++ manageprojects/utilities/publish.py | 9 +++++--- pyproject.toml | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/manageprojects/tests/test_utilities_publish.py b/manageprojects/tests/test_utilities_publish.py index 8853c61..753d120 100644 --- a/manageprojects/tests/test_utilities_publish.py +++ b/manageprojects/tests/test_utilities_publish.py @@ -88,6 +88,27 @@ def test_get_pyproject_toml_version(self): version = get_pyproject_toml_version(temp_path) self.assertEqual(version, Version('2.3')) + def test_publisher_fast_checks_not_existing_tag(self): + # https://github.com/jedie/manageprojects/issues/68 + with AssertLogs(self, loggers=('manageprojects',)), TemporaryDirectory( + prefix='test_publisher_fast_checks_not_existing_tag' + ) as temp_path: + Path(temp_path, '1.txt').touch() + init_git(temp_path, comment='The initial commit ;)') + + pgit = PublisherGit( + package_path=temp_path, + version=Version('0.0.1'), + possible_branch_names=('main',), + tag_msg_log_format='%s', + ) + self.assertIs(pgit.git_tag_msg, None) + pgit.fast_checks() + self.assertEqual( + pgit.git_tag_msg, + 'publish version v0.0.1 with these changes:\n\n * The initial commit ;)\n', + ) + def test_publisher_git(self): with AssertLogs(self, loggers=('manageprojects',)), TemporaryDirectory( prefix='test_publisher_git' diff --git a/manageprojects/utilities/publish.py b/manageprojects/utilities/publish.py index c140a93..7b42967 100644 --- a/manageprojects/utilities/publish.py +++ b/manageprojects/utilities/publish.py @@ -102,9 +102,12 @@ def fast_checks(self): change_msg = '\n'.join(f' * {line}' for line in log_lines) print('done:') print(change_msg) - self.git_tag_msg = ( - f'publish version v{self.version} with these changes (since {last_tag.version_tag}):\n\n{change_msg}\n' - ) + if last_tag: + self.git_tag_msg = ( + f'publish version v{self.version} with these changes (since {last_tag.version_tag}):\n\n{change_msg}\n' + ) + else: + self.git_tag_msg = f'publish version v{self.version} with these changes:\n\n{change_msg}\n' def slow_checks(self): print('\nLocal repository up-to-date: fetch origin...', end='') diff --git a/pyproject.toml b/pyproject.toml index 3b1b974..f0dbcc0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "manageprojects" -version = "0.9.5" +version = "0.9.6" description = "Manage Python / Django projects" readme = "README.md" authors = [ From 8a1edd5387d2d16de1d7c23dd7ff8e81ad9c7c10 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sun, 12 Mar 2023 20:14:56 +0100 Subject: [PATCH 3/3] Speedup: Install as editable with '--no-deps' because pip-sync has already installed all needed packages ;) --- cli.py | 2 +- manageprojects/cli/cli_app.py | 2 +- manageprojects/tests/test_cli.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli.py b/cli.py index 9eaee29..f84fdab 100755 --- a/cli.py +++ b/cli.py @@ -101,7 +101,7 @@ def main(argv): verbose_check_call(PIP_SYNC_PATH, str(DEP_LOCK_PATH)) # install project - verbose_check_call(PIP_PATH, 'install', '-e', '.') + verbose_check_call(PIP_PATH, 'install', '--no-deps', '-e', '.') store_dep_hash() # Call our entry point CLI: diff --git a/manageprojects/cli/cli_app.py b/manageprojects/cli/cli_app.py index 88bc09e..f7421e6 100644 --- a/manageprojects/cli/cli_app.py +++ b/manageprojects/cli/cli_app.py @@ -97,7 +97,7 @@ def install(): Run pip-sync and install 'manageprojects' via pip as editable. """ verbose_check_call('pip-sync', PACKAGE_ROOT / 'requirements.dev.txt') - verbose_check_call('pip', 'install', '-e', '.') + verbose_check_call('pip', 'install', '--no-deps', '-e', '.') cli.add_command(install) diff --git a/manageprojects/tests/test_cli.py b/manageprojects/tests/test_cli.py index d663742..1d7b123 100644 --- a/manageprojects/tests/test_cli.py +++ b/manageprojects/tests/test_cli.py @@ -80,6 +80,6 @@ def test_install(self): call_mock.get_popenargs(rstrip_paths=(PY_BIN_PATH,)), [ ['.../pip-sync', f'{PACKAGE_ROOT}/requirements.dev.txt'], - ['.../pip', 'install', '-e', '.'], + ['.../pip', 'install', '--no-deps', '-e', '.'], ], )