Live data from Hacker News

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

github.com

21–30 of 49 posts

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

#21
I'm disappointed to see so many negative HN comments about this project. I think it is really cool!

You shouldn't use this in a production web service--and the author says as much in the README--I think there are some great uses for this code:

1. Demonstrating how the Python import system works. There is a lot of nuance at hand that other programming languages (like C) don't have an analogy for.

2. Creating truly self-contained Jupyter notebooks. Right now, if I want to send someone a working Jupyter notebook, I have to send them a requirements.txt (or, better yet, a Dockerfile) for them to install in a virtualenv. This is too bad, because specifying the dependencies in the notebook itself is better for teaching purposes.

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

#22
This is cool!

I wrote a script that would try and automatically determine missing packages and their version numbers a while a go: https://gist.github.com/JosephRedfern/ef52916e70497bc9631d6e...

It was a joke rather than a serious tool. Caught import errors and runtime errors and would install pip packages going back from most recent to oldest, until the script under test worked without error. At least, that was the idea —- I never really finished it.

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

#23

I'm disappointed to see so many negative HN comments about this project. I think it is really cool! You shouldn't use this in a production web service--and the author says as much in the README--I think there are some great uses for this code: 1. Demonstrating how the Python import system works. There is a lot of nuance at hand that other programming languages (like C) don't have an analogy for. 2. Creating truly sel…

Re: 2, IMO this is where makefiles shine.

When I got my start on Linux with Ubuntu (Breezy Badger IIRC) I compiled many (most?) of the utilities I wanted from source. When `make` didn’t “JustWorkTM”, it give very clear reasons why, and even as a noob I could usually correct the issue. Python , Docker, and NodeJS etc still leave much to be desired in that regard.

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

#24

This is cool! I wrote a script that would try and automatically determine missing packages and their version numbers a while a go: https://gist.github.com/JosephRedfern/ef52916e70497bc9631d6e... It was a joke rather than a serious tool. Caught import errors and runtime errors and would install pip packages going back from most recent to oldest, until the script under test worked without error. At least, that was the…

Obligatory xkcd: https://xkcd.com/1654/

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

#25
post #20
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".

You can check https://pypi.org/project/smart_imports/

> Get source code of the module, from which smart_imports.all() has called.

> Parse it, find all not initialized variables.

> Search imports, suitable for found variables. Import them.

Genius. (Evil genius mabye...)

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

#26

Earlier quoted context omitted.

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…

You're basically saying that I am not allowed to give my opinion on this project, because it happens to be critical. I don't know how we can have interesting discussions in this forum if criticism is not allowed. At the end of the day, I think you're saying it's a fun toy and I shouldn't worry, whereas my point was that I wouldn't even want to use it as a toy, and I am afraid it will lead especially less experienced…

Nope, your comment is poor because it’s off-topic, not critical. You saw the project and launched into a mild rant about “kids these days who use libraries for everything” when on-topic comments would be “I hope nobody actually uses this ;) Although in all seriousness based on my experience this kind of thinking is unironically already present in the software engineering community”. Your original comment fails to tie itself back to the project and it fails to demonstrate that you understood it was not meant for use in production. As such, it deserves as much disdain as a “Mozilla should fire its CEO” comment should get on a post about SpiderMonkey.

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

#27
post #19

Earlier quoted context omitted.

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…

This is just a toy but might seem like a great idea for someone less experienced and could normalize bad practices. Specifically stating to not use in production will not stop people from doing just that! Requirement files aren't magic, neither are virtual envs. Every slightly professional IDE supports that. No need to create anti-patterns.

This. The Node.js community is a good example of where this has happened - lots of bad practices with fancy logos making it into the top 50 most depended upon packages (e.g. left-pad).

The top-level comment is just being critical. It's not inappropriate. People just don't like having their feelings hurt.

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

#29
post #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 di…

I would discourage distros from even shipping easy_install and pip by default. One should never mess with the system Python.

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

#30
post #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

This is one of those cases when something that can be done just shouldn't.
Post reply on HN