You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Absolute/"source-relative" imports for csv-table :file: #8487
Describe the bug
To be honest, I am not sure if this can be considered a bug, or if it is rather a feature request. Sorry about that.
When using the csv-table directive, the use of :file: with absolute paths are really absolute, unlike with (eg) the figure directive, where absolute paths are treated relative to the source directory (herein called "source-relative").
I do understand that there is a difference in the 2 cases, because with figure the path is not specified in :file:. Yet, I do not see a possibility to mimic this behavior in the cvs-tables directive.
To Reproduce
A phone_list.rst file in source/resources:
Relative imports:
.. csv-table:: The group's phone and room list:align: center
:file: _tables/phone_list.csv
:header-rows: 1
are treated, as expected, relative to the .rst file:
C:\Users\lcnittl\project\docs\source\resources\phone_list.rst:13: WARNING: Problems with "csv-table" directive path:
[Errno 2] No such file or directory: 'source/resources/_tables/phone_list.csv'.
.. csv-table:: The group's phone and room list
:align: center
:file: _tables/phone_list.csv
:header-rows: 1
Absolute imports:
.. csv-table:: The group's phone and room list:align: center
:file: /_tables/phone_list.csv
:header-rows: 1
are treated, opposed to my expectations, like real absolute paths:
C:\Users\lcnittl\project\docs\source\resources\phone_list.rst:13: WARNING: Problems with "csv-table" directive path:
[Errno 2] No such file or directory: 'C:/_tables/phone_list.csv'.
.. csv-table:: The group's phone and room list
:align: center
:file: /_tables/phone_list.csv
:header-rows: 1
and not like relative-to-source paths.
Expected behavior
I would expect this to work like absolute paths in the (eg) figure directive.
But as stated in the beginning, probably I am wrong with my expectation, and this should be a feature request to add an option to use "source-relative" paths with the csv-table directive.
+1: I agree this is inconsistent behavior. It should behave like the figure directive. But changing the behavior is an incompatible change. So we have to change it carefully...
I'd greatly appreciate this change too. Changing the behavior of :file: flag for csv-table to mimic that of figure directive would be great. As it stands with csv-table, even when using an absolute path and the file fails to load, it fails silently.
I may be running into this problem again - I have a csv-table directive in a docstring of a function, and when it's loaded for the api documentation it tries a different path than when it loads it for the a custom page where I want to reference that function using autoapimodule members.
Using Sphinx v4.0.0
More details:
I have the following python function in a GameState class:
defget_player_stats_vector(self):
""" The player stats vector consists of the following features and is returned as a python list. .. csv-table:: Player Stats Vector :file: ../../../csv_tables/state_representations.csv :header-rows: 1 Returns: A list of features representing the player's stats """
In addition to generating complete API documentation using autoapi, I also want to reference this specific function in a manually created page, like the following:
*********************
State Representations
*********************
dcss-ai-wrapper offers multiple state representations to support multiple types of AI agents.
.. autoapiclass:: src.dcss.state.game.GameState
:members: get_player_stats_vector
and then when I go to run sphinx-build I'm seeing that it's trying two different paths (both of which are incorrect in this case). Should the correct behavior be that it's trying the same path? I can get it to work for the API, but then it fails for the manual page I'm making.
D:\OneDrive\Code Projects\dcss-ai-wrapper\docs\autoapi\src\dcss\state\game\index.rst:43: WARNING: Problems with "csv-table" directive path:
[Errno 2] No such file or directory: 'docs/autoapi/src/csv_tables/state_representations.csv'.
.. csv-table:: Player Stats Vector
:file: ../../../csv_tables/state_representations.csv
:header-rows: 1
And then a little bit later, same error showing its trying a different path:
[Errno 2] No such file or directory: 'D:/csv_tables/state_representations.csv'.
.. csv-table:: Player Stats Vector
:file: ../../../csv_tables/state_representations.csv
:header-rows: 1
Activity
tk0miya commentedon Nov 25, 2020
+1: I agree this is inconsistent behavior. It should behave like the figure directive. But changing the behavior is an incompatible change. So we have to change it carefully...
mvincerx commentedon Jan 16, 2021
I'd greatly appreciate this change too. Changing the behavior of
:file:flag forcsv-tableto mimic that offiguredirective would be great. As it stands withcsv-table, even when using an absolute path and the file fails to load, it fails silently.Close sphinx-doc#8487: csv-table now considers abspath as relpath fro…
Close sphinx-doc#8487: csv-table now considers abspath as relpath fro…
Close sphinx-doc#8487: csv-table now considers abspath as relpath fro…
Close sphinx-doc#8487: csv-table now considers abspath as relpath fro…
Merge pull request #8969 from tk0miya/8487_absoluted_file_option_for_…
Master.patch (#1)
dtdannen commentedon May 10, 2021
I may be running into this problem again - I have a csv-table directive in a docstring of a function, and when it's loaded for the api documentation it tries a different path than when it loads it for the a custom page where I want to reference that function using autoapimodule members.
More details:
I have the following python function in a GameState class:
In addition to generating complete API documentation using autoapi, I also want to reference this specific function in a manually created page, like the following:
and then when I go to run sphinx-build I'm seeing that it's trying two different paths (both of which are incorrect in this case). Should the correct behavior be that it's trying the same path? I can get it to work for the API, but then it fails for the manual page I'm making.
And then a little bit later, same error showing its trying a different path:
The bug should be reproducible on this commit
I'm running sphinx-build in the root level via:
sphinx-build -v -a -b html docs/ docs/_build(I'm still learning sphinx so I can't rule out user error, in which case any advice in the right direction would be greatly appreciated).