Live data from Hacker News

Magicimport.py: Python code that fetches its dependencies without complaining

github.com

1–10 of 49 posts

Re: Magicimport.py: Python code that fetches its dependencies without complaining

#2
Since moving to Nix, I've been forced to setup virtual envs for my more interesting projects (oh sure, I install the common libraries at the system level), and though I resisted this workflow a lot initially (I like to keep a tight ship), I've come to embrace its practicality when working on projects that have libs with breaking changes due to rapid releases.

it's saved me a world of pain a number of times to have different versions of the same libs installed in different envs

Re: Magicimport.py: Python code that fetches its dependencies without complaining

#6
As someone who has been coding for 20 years, "magic" is a negative adjective for me. I don't want magic code. I want code that is simple and works in obvious ways.

> You can even specify a version number

Sorry to be sarcastic here but wow, you mean I can even make sure that my code will not break at an arbitrary point in the future, when my dependency inevitably introduces a breaking change? Fantastic.

I understand that installing dependencies is a bit of a hassle. But really, once you have done it twice it takes seconds. And I would not want a mechanism that fetches dependencies as a side effect of my app running. I want to know what's going on when my app runs. The fewer moving parts, the better. Often, it's hard work to achieve this simplicity. But, at least in my experience, it pays off.

Re: Magicimport.py: Python code that fetches its dependencies without complaining

#7
post #5

Another thing I'd like for small projects is for "obvious" modules to be imported without having to say so. For example if I do glob.glob("*.txt") it's rather obvious that I also wanted to "import glob".

I think this would be super helpful within the context of a jupyter notebook

Re: Magicimport.py: Python code that fetches its dependencies without complaining

#9
post #3

I opened this expecting Python to allow you to define custom import handlers at runtime, but this is cool too.

That is in fact also possible, and you could use it to make this magicimport system get called automatically whenever you try to import a non-existent library.

https://docs.python.org/3/reference/import.html#import-hooks

Re: Magicimport.py: Python code that fetches its dependencies without complaining

#10

As someone who has been coding for 20 years, "magic" is a negative adjective for me. I don't want magic code. I want code that is simple and works in obvious ways. > You can even specify a version number Sorry to be sarcastic here but wow, you mean I can even make sure that my code will not break at an arbitrary point in the future, when my dependency inevitably introduces a breaking change? Fantastic. I understand t…

This is a toy/neat experiment that someone made and they explicitly say you should not use it for production. This sort of criticism is inappropriate (or at best, poorly framed). This is Hacker News, and this is a Hack.

If I made a bot that drives cars around in GTA would you make a post ridiculing how dangerous my lane detection algorithm would be for a self-driving car in snow?

Furthermore, the point OP makes about L5 cars being presumably achievable while "L5 software" is not is a 100% valid point - why should we not aspire to that level of consistency and effectiveness in our systems? Maybe achieving this is actually possible and projects like this inspire the approaches that actually deliver those capabilities in a production-mature form.

Post reply on HN