Skip to content

Change from __file__ to inspect.getfile() syntax for path retrieval #102

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

Merged
merged 6 commits into from
Jul 2, 2025

Conversation

cosimolupo
Copy link
Contributor

In the __main__.py file, in the lines retrieving the Cobrawap version from the VERSION file, path recognition has been implemented in a different way, moving from Path(__file__) to inspect.getfile(lambda: None) syntax, because of the former suspected to lead to a failure in readthedocs automatic checks triggered by commits in the NeuralEnsemble official Cobrawap repository. In the same way, again in the __main__.py file, also the syntax for retrieving pipeline_path has been changed accordingly, and simplified.

@cosimolupo cosimolupo requested review from rgutzen and mdenker and removed request for rgutzen June 18, 2025 15:14
@cosimolupo cosimolupo self-assigned this Jun 18, 2025
@mdenker mdenker added this to the v0.2.2 milestone Jul 2, 2025
@mdenker
Copy link
Member

mdenker commented Jul 2, 2025

Added details to understand this change for future reference: Readthedoc is throwing the following error:

[...]
      File "/home/docs/checkouts/readthedocs.org/user_builds/cobrawap/conda/89/lib/python3.11/site-packages/sphinxarg/ext.py", line 501, in run
        exec(code, mod)
      File "../../cobrawap/__main__.py", line 45, in <module>
        with open(Path(__file__).parents[1] / 'VERSION') as f:
                       ^^^^^^^^
    NameError: name '__file__' is not defined

Thus, it seems the current sphinx build uses an exec statement to execute parts of the code in main. Indeed, calling a string of code in exec, the __file__ attribute is not recognized.

exec("import inspect; print(__file__)")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name '__file__' is not defined. Did you mean: '__name__'?

Thus, the suggested change is necessary for the doc build.

@mdenker mdenker merged commit 4193444 into NeuralEnsemble:master Jul 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants