|
1 | | -import shutil |
2 | 1 | from pathlib import Path |
3 | 2 |
|
4 | 3 | import click |
| 4 | +import yaml |
5 | 5 | from ape import project |
6 | 6 |
|
7 | 7 | PLUGIN_MANIFEST_FOLDER = project.path / "ape_safe" / "manifests" |
8 | 8 |
|
| 9 | +VERSIONS = { |
| 10 | + "v1.1.1": """ |
| 11 | +compile: |
| 12 | + exclude: |
| 13 | + - mocks |
| 14 | + - interfaces |
| 15 | +
|
| 16 | +dependencies: |
| 17 | + - name: openzeppelin |
| 18 | + github: OpenZeppelin/openzeppelin-contracts |
| 19 | + version: 2.2.0 |
| 20 | +
|
| 21 | +solidity: |
| 22 | + version: 0.5.14 |
| 23 | + import_remapping: |
| 24 | + - "@openzeppelin/contracts=openzeppelin/v2.2.0" |
| 25 | +""", |
| 26 | + "v1.3.0": """ |
| 27 | +compile: |
| 28 | + exclude: |
| 29 | + - test |
| 30 | + - examples |
| 31 | + - interfaces |
| 32 | +
|
| 33 | +dependencies: |
| 34 | + - name: openzeppelin |
| 35 | + github: OpenZeppelin/openzeppelin-contracts |
| 36 | + version: 3.4.0 |
| 37 | +
|
| 38 | +solidity: |
| 39 | + version: 0.7.6 |
| 40 | + import_remapping: |
| 41 | + - "@openzeppelin/contracts=openzeppelin/v3.4.0" |
| 42 | +""", |
| 43 | + "v1.4.1": """ |
| 44 | +compile: |
| 45 | + exclude: |
| 46 | + - test |
| 47 | + - examples |
| 48 | + - interfaces |
| 49 | +
|
| 50 | +dependencies: |
| 51 | + - name: openzeppelin |
| 52 | + github: OpenZeppelin/openzeppelin-contracts |
| 53 | + version: 3.4.0 |
| 54 | +
|
| 55 | +solidity: |
| 56 | + version: 0.7.6 |
| 57 | + import_remapping: |
| 58 | + - "@openzeppelin/contracts=openzeppelin/v3.4.0" |
| 59 | +""", |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +def compile_version(version: str, override: bool): |
| 64 | + dependency = project.dependencies.install( |
| 65 | + name="safe-contracts", |
| 66 | + github="safe-global/safe-smart-account", |
| 67 | + version=version, |
| 68 | + config_override=yaml.safe_load(VERSIONS[version]), |
| 69 | + ) |
| 70 | + plugin_manifest_path = PLUGIN_MANIFEST_FOLDER / f"safe-{version}.json" |
| 71 | + if not override and (plugin_manifest_path).is_file(): |
| 72 | + click.echo(f"Version '{version}' already exists, skipping.'") |
| 73 | + return |
| 74 | + |
| 75 | + if not dependency.compiled: |
| 76 | + click.echo(f"Safe {version} not compiled, compiling...") |
| 77 | + dependency.compile() |
| 78 | + |
| 79 | + click.echo( |
| 80 | + f"cp $HOME/{dependency.manifest_path.relative_to(Path.home())}" |
| 81 | + f" ./{plugin_manifest_path.relative_to(Path.cwd())}" |
| 82 | + ) |
| 83 | + plugin_manifest_path.write_text(dependency.manifest_path.read_text()) |
| 84 | + |
9 | 85 |
|
10 | 86 | @click.command() |
11 | 87 | @click.option("--override", is_flag=True) |
12 | | -def cli(override): |
13 | | - for version in project.dependencies["safe-contracts"]: |
14 | | - dependency = project.dependencies["safe-contracts"][version] |
15 | | - plugin_manifest_path = PLUGIN_MANIFEST_FOLDER / f"safe-{version}.json" |
16 | | - |
17 | | - if plugin_manifest_path.is_file() and not override: |
18 | | - click.echo(f"Version '{version}' already exists, skipping.'") |
19 | | - continue |
20 | | - |
21 | | - # OK to delete - either doesn't exist or override set. |
22 | | - plugin_manifest_path.unlink(missing_ok=True) |
23 | | - |
24 | | - click.echo( |
25 | | - f"cp $HOME/{dependency.manifest_path.relative_to(Path.home())}" |
26 | | - f" ./{plugin_manifest_path.relative_to(Path.cwd())}" |
27 | | - ) |
28 | | - shutil.copyfile(dependency.manifest_path, plugin_manifest_path) |
| 88 | +@click.argument( |
| 89 | + "versions", |
| 90 | + nargs=-1, |
| 91 | + type=click.Choice(list(VERSIONS)), |
| 92 | +) |
| 93 | +def cli(override, versions): |
| 94 | + """Build manifests for Safe protocol""" |
| 95 | + |
| 96 | + for version in iter(versions or VERSIONS): |
| 97 | + compile_version(version, override) |
0 commit comments