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

Fable 5.0.0-alpha.10 introduced path bug in python dependencies #4088

Open
Freymaurer opened this issue Mar 25, 2025 · 9 comments
Open

Fable 5.0.0-alpha.10 introduced path bug in python dependencies #4088

Freymaurer opened this issue Mar 25, 2025 · 9 comments
Assignees
Labels

Comments

@Freymaurer
Copy link
Contributor

Freymaurer commented Mar 25, 2025

I have a fable compatible library with a test project. I encountered an error using this library with the newest fable alpha version, so i wanted to update the library. In this case from 4.19.3 to 5.0.0-alpha.12. The error i wanted to fix was gone, but instead i got a new error related to python import paths in fable dependencies.

The test project has a dependency to Fable.Pyxpecto so my fable_modules looks like this:

fable_modules
|-- fable_library
|-- fable_python
|-- fable_pyxpecto

And the error occurs in fable_modules/fable_pyxpecto/pyxpecto.py. I copied the relevant parts from each version down below.

The imports in Fable.Pyxpecto are incorrectly done from the same folder level, instead of from the parent folder (see the code from 4.19.3).

Fable v5.0.0-alpha.9

from typing import (Any, TypeVar)
from ..fable_library.array_ import (choose, contains as contains_1, append as append_2)
from ..fable_library.async_ import run_synchronously
from ..fable_library.async_builder import (Async, singleton as singleton_1)
from ..fable_library.date import (now, op_subtraction, to_string as to_string_2)
from ..fable_library.fsharp_core import Operators_Using

Fable v5.0.0-alpha.10

from typing import (Any, TypeVar)
# wrong as the import should be from parent folder
from .fable_library.array_ import (choose, contains as contains_1, append as append_2) 
from .fable_library.async_ import run_synchronously
from .fable_library.async_builder import (Async, singleton as singleton_1)
from .fable_library.date import (now, op_subtraction, to_string as to_string_2)
from .fable_library.fsharp_core import Operators_Using
@Freymaurer
Copy link
Contributor Author

I found the breaking version alpha.10.

@MangelMaxime
Copy link
Member

Looking at the Changelog history, I suspect the error to be coming from this PR #4035

@MangelMaxime
Copy link
Member

@Freymaurer
Copy link
Contributor Author

I agree. I am a bit confused because of:

Also, ignore backwards paths in relative imports as this is not allowed in python.
@alfonsogarciacaro

As backwards relative paths seem valid to me, here the relevant link to python docs.

@MangelMaxime
Copy link
Member

There is also this reference which seems to hint that .. is valid in certain other scenarios

@Freymaurer
Copy link
Contributor Author

I am looking into it

@Freymaurer
Copy link
Contributor Author

I checked and indeed reverting the following part fixes the issue i encountered, but makes the new tests around TestsPyInterop.fs fail:

  if part = "." then
      None
  elif part = ".." then
      Some ""

Image

Will work on a fix tomorrow

@Freymaurer Freymaurer changed the title Fable alpha version introduced path bug in python dependencies Fable 5.0.0-alpha.10 introduced path bug in python dependencies Mar 25, 2025
@Freymaurer
Copy link
Contributor Author

Encountered another issue #4089 while working on this. Still trying to reproduce the issue with the wrong import of native code in the quicktest.

@Freymaurer
Copy link
Contributor Author

Trying to debug the issue about fable imports of native code.

The relevant tests are located in tests/Python/TestPyInterop.fs, importing tests/Python/native_code.py and tests/Python/more_native_code.py. The resulting import statements have wrong relative paths:

from ...tests.Python.more_native_code import multiply3 as multiply3_1
import ...tests.Python.native_code as native_code_1
from ...tests.Python.native_code import (add5 as add5_1, add7 as add7_1)

When trying to reproduce this issue with the python quicktest in src/quicktest-py/quicktest.fsx with let add5': int -> int = import "add5" "./native_code.py" i get the correct output of: from native_code import add5.

Therefore i assume this behavior is only triggered when the transpiled code is not in the same location as the fsharp source code.
(non-quicktests are transpiled into temp/tests/xxx, which quicktest is transpiled to the location of the source file).

@MangelMaxime can you give me some guidance on how to make the quicktest transpile to temp? or another option on how to easily debug this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants