Skip to content

Absolute/"source-relative" imports for csv-table :file: #8487

Closed

Description

@lcnittl

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.

Environment info

  • OS: Win
  • Python version: 3.8.5
  • Sphinx version: 3.2.1

Activity

  1. tk0miya commented on Nov 25, 2020

    @tk0miya
    Member

    +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...

  2. added this to the 4.0.0 milestone on Nov 25, 2020
  3. mvincerx commented on Jan 16, 2021

    @mvincerx

    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.

  4. added 5 commits that reference this issue on Mar 6, 2021
    94ed68a
    e1f118a
    80c39a0
    fb4220d
    426fa9d
  5. added a commit that references this issue on Mar 11, 2021
    3134085
  6. dtdannen commented on May 10, 2021

    @dtdannen

    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:

        def get_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

    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).

  7. locked as resolved and limited conversation to collaborators on Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions