From 9cd0fcbc3478749ed78fd2ab510c20a2b2648b94 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Thu, 6 Oct 2022 18:24:15 +0200 Subject: [PATCH] (#13331) [docs] Apply python black formatter over recipe templates * Apply python black Signed-off-by: Uilian Ries * Update to 120 chars Signed-off-by: Uilian Ries * Update to 120 chars Signed-off-by: Uilian Ries Signed-off-by: Uilian Ries --- .../autotools_package/all/conanfile.py | 28 +++++++---- .../cmake_package/all/conanfile.py | 43 ++++++++++------- .../header_only/all/conanfile.py | 26 ++++++---- .../msbuild_package/all/conanfile.py | 48 +++++++++++-------- .../prebuilt_tool_package/all/conanfile.py | 15 ++++-- .../all/test_package/conanfile.py | 4 +- 6 files changed, 103 insertions(+), 61 deletions(-) diff --git a/docs/package_templates/autotools_package/all/conanfile.py b/docs/package_templates/autotools_package/all/conanfile.py index 6f71bb9b45..4bb09b1419 100644 --- a/docs/package_templates/autotools_package/all/conanfile.py +++ b/docs/package_templates/autotools_package/all/conanfile.py @@ -10,14 +10,21 @@ import os required_conan_version = ">=1.52.0" +# +# INFO: Please, remove all comments before pushing your PR! +# + class PackageConan(ConanFile): name = "package" description = "short description" - license = "" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # In case not listed there, use "LicenseRef-" + license = "" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/project/package" - topics = ("topic1", "topic2", "topic3") # no "conan" and project name in topics + # no "conan" and project name in topics. Use topics from the upstream listed on GH + topics = ("topic1", "topic2", "topic3") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -42,23 +49,27 @@ class PackageConan(ConanFile): def configure(self): if self.options.shared: try: - del self.options.fPIC # once removed by config_options, need try..except for a second del + # once removed by config_options, need try..except for a second del + del self.options.fPIC except Exception: pass + # for plain C projects only try: - del self.settings.compiler.libcxx # for plain C projects only + del self.settings.compiler.libcxx except Exception: pass try: - del self.settings.compiler.cppstd # for plain C projects only + del self.settings.compiler.cppstd except Exception: pass def layout(self): - basic_layout(self, src_folder="src") # src_folder must use the same source folder name the project + # src_folder must use the same source folder name the project + basic_layout(self, src_folder="src") def requirements(self): - self.requires("dependency/0.8.1") # prefer self.requires method instead of requires attribute + # prefer self.requires method instead of requires attribute + self.requires("dependency/0.8.1") if self.options.with_foobar: self.requires("foobar/0.1.0") @@ -75,8 +86,7 @@ class PackageConan(ConanFile): self.tool_requires("pkgconf/x.y.z") def source(self): - get(self, **self.conan_data["sources"][self.version], - destination=self.source_folder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def generate(self): # autotools usually uses 'yes' and 'no' to enable/disable options diff --git a/docs/package_templates/cmake_package/all/conanfile.py b/docs/package_templates/cmake_package/all/conanfile.py index 9f605b9822..d9603ad628 100644 --- a/docs/package_templates/cmake_package/all/conanfile.py +++ b/docs/package_templates/cmake_package/all/conanfile.py @@ -11,14 +11,21 @@ import os required_conan_version = ">=1.52.0" +# +# INFO: Please, remove all comments before pushing your PR! +# + class PackageConan(ConanFile): name = "package" description = "short description" - license = "" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # In case not listed there, use "LicenseRef-" + license = "" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/project/package" - topics = ("topic1", "topic2", "topic3") # no "conan" and project name in topics + # no "conan" and project name in topics. Use topics from the upstream listed on GH + topics = ("topic1", "topic2", "topic3") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -54,23 +61,27 @@ class PackageConan(ConanFile): def configure(self): if self.options.shared: try: - del self.options.fPIC # once removed by config_options, need try..except for a second del + # once removed by config_options, need try..except for a second del + del self.options.fPIC except Exception: pass + # for plain C projects only try: - del self.settings.compiler.libcxx # for plain C projects only + del self.settings.compiler.libcxx except Exception: pass try: - del self.settings.compiler.cppstd # for plain C projects only + del self.settings.compiler.cppstd except Exception: pass def layout(self): - cmake_layout(self, src_folder="src") # src_folder must use the same source folder name the project + # src_folder must use the same source folder name the project + cmake_layout(self, src_folder="src") def requirements(self): - self.requires("dependency/0.8.1") # prefer self.requires method instead of requires attribute + # prefer self.requires method instead of requires attribute + self.requires("dependency/0.8.1") def validate(self): # validate the minimum cpp standard supported. For C++ projects only @@ -80,7 +91,9 @@ class PackageConan(ConanFile): if not is_msvc(self): minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False) if minimum_version and Version(self.info.settings.compiler.version) < minimum_version: - raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._minimum_cpp_standard}, which your compiler does not support.") + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._minimum_cpp_standard}, which your compiler does not support." + ) # in case it does not work in another configuration, it should validated here too if is_msvc(self) and self.info.options.shared: raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") @@ -90,8 +103,7 @@ class PackageConan(ConanFile): self.tool_requires("tool/x.y.z") def source(self): - get(self, **self.conan_data["sources"][self.version], - destination=self.source_folder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def generate(self): # BUILD_SHARED_LIBS and POSITION_INDEPENDENT_CODE are automatically parsed when self.options.shared or self.options.fPIC exist @@ -116,15 +128,10 @@ class PackageConan(ConanFile): apply_conandata_patches(self) # remove bundled xxhash rm(self, "whateer.*", os.path.join(self.source_folder, "lib")) - replace_in_file( - self, - os.path.join(self.source_folder, "CMakeLists.txt"), - "...", - "", - ) + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "...", "") def build(self): - self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed + self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed cmake = CMake(self) cmake.configure() cmake.build() @@ -138,7 +145,7 @@ class PackageConan(ConanFile): rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) rmdir(self, os.path.join(self.package_folder, "share")) - rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) diff --git a/docs/package_templates/header_only/all/conanfile.py b/docs/package_templates/header_only/all/conanfile.py index 96ae97d1ec..51cc820f18 100644 --- a/docs/package_templates/header_only/all/conanfile.py +++ b/docs/package_templates/header_only/all/conanfile.py @@ -13,12 +13,16 @@ required_conan_version = ">=1.52.0" class PackageConan(ConanFile): name = "package" description = "short description" - license = "" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # In case not listed there, use "LicenseRef-" + license = "" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/project/package" - topics = ("topic1", "topic2", "topic3", "header-only") # no "conan" and project name in topics, keep 'header-only' - settings = "os", "arch", "compiler", "build_type" # even for header only - no_copy_source = True # do not copy sources to build folder for header only projects, unless, need to apply patches + # no "conan" and project name in topics. Use topics from the upstream listed on GH + # Keep 'hearder-only' as topic + topics = ("topic1", "topic2", "topic3", "header-only") + settings = "os", "arch", "compiler", "build_type" # even for header only + no_copy_source = True # do not copy sources to build folder for header only projects, unless, need to apply patches @property def _minimum_cpp_standard(self): @@ -59,7 +63,9 @@ class PackageConan(ConanFile): check_min_cppstd(self, self._minimum_cpp_standard) minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False) if minimum_version and Version(self.info.settings.get_safe("compiler.version")) < minimum_version: - raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._minimum_cpp_standard}, which your compiler does not support.") + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._minimum_cpp_standard}, which your compiler does not support." + ) # in case it does not work in another configuration, it should validated here too if self.info.settings.os == "Windows": raise ConanInvalidConfiguration(f"{self.ref} can not be used on Windows.") @@ -70,8 +76,7 @@ class PackageConan(ConanFile): def source(self): # download source package and extract to source folder - get(self, **self.conan_data["sources"][self.version], - destination=self.source_folder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) # not mandatory when there is no patch, but will suppress warning message about missing build() method def build(self): @@ -81,7 +86,12 @@ class PackageConan(ConanFile): # copy all files to the package folder def package(self): copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) - copy(self, pattern="*.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self.source_folder, "include")) + copy( + self, + pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include"), + ) def package_info(self): # folders not used for header-only diff --git a/docs/package_templates/msbuild_package/all/conanfile.py b/docs/package_templates/msbuild_package/all/conanfile.py index cc1c13ec4b..5954e93a40 100644 --- a/docs/package_templates/msbuild_package/all/conanfile.py +++ b/docs/package_templates/msbuild_package/all/conanfile.py @@ -12,10 +12,13 @@ required_conan_version = ">=1.52.0" class PackageConan(ConanFile): name = "package" description = "short description" - license = "" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # In case not listed there, use "LicenseRef-" + license = "" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/project/package" - topics = ("topic1", "topic2", "topic3") # no "conan" and project name in topics + # no "conan" and project name in topics. Use topics from the upstream listed on GH + topics = ("topic1", "topic2", "topic3") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -38,23 +41,27 @@ class PackageConan(ConanFile): def configure(self): if self.options.shared: try: - del self.options.fPIC # once removed by config_options, need try..except for a second del + # once removed by config_options, need try..except for a second del + del self.options.fPIC except Exception: pass + # for plain C projects only try: - del self.settings.compiler.libcxx # for plain C projects only + del self.settings.compiler.libcxx except Exception: pass try: - del self.settings.compiler.cppstd # for plain C projects only + del self.settings.compiler.cppstd except Exception: pass def layout(self): - vs_layout(self, src_folder="src") # src_folder must use the same source folder name the project + # src_folder must use the same source folder name the project + vs_layout(self, src_folder="src") def requirements(self): - self.requires("dependency/0.8.1") # prefer self.requires method instead of requires attribute + # prefer self.requires method instead of requires attribute + self.requires("dependency/0.8.1") def validate(self): # in case it does not work in another configuration, it should validated here too @@ -66,8 +73,7 @@ class PackageConan(ConanFile): self.tool_requires("tool/x.y.z") def source(self): - get(self, **self.conan_data["sources"][self.version], - destination=self.source_folder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def generate(self): tc = MSBuildToolchain(self) @@ -81,15 +87,10 @@ class PackageConan(ConanFile): apply_conandata_patches(self) # remove bundled xxhash rm(self, "whateer.*", os.path.join(self.source_folder, "lib")) - replace_in_file( - self, - os.path.join(self.source_folder, "CMakeLists.txt"), - "...", - "", - ) + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "...", "") def build(self): - self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed + self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed msbuild = MSBuild(self) # customize to Release when RelWithDebInfo msbuild.build_type = "Debug" if self.settings.build_type == "Debug" else "Release" @@ -100,9 +101,18 @@ class PackageConan(ConanFile): def package(self): copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) - copy(self, pattern="*.lib", dst=os.path.join(self.package_folder, "lib"), src=self.build_folder, keep_path=False) - copy(self, pattern="*.dll", dst=os.path.join(self.package_folder, "bin"), src=self.build_folder, keep_path=False) - copy(self, pattern="*.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self.source_folder, "include")) + copy( + self, pattern="*.lib", dst=os.path.join(self.package_folder, "lib"), src=self.build_folder, keep_path=False + ) + copy( + self, pattern="*.dll", dst=os.path.join(self.package_folder, "bin"), src=self.build_folder, keep_path=False + ) + copy( + self, + pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include"), + ) def package_info(self): self.cpp_info.libs = ["package_lib"] diff --git a/docs/package_templates/prebuilt_tool_package/all/conanfile.py b/docs/package_templates/prebuilt_tool_package/all/conanfile.py index b4b3859fcb..92e54d11b0 100644 --- a/docs/package_templates/prebuilt_tool_package/all/conanfile.py +++ b/docs/package_templates/prebuilt_tool_package/all/conanfile.py @@ -11,11 +11,12 @@ required_conan_version = ">=1.47.0" class PackageConan(ConanFile): name = "package" description = "short description" - license = "" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + license = "" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/project/package" - topics = ("topic1", "topic2", "topic3", "pre-built") # no "conan" and project name in topics. Use "pre-built" for tooling packages - settings = "os", "arch", "compiler", "build_type" # even for pre-built executables + # no "conan" and project name in topics. Use "pre-built" for tooling packages + topics = ("topic1", "topic2", "topic3", "pre-built") + settings = "os", "arch", "compiler", "build_type" # even for pre-built executables # not needed but supress warning message from conan commands def layout(self): @@ -37,8 +38,12 @@ class PackageConan(ConanFile): # download the source here, than copy to package folder def build(self): - get(self, **self.conan_data["sources"][self.version][str(self.settings.os)][str(self.settings.arch)], - destination=self.source_folder, strip_root=True) + get( + self, + **self.conan_data["sources"][self.version][str(self.settings.os)][str(self.settings.arch)], + destination=self.source_folder, + strip_root=True, + ) # copy all needed files to the package folder def package(self): diff --git a/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py b/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py index b84c922d41..74e84fd251 100644 --- a/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py +++ b/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py @@ -5,7 +5,7 @@ from conan.tools.build import can_run # It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "VirtualRunEnv" + generators = "VirtualBuildEnv" test_type = "explicit" def build_requirements(self): @@ -15,4 +15,4 @@ class TestPackageConan(ConanFile): if can_run(self): # self.run checks the command exit code # the tool must be available on PATH - self.run("tool --version", env="conanrun") + self.run("tool --version")