From 1b19822a2df7ff969e3734973f131df9ed9d2ee3 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Tue, 1 Sep 2020 14:27:10 +0200 Subject: [PATCH] typing: Fix templates --- mesonbuild/templates/cpptemplates.py | 4 ++-- mesonbuild/templates/cstemplates.py | 4 ++-- mesonbuild/templates/ctemplates.py | 4 ++-- mesonbuild/templates/cudatemplates.py | 4 ++-- mesonbuild/templates/dlangtemplates.py | 4 ++-- mesonbuild/templates/fortrantemplates.py | 4 ++-- mesonbuild/templates/javatemplates.py | 4 ++-- mesonbuild/templates/mesontemplates.py | 4 +++- mesonbuild/templates/objcpptemplates.py | 4 ++-- mesonbuild/templates/objctemplates.py | 4 ++-- mesonbuild/templates/rusttemplates.py | 4 ++-- mesonbuild/templates/samplefactory.py | 4 +++- mesonbuild/templates/sampleimpl.py | 4 ++-- 13 files changed, 28 insertions(+), 24 deletions(-) diff --git a/mesonbuild/templates/cpptemplates.py b/mesonbuild/templates/cpptemplates.py index 834d95520..2d28d3a17 100644 --- a/mesonbuild/templates/cpptemplates.py +++ b/mesonbuild/templates/cpptemplates.py @@ -146,7 +146,7 @@ class CppProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.cpp' open(source_name, 'w').write(hello_cpp_template.format(project_name=self.name)) @@ -155,7 +155,7 @@ class CppProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] diff --git a/mesonbuild/templates/cstemplates.py b/mesonbuild/templates/cstemplates.py index b9b376e27..8524c97ea 100644 --- a/mesonbuild/templates/cstemplates.py +++ b/mesonbuild/templates/cstemplates.py @@ -95,7 +95,7 @@ class CSharpProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] @@ -107,7 +107,7 @@ class CSharpProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] diff --git a/mesonbuild/templates/ctemplates.py b/mesonbuild/templates/ctemplates.py index 30acef373..440731cab 100644 --- a/mesonbuild/templates/ctemplates.py +++ b/mesonbuild/templates/ctemplates.py @@ -129,7 +129,7 @@ class CProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.c' open(source_name, 'w').write(hello_c_template.format(project_name=self.name)) @@ -138,7 +138,7 @@ class CProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() function_name = lowercase_token[0:3] + '_func' diff --git a/mesonbuild/templates/cudatemplates.py b/mesonbuild/templates/cudatemplates.py index 2321011c8..4fa9a2b4e 100644 --- a/mesonbuild/templates/cudatemplates.py +++ b/mesonbuild/templates/cudatemplates.py @@ -146,7 +146,7 @@ class CudaProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.cu' open(source_name, 'w').write(hello_cuda_template.format(project_name=self.name)) @@ -155,7 +155,7 @@ class CudaProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] diff --git a/mesonbuild/templates/dlangtemplates.py b/mesonbuild/templates/dlangtemplates.py index 84e6ab0c2..4aacda8c5 100644 --- a/mesonbuild/templates/dlangtemplates.py +++ b/mesonbuild/templates/dlangtemplates.py @@ -107,7 +107,7 @@ class DlangProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.d' open(source_name, 'w').write(hello_d_template.format(project_name=self.name)) @@ -116,7 +116,7 @@ class DlangProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() function_name = lowercase_token[0:3] + '_func' diff --git a/mesonbuild/templates/fortrantemplates.py b/mesonbuild/templates/fortrantemplates.py index a4f307971..f4cae66c9 100644 --- a/mesonbuild/templates/fortrantemplates.py +++ b/mesonbuild/templates/fortrantemplates.py @@ -106,7 +106,7 @@ class FortranProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.f90' open(source_name, 'w').write(hello_fortran_template.format(project_name=self.name)) @@ -115,7 +115,7 @@ class FortranProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() function_name = lowercase_token[0:3] + '_func' diff --git a/mesonbuild/templates/javatemplates.py b/mesonbuild/templates/javatemplates.py index 211faede4..9c64743f1 100644 --- a/mesonbuild/templates/javatemplates.py +++ b/mesonbuild/templates/javatemplates.py @@ -99,7 +99,7 @@ class JavaProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] @@ -111,7 +111,7 @@ class JavaProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() class_name = uppercase_token[0] + lowercase_token[1:] diff --git a/mesonbuild/templates/mesontemplates.py b/mesonbuild/templates/mesontemplates.py index 6b341a219..68f9769b3 100644 --- a/mesonbuild/templates/mesontemplates.py +++ b/mesonbuild/templates/mesontemplates.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse + meson_executable_template = '''project('{project_name}', '{language}', version : '{version}', default_options : [{default_options}]) @@ -33,7 +35,7 @@ jar('{executable}', ''' -def create_meson_build(options): +def create_meson_build(options: argparse.Namespace) -> None: if options.type != 'executable': raise SystemExit('\nGenerating a meson.build file from existing sources is\n' 'supported only for project type "executable".\n' diff --git a/mesonbuild/templates/objcpptemplates.py b/mesonbuild/templates/objcpptemplates.py index 84299a869..f4f4b51ea 100644 --- a/mesonbuild/templates/objcpptemplates.py +++ b/mesonbuild/templates/objcpptemplates.py @@ -129,7 +129,7 @@ class ObjCppProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.mm' open(source_name, 'w').write(hello_objcpp_template.format(project_name=self.name)) @@ -138,7 +138,7 @@ class ObjCppProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() function_name = lowercase_token[0:3] + '_func' diff --git a/mesonbuild/templates/objctemplates.py b/mesonbuild/templates/objctemplates.py index 9ec4a5e11..4243024c2 100644 --- a/mesonbuild/templates/objctemplates.py +++ b/mesonbuild/templates/objctemplates.py @@ -129,7 +129,7 @@ class ObjCProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.m' open(source_name, 'w').write(hello_objc_template.format(project_name=self.name)) @@ -138,7 +138,7 @@ class ObjCProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() function_name = lowercase_token[0:3] + '_func' diff --git a/mesonbuild/templates/rusttemplates.py b/mesonbuild/templates/rusttemplates.py index c4ff53dec..6e9958694 100644 --- a/mesonbuild/templates/rusttemplates.py +++ b/mesonbuild/templates/rusttemplates.py @@ -77,7 +77,7 @@ class RustProject(SampleImpl): self.name = options.name self.version = options.version - def create_executable(self): + def create_executable(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) source_name = lowercase_token + '.rs' open(source_name, 'w').write(hello_rust_template.format(project_name=self.name)) @@ -86,7 +86,7 @@ class RustProject(SampleImpl): source_name=source_name, version=self.version)) - def create_library(self): + def create_library(self) -> None: lowercase_token = re.sub(r'[^a-z0-9]', '_', self.name.lower()) uppercase_token = lowercase_token.upper() function_name = lowercase_token[0:3] + '_func' diff --git a/mesonbuild/templates/samplefactory.py b/mesonbuild/templates/samplefactory.py index 1da2bc12d..1192e138a 100644 --- a/mesonbuild/templates/samplefactory.py +++ b/mesonbuild/templates/samplefactory.py @@ -21,9 +21,11 @@ from mesonbuild.templates.objctemplates import ObjCProject from mesonbuild.templates.cpptemplates import CppProject from mesonbuild.templates.cstemplates import CSharpProject from mesonbuild.templates.ctemplates import CProject +from mesonbuild.templates.sampleimpl import SampleImpl +import argparse -def sameple_generator(options): +def sameple_generator(options: argparse.Namespace) -> SampleImpl: return { 'c': CProject, 'cpp': CppProject, diff --git a/mesonbuild/templates/sampleimpl.py b/mesonbuild/templates/sampleimpl.py index 20ed8ab30..2d1498b83 100644 --- a/mesonbuild/templates/sampleimpl.py +++ b/mesonbuild/templates/sampleimpl.py @@ -14,8 +14,8 @@ class SampleImpl: - def create_executable(self): + def create_executable(self) -> None: raise NotImplementedError('Sample implementation for "executable" not implemented!') - def create_library(self): + def create_library(self) -> None: raise NotImplementedError('Sample implementation for "library" not implemented!')