Path.BASE_PATH no info available?

Can’t find any information on Path.BASE_PATH online. Why? What am I missing?

I checked the pathlib documentation here and found nothing on BASE_PATH attribute. Why? What am I doing wrong?

1 Like

@thetj09
BASE_PATH is a fastai thing, which is defined in the fastcore library, which is nothing but a collection of slight modifications of already existing Python libraries and functions, to make life a little bit easier (and a few functions which dont exist anywhere else)

You can see here, the repr is modified to print the path without the BASE_PATH part.

5 Likes

This is great. Thanks.

So I looked at the Path object. I checked the location of Path by using Shift tab. It didn’t appear to be modified (File: /opt/conda/envs/fastai/lib/python3.8/pathlib.py). So I assumed it is the real pathlib without any modifications.

How to I go from looking at Path in a sheet to this page? How do I systematically go there? can you please help me?

I’m no expert, but the way I thought of this was:

  1. I first checked the Pathlib documentation and source code - could’nt find anything about the BASE_PATH variable.

  2. Then I thought - what if BASE_PATH is just a dummy name. What if you can attribute a string to any variable name, and it would still work? For example, I tried, Path.BASE = ‘path/…’. But that didnt work. So BASE_PATH definitely must be hard coded somewhere.

  3. So it must be within fastai. So just to be sure, I reloaded the notebook, and tried doing this without importing fastai or fastcore. That didnt work, so I knew it was definitely a fastai thing. And not any fastai module, it must be within fastcore, because thats what its meant to do.

  4. So it must be stored in a place where all other Path modifications are stored. I know one of them - Path.ls() (this too is a fastai thing). So I did ??Path.ls and saw that it is stored in a file inside fastcore, called xtras.py. So its quite likely that this too would be in the same file.

  5. So i went there on github, did a quick CTRL+F BASE_PATH, and sure it was there…

Hope this helps you develop an idea of searching through source codes.
Cheers and stay safe

12 Likes

Amazing. But I can’t believe it is this convoluted to find what is happening where.

With the limited experience of fastai which I have, I can suggest the following thing.

  1. If any constant or method or function that you can not find with single ? or double ??, in Python standard library then it must have to be a fast.ai thing.
  2. Now you can go to fastai repo in GitHub and search in the repo. This will give you the file name where it is defined.
  3. Then either you can read the source code in GitHub or you refer to the documentation of fastai or fastcore.
  4. Most of the time it has to be in the fastcore.

I too struggled a lot initially, but now I am able to find the many things with relative ease. however this time I stumbled on this thing and had to do a Google search to find this post BASE_PATH.

3 Likes

Thank you for sharing!

Jeremy briefly touches upon it here (Lesson 3 - Deep Learning for Coders (2020) - YouTube at time stamp 1:08:02)

2 Likes

@PalaashAgrawal

2.5 - google and find this post

@jeremy is using a lot of dirty patches, which is not very cool for educational purposes, and I’ve seen a lot of criticism of fastai because of that.

He has his point on that, at the end of the day it is his library and his rule, but I think fastai could be much more popular if one uses more stand way of development.

@CreatorCreation the video gives a wrong impression of pathlib

for example @jeremy said that pathlib doesn’t have ls, it doesn’t, but it has glob function, which has more functions than its own ls implementation + it returns generator instead of list, which is better by definition