|
| 1 | +from tomlkit import parse |
| 2 | + |
| 3 | +from pathlib import Path as _Path |
| 4 | +from conans.client.conan_api import ConanAPIV1 as _ConanAPI |
| 5 | + |
| 6 | + |
| 7 | +class SynodicPlugin: |
| 8 | + |
| 9 | + data = None |
| 10 | + generators = ["cmake_find_package", "cmake_paths"] |
| 11 | + |
| 12 | + def __init__(self): |
| 13 | + """ |
| 14 | + TODO: Remove hardcoded extraction once poetry has plugin support |
| 15 | + """ |
| 16 | + |
| 17 | + if not SynodicPlugin.data: |
| 18 | + with open("pyproject.toml", "r") as file: |
| 19 | + SynodicPlugin.data = parse(file.read()) |
| 20 | + |
| 21 | + # Generate the conanfile.py |
| 22 | + self.__write_conanfile( |
| 23 | + _Path(SynodicPlugin.data["tool"]["conan"]["install-path"]) |
| 24 | + ) |
| 25 | + |
| 26 | + def __write_conanfile(self, path: _Path): |
| 27 | + """ |
| 28 | + Generate a conanfile.py with the given path. |
| 29 | + The resulting recipe is TODO |
| 30 | + """ |
| 31 | + path = path.absolute() |
| 32 | + path.mkdir(parents=True, exist_ok=True) |
| 33 | + with open(path / "conanfile.py", "w+") as file: |
| 34 | + |
| 35 | + # Process the Conan data into a Conan format |
| 36 | + name = SynodicPlugin.data["tool"]["poetry"]["name"] |
| 37 | + name = name.replace("-", "") |
| 38 | + |
| 39 | + dependencies = [ |
| 40 | + "/".join(tup) |
| 41 | + for tup in SynodicPlugin.data["tool"]["conan"]["dependencies"].items() |
| 42 | + ] |
| 43 | + dependencies = ",".join('"{0}"'.format(w) for w in dependencies) |
| 44 | + |
| 45 | + generators = ",".join('"{0}"'.format(g) for g in SynodicPlugin.generators) |
| 46 | + |
| 47 | + # Write the Conan data to file |
| 48 | + contents = ( |
| 49 | + f"from conans import ConanFile, CMake\n" |
| 50 | + f"\n" |
| 51 | + f"class {name}Conan(ConanFile):\n" |
| 52 | + f' settings = "os", "compiler", "build_type", "arch"\n' |
| 53 | + f" requires = {dependencies}\n" |
| 54 | + f" generators = {generators}\n" |
| 55 | + ) |
| 56 | + |
| 57 | + print(contents, file=file) |
| 58 | + |
| 59 | + def poetry_new(self): |
| 60 | + |
| 61 | + pass |
| 62 | + |
| 63 | + def poetry_init(self): |
| 64 | + |
| 65 | + pass |
| 66 | + |
| 67 | + def poetry_install(self): |
| 68 | + |
| 69 | + _ConanAPI().install( |
| 70 | + path=SynodicPlugin.data["tool"]["conan"]["install-path"], |
| 71 | + name=SynodicPlugin.data["tool"]["poetry"]["name"], |
| 72 | + version=SynodicPlugin.data["tool"]["poetry"]["version"], |
| 73 | + user=None, |
| 74 | + channel=None, |
| 75 | + settings=None, |
| 76 | + options=None, |
| 77 | + env=None, |
| 78 | + remote_name=SynodicPlugin.data["tool"]["conan"]["remotes"], |
| 79 | + verify=None, |
| 80 | + manifests=None, |
| 81 | + manifests_interactive=None, |
| 82 | + build=None, |
| 83 | + profile_names=None, |
| 84 | + update=False, |
| 85 | + generators=None, |
| 86 | + no_imports=False, |
| 87 | + install_folder=SynodicPlugin.data["tool"]["conan"]["install-path"], |
| 88 | + cwd=_Path().absolute(), |
| 89 | + lockfile=None, |
| 90 | + ) |
| 91 | + |
| 92 | + def poetry_update(self): |
| 93 | + |
| 94 | + _ConanAPI().install( |
| 95 | + path=SynodicPlugin.data["tool"]["conan"]["install-path"], |
| 96 | + name=SynodicPlugin.data["tool"]["poetry"]["name"], |
| 97 | + version=SynodicPlugin.data["tool"]["poetry"]["version"], |
| 98 | + user=None, |
| 99 | + channel=None, |
| 100 | + settings=None, |
| 101 | + options=None, |
| 102 | + env=None, |
| 103 | + remote_name=SynodicPlugin.data["tool"]["conan"]["remotes"], |
| 104 | + verify=None, |
| 105 | + manifests=None, |
| 106 | + manifests_interactive=None, |
| 107 | + build=None, |
| 108 | + profile_names=None, |
| 109 | + update=True, |
| 110 | + generators=None, |
| 111 | + no_imports=False, |
| 112 | + install_folder=SynodicPlugin.data["tool"]["conan"]["install-path"], |
| 113 | + cwd=_Path().absolute(), |
| 114 | + lockfile=None, |
| 115 | + ) |
| 116 | + |
| 117 | + def poetry_add(self): |
| 118 | + |
| 119 | + pass |
| 120 | + |
| 121 | + def poetry_remove(self): |
| 122 | + |
| 123 | + pass |
| 124 | + |
| 125 | + def poetry_show(self): |
| 126 | + |
| 127 | + pass |
| 128 | + |
| 129 | + def poetry_build(self): |
| 130 | + |
| 131 | + pass |
| 132 | + |
| 133 | + def poetry_publish(self): |
| 134 | + self.__init_data() |
| 135 | + |
| 136 | + _ConanAPI().export() |
| 137 | + |
| 138 | + def poetry_config(self): |
| 139 | + |
| 140 | + pass |
| 141 | + |
| 142 | + def poetry_check(self): |
| 143 | + """ |
| 144 | + Validate the conan entries |
| 145 | + """ |
| 146 | + |
| 147 | + pass |
| 148 | + |
| 149 | + def poetry_search(self): |
| 150 | + |
| 151 | + pass |
| 152 | + |
| 153 | + def poetry_lock(self): |
| 154 | + |
| 155 | + pass |
| 156 | + |
| 157 | + def poetry_version(self): |
| 158 | + |
| 159 | + pass |
| 160 | + |
| 161 | + def poetry_export(self): |
| 162 | + |
| 163 | + pass |
| 164 | + |
| 165 | + def poetry_env(self): |
| 166 | + |
| 167 | + pass |
0 commit comments