DISQUS

Rob's Cogitations: Django and Relativity Updated

  • christian · 7 months ago
    option 3) can be typed shorter:
    PROJECT_ROOT = os.path.realpath('.')
  • Malcolm Tredinnick · 7 months ago
    No, because you want the path of the file you're importing, which isn't necessarily in the current directory. The sort of thing Rob is talking about here goes in, e.g, a Django settings file, which can easily be somewhere other than the "current" directory from the perspective of the thing doing the importing.
  • Malcolm Tredinnick · 7 months ago
    You haven't really justified your preference for realpath() -- and since it's your blog, I guess you don't have to. I've seen this debate go around a bit in the past, though, and it's a two-sided sword that, if I'm an operations manager or system admin, I would prefer to avoid, usually. If symlinks are involved, they're there for a reason and reporting the correct name (the symlink name) in debugging output, etc, is important. Changing that, by removing the links from the name can lead to confusion.

    On the flip side, removing the symlink from any reported paths does help demystify why "../" is referring to an entirely different location to what you were expecting at times. However, using ".." in files that are going to be symlinked into random locations is probably indicative of a larger problem in the code.

    In short, I'm not convinced about your best option being best. I think your "good" is actually closer to "bad" for the primary reason that it doesn't give an absolute path.
  • Rob Hudson · 7 months ago
    Hey Malcolm,

    I agree that "Best" here is debatable. Maybe I should have thrown in a "in my opinion" for good measure. For me personally, I'd rather see the true path to the Django directory than however it might be symlinked. I can see arguments other ways. Listing them as good, better, and best was a last minute change that I probably shouldn't have done. I think I'll update it to remove that and other biases and just point out the differences. Always good to have your feedback.

    -Rob
  • Julian · 7 months ago
    Why is eliminating symlinks good? If I symlink your app into my project, wouldn't it be bad if it still uses it's real location?
  • Rob Hudson · 7 months ago
    Define "bad".

    As it's stated in the post, this is just my personal preference. My intention with the blog post was to explain the differences and you can choose the best option for you. I like realpath myself. You can pick the best option for your use cases.