Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding depency crashes when not string [APE-959] #103

Merged
merged 3 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def _add_dependencies(
cached_source.parent.mkdir(parents=True, exist_ok=True)
if src.content:
cached_source.touch()
cached_source.write_text(src.content or "")
cached_source.write_text(
src.content if isinstance(src.content, str) else str(src.content)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does this handle .contract being None?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you meant .content right?

I was just looking at how the manifest is loaded in, parse_file looks like it's deprecated: https://github.com/pydantic/pydantic/blob/0e73e00cbf19ad787c685edf01bb1da7c809a13f/pydantic/main.py#L1086

manifest_data = cached_manifest_file.read_text()
manifest_dict = load_dict(manifest_data)
manifest = PackageManifest.validate(manifest_dict)
sources = manifest.sources
first_source = sources[list(sources.keys())[0]]
print(f"{type(first_source)=}")
first_source.content = None
print(f"{str(first_source.content)=}")
print(f"{first_source.content if isinstance(first_source.content, str) else str(first_source.content)=}")
method1 = str(first_source.content)
method2 = first_source.content if isinstance(first_source.content, str) else str(first_source.content)
print(f"{(method1 == method2)=}")

looks like what I wrote is identical to just casting to str, the above gives:

type(first_source)=<class 'ethpm_types.source.Source'>
str(first_source.content)='None'
first_source.content if isinstance(first_source.content, str) else str(first_source.content)='None'
(method1 == method2)=True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt .content being None would happen, since I think that means the compiler would have given None as output, no? Like on an empty .sol file? I bet it would break before here.

Copy link
Contributor Author

@wakamex wakamex May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah no compiling happens here. tested with a totally empty file (1f14214), and it doesn't pass the if src.content: on line 200:

Content(__root__={})
if src.content:
    print("true")
else:
    print("not")
not

)

# Add dependency remapping that may be needed.
for compiler in manifest.compilers or []:
Expand Down