Skip to content

Pathlib, Pathlib everywhere. #12515

Closed

Description

@Carreau

There are many places where we could make use of Pathlib.

Look for any places that uses with open(...) and ask yourself:

  • is the argument a string ?
  • would it make sens to make it a Path(),
  • how far upstream in the code can I make it a Path.

Don't try to bite more than you can chew (or more than I can review), try to fix 1 place at a time.

Activity

  1. added
    Hacktoberfest
    on Aug 27, 2020
  2. Carreau commented on Aug 27, 2020

    @Carreau
    MemberAuthor

    for example see #12512

  3. Inception95 commented on Sep 21, 2020

    @Inception95
    Contributor

    Hi @Carreau, if no one is working on /core/page.py for using Pathlib, can I take this part?

  4. Carreau commented on Sep 21, 2020

    @Carreau
    MemberAuthor

    Hi @Carreau, if no one is working on /core/page.py for using Pathlib, can I take this part?

    Sure, please. Thanks.

  5. barhenkro commented on Oct 8, 2020

    @barhenkro
    Contributor

    Hi, I would like to work on core/interactiveshell.py and add there more use of Pathlib.
    Can I help with that?

  6. nicksspirit commented on Oct 9, 2020

    @nicksspirit
    Contributor

    Hey @Carreau can I take on testing/iptestcontroller.py and core/magics/execution.py ?

  7. MrMino commented on Oct 11, 2020

    @MrMino
    Member

    Might also be of use: https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module

    There are many places other than with open() that might use pathlib treatment:

    -    conda_history = os.path.join(sys.prefix, 'conda-meta', 'history')
    -    return os.path.exists(conda_history)
    +    return Path(sys.prefix, 'conda-meta', 'history').exists()
  8. nicksspirit commented on Oct 11, 2020

    @nicksspirit
    Contributor
  9. MrMino commented on Oct 11, 2020

    @MrMino
    Member

    Might also be of use: https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module

    There are many places other than with open() that might use pathlib treatment:

    Although... some of them might be less trivial and more error prone, especially when they're interpreted as text. For example, when returning a PosixPath object breaks code in the scope above because it is being ' '.join()-ed with other shell arguments.

  10. Creonalia commented on Oct 13, 2020

    @Creonalia

    There still any places left to fix this? Looks like a lot of people are working on it.
    edit: found some, nevermind

  11. Carreau commented on Oct 13, 2020

    @Carreau
    MemberAuthor

    There still any places left to fix this? Looks like a lot of people are working on it.

    I'm slowly checking the PRs and merging them, I'm not sure if there are other places left.

    THere are other things you can try; find all places that uses cast_unicode/cast_bytes, and see if they are removable. Many of those are due to old Python 2 compatibility.

    for example there is

    def find_file(obj) -> str:
      ...
        fname = None
        try:
            fname = inspect.getabsfile(obj)
        except TypeError:
            # For an instance, the file that matters is where its class was
            # declared.
            if hasattr(obj, '__class__'):
                try:
                    fname = inspect.getabsfile(obj.__class__)
                except TypeError:
                    # Can happen for builtins
                    pass
        except:
            pass
        return cast_unicode(fname)
    

    If you can prove that inspect.getabsfil always return str and not bytes, then cast_unicode is unnecessary. It's a bit more work, but that would cleanup a bt the codebase.

  12. sumagnadas commented on Oct 16, 2020

    @sumagnadas

    I searched for the functions in the whole project and i found many of them. Should i consider replacing all of them with Pathlib alternatives or what files should i consider not replacing the functions in?

    Sorry if i couldn't make you understand what i want to say.

  13. davbrito commented on Oct 19, 2020

    @davbrito

    I'm working on paths.py and I found the following line in several functions:

    assert isinstance(ipdir, str)

    One of such assertions gives a message saying "all path manipulation should be str(unicode), but are not.".

    Should I delete such lines so the move to pathlib can work?

  14. 8 remaining items

  15. davbrito commented on Nov 5, 2020

    @davbrito

    I am new to open source contribution and would love to work on this issue. After I am done with my changes, what would be the easiest way to test the code before I create a PR?

    Hello @squarebat
    You should do this:

    • Install the testing dependencies this by running this command in the root of the repo:
    $ pip3 install -e .[test]
    
    • Then execute the tests with
    $ iptest
    
  16. squarebat commented on Nov 5, 2020

    @squarebat

    I want to work on the test_run.py file. However, I'm having trouble resolving some errors in that file. The two main errors are

    • undefined variable get_ipython (This one is resolved by adding an import but that seems wrong)

    • undefined variable _ip : In some functions _ip is initialized as _ip = get_ipython() hence defining it, but in other functions it not initialized, hence causing error.

    I have set up my environment using pip install .
    I just wanted to know if I made a mistake while setting up the environment, or if there is a bug in the test_run.py file.

  17. davbrito commented on Nov 7, 2020

    @davbrito

    I have set up my environment using pip install

    You have to use pip install -e .[test]

    The -e means that you Install it in editable mode.

  18. joesinghh commented on Dec 6, 2020

    @joesinghh

    Hello! This is my first time contributing to an open source project , I would like to work on this issue .
    can i get assigned ?

  19. nitin-pandita commented on Apr 2, 2023

    @nitin-pandita

    Hey, I would love to work on this issue, as a beginner in Open source I think I can make it work. Thank you

  20. HmbleCreator commented on Oct 14, 2024

    @HmbleCreator

    Hey, I would love to work on this issue can you assign it to me ?

  21. kevin1kevin1k commented on Oct 15, 2024

    @kevin1kevin1k
    Contributor

    I am also willing to work on this, possibly on different set of files.

  22. Carreau commented on Oct 17, 2024

    @Carreau
    MemberAuthor

    Closing this issue,

    In general this is open source, we can't/won't assign people to it; if you want to work on something you are free to do so; You can comment that you are planning on doing X/Y/Z to avoid people doing duplicate work, you can also submit draft/incomplete PRs to show that you are working on it.

    But keep in mind that in general maintainer will tend to just ignore those comments as too many people say "I will do X" and never do it.

    Even if closed, if you believe some files may make use of better libraries like pathlib, feel free to do so, but please keep your PRs small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hacktoberfest

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions