(#13331) [docs] Apply python black formatter over recipe templates

* Apply python black

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Update to 120 chars

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Update to 120 chars

Signed-off-by: Uilian Ries <uilianries@gmail.com>

Signed-off-by: Uilian Ries <uilianries@gmail.com>
This commit is contained in:
Uilian Ries
2022-10-06 18:24:15 +02:00
committed by GitHub
parent 47bac9d8b8
commit 9cd0fcbc34
6 changed files with 103 additions and 61 deletions

View File

@@ -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-file-name>"
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

View File

@@ -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-file-name>"
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"))

View File

@@ -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-file-name>"
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

View File

@@ -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-file-name>"
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"]

View File

@@ -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):

View File

@@ -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")