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

Error during Module initialization #131

Closed
pedromxavier opened this issue Mar 11, 2022 · 5 comments
Closed

Error during Module initialization #131

pedromxavier opened this issue Mar 11, 2022 · 5 comments

Comments

@pedromxavier
Copy link
Contributor

I'm currently using PythonCall within a new Julia package. The environment is configured according to the docs. Indeed, PythonCall is was added as a dependency, CondaPkg.toml is present and so on.
Locally it works like a charm, but during standard Julia CI it fails to initialize due to pathof(PythonCall) returning nothing. It then triggers a Method Error by calling dirname(::Nothing). In fact, according to pathof's docs:

help?> pathof
search: pathof

  pathof(m::Module)

  Return the path of the m.jl file that was used to import
  module m, or nothing if m was not imported from a package.

  Use dirname to get the directory part and basename to get the
  file name part of the path.

I'm not really certain about init_juliacall semantics, but I think this is a corner case to be addressed.
https://github.com/cjdoris/PythonCall.jl/blob/d193f567c6a4ddde84ecb0ca3a9a36c8335820d1/src/juliacall.jl#L20

Also, any tips or workarounds are appreciated!

@cjdoris
Copy link
Collaborator

cjdoris commented Mar 12, 2022

I've occasionally had the same issue locally, but it seemed to occur at random - restarting Julia always fixed it.

PythonCall is always loaded from a package though, so pathof should always return a string, so this seems like a bug?

Do you have a way to reproduce this reliably?

@cjdoris
Copy link
Collaborator

cjdoris commented Mar 12, 2022

I guess I should really be using @__DIR__ instead. I'll do that.

@pedromxavier
Copy link
Contributor Author

I've occasionally had the same issue locally, but it seemed to occur at random - restarting Julia always fixed it.

PythonCall is always loaded from a package though, so pathof should always return a string, so this seems like a bug?

Do you have a way to reproduce this reliably?

TL;DR: I think this issue may affect every chained dependecy in the form Package -> Other Package -> PythonCall

Yes, indeed. I should've made this explict but I was in a hurry. The problem showed up in two situations and I guess it has to do with caching of some sort.

The first one happens randomly when the environment was clean and the project is built for the first time. The reliable situation happens when using PythonCall on the innermost package on a Pkg.develop-nested environment. I don't know if this extends to Pkg.add but I guess yes. I think that nesting has nothing to do with it, any locally-dependent package would trigger this.

Summary:

MainPackage.jl (uses InnerPackage via ]dev)
├── src
│   ├── InnerPackge.jl (uses Pythoncall via ]add)

I've just solved it by building and testing InnerPackage before instead of lazily wating for it to be built as MainPackage's dep.

@pedromxavier
Copy link
Contributor Author

I think this happens because from Package's perspective, PythonCall is not imported from a package as it is from OtherPackage's.

When running locally this can be fixed by running again but keeping this will mess with many CI workflows around.

@cjdoris
Copy link
Collaborator

cjdoris commented Mar 14, 2022

Interesting! Anyway I've fixed this on the main branch now, using @__DIR__ instead of pathof.

@cjdoris cjdoris closed this as completed Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants