diff --git a/pyro/Application.py b/pyro/Application.py index ceabc155..e26c2f05 100644 --- a/pyro/Application.py +++ b/pyro/Application.py @@ -56,7 +56,8 @@ def _try_fix_input_path(input_path: str) -> str: @staticmethod def _validate_project_file(ppj: PapyrusProject): - if ppj.imports_node is None: + if ppj.imports_node is None and \ + (ppj.scripts_node is not None or ppj.folders_node is not None): Application.log.error('Cannot proceed without imports defined in project') sys.exit(1) @@ -108,7 +109,7 @@ def run(self) -> int: self._validate_project_file(ppj) - if ppj.scripts_node or ppj.folders_node or ppj.remote_paths: + if ppj.scripts_node is not None or ppj.folders_node is not None or ppj.remote_paths: ppj.try_initialize_remotes() if ppj.use_pre_import_event: @@ -161,7 +162,7 @@ def run(self) -> int: else: Application.log.error(f'Cannot create Packages because {build.compile_data.failed_count} scripts failed to compile') sys.exit(build.compile_data.failed_count) - else: + elif ppj.packages_node is not None: Application.log.info('Cannot create Packages because Package is disabled in project') if ppj.options.zip: @@ -170,15 +171,17 @@ def run(self) -> int: else: Application.log.error(f'Cannot create ZipFile because {build.compile_data.failed_count} scripts failed to compile') sys.exit(build.compile_data.failed_count) - else: + elif ppj.zip_files_node is not None: Application.log.info('Cannot create ZipFile because Zip is disabled in project') if build.scripts_count > 0: Application.log.info(build.compile_data.to_string() if build.compile_data.success_count > 0 else 'No scripts were compiled.') - Application.log.info(build.package_data.to_string() if build.package_data.file_count > 0 else 'No files were packaged.') + if ppj.packages_node is not None: + Application.log.info(build.package_data.to_string() if build.package_data.file_count > 0 else 'No files were packaged.') - Application.log.info(build.zipping_data.to_string() if build.zipping_data.file_count > 0 else 'No files were zipped.') + if ppj.zip_files_node is not None: + Application.log.info(build.zipping_data.to_string() if build.zipping_data.file_count > 0 else 'No files were zipped.') Application.log.info('DONE!') diff --git a/pyro/Enums/ZipCompression.py b/pyro/Enums/ZipCompression.py index 3177d739..7a4c8796 100644 --- a/pyro/Enums/ZipCompression.py +++ b/pyro/Enums/ZipCompression.py @@ -1,15 +1,13 @@ -from enum import Enum - - -class ZipCompression(Enum): +class ZipCompression: STORE = 0 DEFLATE = 8 + MAP = {'STORE': 0, 'DEFLATE': 8} - @classmethod - def _missing_(cls, value): + @staticmethod + def get(value: str) -> int: try: - return cls[value.upper()] + return ZipCompression.MAP[value.upper()] except KeyError: pass - raise ValueError("%r is not a valid %s" % (value, cls.__name__)) + raise ValueError("%s is not a valid key" % value.upper()) diff --git a/pyro/PackageManager.py b/pyro/PackageManager.py index f35f1f2c..8f94dd5b 100644 --- a/pyro/PackageManager.py +++ b/pyro/PackageManager.py @@ -324,13 +324,11 @@ def create_zip(self) -> None: self._check_write_permission(file_path) - try: - if self.options.zip_compression in ('store', 'deflate'): - compress_type = ZipCompression[self.options.zip_compression] - else: - compress_type = ZipCompression[zip_node.get(XmlAttributeName.COMPRESSION)] - except KeyError: - compress_type = ZipCompression.STORE + if self.options.zip_compression in ('store', 'deflate'): + compress_type = ZipCompression.get(self.options.zip_compression) + else: + compress_str = zip_node.get(XmlAttributeName.COMPRESSION) + compress_type = ZipCompression.get(compress_str) root_dir: str = self.ppj._get_path(zip_node.get(XmlAttributeName.ROOT_DIR), relative_root_path=self.ppj.project_path, @@ -340,7 +338,7 @@ def create_zip(self) -> None: PackageManager.log.info(f'Creating "{attr_file_name}"...') try: - with zipfile.ZipFile(file_path, mode='w', compression=compress_type.value) as z: + with zipfile.ZipFile(file_path, mode='w', compression=compress_type) as z: for include_path, attr_path in self._generate_include_paths(zip_node, root_dir, True): if not attr_path: if root_dir in include_path: @@ -353,7 +351,7 @@ def create_zip(self) -> None: arcname = attr_file_name if attr_path == os.curdir else os.path.join(attr_path, attr_file_name) PackageManager.log.info('+ "{}"'.format(arcname)) - z.write(include_path, arcname, compress_type=compress_type.value) + z.write(include_path, arcname, compress_type=compress_type) self.includes += 1