Skip to content

Commit

Permalink
fix: import clash between dependency and relative path (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 9, 2024
1 parent 961ca03 commit 7bea8bb
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ape_solidity/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def _resolve_source(
self._resolve_path(reference, project)

def _resolve_import_remapping(self, project: ProjectManager):
if self.value.startswith("."):
# Relative paths should not use import-remappings.
return

import_remapping = self.solidity._import_remapping_cache[project]

# Get all matches.
Expand Down
2 changes: 2 additions & 0 deletions tests/ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dependencies:
ref: master

# Ensure NPM dependencies work.
# NOTE: Do not change this dependency; it is also
# part of other tests. See `./safe/ThisIsNotGnosisSafe.sol`.
- name: safe
npm: "@gnosis.pm/safe-contracts"
version: 1.3.0
Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/BuiltinErrorChecker.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

contract BuiltinErrorChecker {
Expand Down
2 changes: 2 additions & 0 deletions tests/contracts/Imports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import "@noncompilingdependency/CompilingContract.sol";
import "@noncompilingdependency/CompilingContract.sol";

import "@safe/contracts/common/Enum.sol";
// Show we can import a local contract with the same name (sin-@) as a dependency.
import "./safe/ThisIsNotGnosisSafe.sol";

// Purposely exclude the contracts folder to test older Ape-style project imports.
import "@noncompilingdependency/subdir/SubCompilingContract.sol";
Expand Down
5 changes: 5 additions & 0 deletions tests/contracts/safe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Local folder named 'safe'

Do not change the name of this folder.
It is part of test where we ensure we can have local imports to folders that have the same name as dependencies.
In this case, we also have a dependency with key `@safe`.
10 changes: 10 additions & 0 deletions tests/contracts/safe/ThisIsNotGnosisSafe.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
// The point of this file is show we can have contracts in folders
// where the folder is the same name as a dependency.
pragma solidity ^0.8.0;

contract ThisIsNotGnosisSafe {
constructor(){

}
}
11 changes: 11 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
return true;
}
}
// File: ./safe/ThisIsNotGnosisSafe.sol
// The point of this file is show we can have contracts in folders
// where the folder is the same name as a dependency.
contract ThisIsNotGnosisSafe {
constructor(){
}
}
// File: ./subfolder/Relativecontract.sol
contract Relativecontract {
Expand Down Expand Up @@ -138,6 +147,8 @@
// Purposely repeat an import to test how the plugin handles that.
// Show we can import a local contract with the same name (sin-@) as a dependency.
// Purposely exclude the contracts folder to test older Ape-style project imports.
// Showing sources with extra extensions are by default excluded,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_get_imports_complex(project, compiler):
"contracts/MissingPragma.sol",
"contracts/NumerousDefinitions.sol",
"contracts/Source.extra.ext.sol",
"contracts/safe/ThisIsNotGnosisSafe.sol",
"contracts/subfolder/Relativecontract.sol",
],
"contracts/MissingPragma.sol": [],
Expand Down Expand Up @@ -413,6 +414,7 @@ def test_get_compiler_settings(project, compiler):
"contracts/MissingPragma.sol",
"contracts/NumerousDefinitions.sol",
"contracts/Source.extra.ext.sol",
"contracts/safe/ThisIsNotGnosisSafe.sol",
"contracts/subfolder/Relativecontract.sol",
]
assert actual_files == expected_files
Expand Down Expand Up @@ -653,7 +655,7 @@ def test_compile_outputs_compiler_data_to_manifest(project, compiler):
actual = project.manifest.compilers[0]
assert actual.name == "solidity"
assert "CompilesOnce" in actual.contractTypes
assert actual.version == "0.8.26+commit.8a97fa7a"
assert actual.version == "0.8.27+commit.40a35a09"
# Compiling again should not add the same compiler again.
_ = [c for c in compiler.compile((path,), project=project)]
length_again = len(project.manifest.compilers or [])
Expand Down

0 comments on commit 7bea8bb

Please sign in to comment.