Magicimport.py: Python code that fetches its dependencies without complaining
github.com
github.com
> 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.
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.
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 programmers who do use it in production down a path that hurts them in the long run.
People are allowed to point out when that comment is appropriate for a different context. They're allowed to do that with imperfect language too.
You're allowed to acknowledge you're wrong, and move on. You're also allowed to push back and explain why you think it's fine for this context.
The only person who has control over you is you. This is a web forum. A Random Stranger on the Internet calling a comment inappropriate shouldn't lead one to believe that "criticism is not allowed" in a particular forum.
And I think it's a nice toy. I haven't seen people break for using toys. I've mostly seen people break when they only do things one way, and habituate to believe other ways are wrong or bad. Toys are for playing, and great ways to discover which things work and which ones don't. Even IOCCC didn't result in broken programmers. Java sometimes did.
So I don't see either your comment or their response as ideal, but that's okay. I'd estimated 25% of my comments are poor, and you'd probably estimate me at 50% since I probably don't always realize my comments are poor. That's okay. Poor comments are parts of conversations. Pointing out they're poor is part of conversation too. Continuing to talk (and sometimes make poor comments) is too.
I've also seen too many things of this nature in production to buy into the "it's just a toy, it's self-evidently not for real use" argument.
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.
The top-level comment is just being critical. It's not inappropriate. People just don't like having their feelings hurt.
In my personal case, I have loads of dead code directories for various half-remembered Python ideas. It'd be convenient to have a lighter-weight "experiments" dir using something like this.
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.
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.
[0]: https://en.parceljs.org/hmr.html#automagically-installed-dep...
> You can disable this feature using --no-autoinstall.
Seems fine to me.
Personally I've been really happy with with pyenv[0].You can install multiple different versions of Python side-by-side and it does a great job managing virtualenvs.
pipx[1] is also pretty good for managing virtualenvs to install applications in but IMHO less so for doing actual development. You can use it to seamlessly install venv'd Python apps or spin up apps in ephemeral environments.
[0]: https://github.com/pyenv/pyenv [1]: https://github.com/pipxproject/pipx
For instance I encountered a python wheel lately that "conveniently" shipped a precompiled .so file. Not only was that a security problem but also did that file not work properly under Ubuntu 18.04.
Compared to R, pythons imports syntax and handling is a god-sent when sharing code, but we still saw a lot of people get stuck after cloning a notebook or dashboard trying to figure out all the dependencies they needed to set up to run it.
Now they just copy the notebook/dashboard and first run configures everything For them referencing both internal and external dependencies.
It’s a small but important difference especially for juniors.
In the future I would love for python just to support something like “import pandas==1.1.3@pypi” and having that automatically do what every python developer who works with virtual envs would do if they saw the “==1.1.3@pupi” in a comment after the import. But then obviously also supporting installs from other sources than pypi.
Famous last words.
it's saved me a world of pain a number of times to have different versions of the same libs installed in different envs
For example if I do glob.glob("*.txt") it's rather obvious that I also wanted to "import glob".
> Parse it, find all not initialized variables.
> Search imports, suitable for found variables. Import them.
Genius. (Evil genius mabye...)
If it finds multiple functions / objects with the same name, it gives you choices. For me on larger projects it shows choices ~80% of the time.
I wonder how can this work correctly on anything larger than the provided example.
Would definitely recommend Poetry for anything larger, it's been a great experience.
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.
that said, it is an amusing hack to run the virtualenv'd python in a subprocess and then extract the environment vars and inject them into the already running python process.
some of the code could be cleaned up a bit -- e.g. it could be using https://docs.python.org/3/library/tempfile.html#tempfile.Tem... to just ask for a uniquely named temp dir, some of the subprocess invocations dont appear to have error handling, etc.
for my python hobby project these days i only depend upon packages i can install using apt in debian stable. containers for isolation help too.
[0](https://www.zdnet.com/article/two-malicious-python-libraries...)
For example, one could replace a python shebang with fades' one and mark dependencies using # fades comments:
#!/usr/bin/fades
import dependency # fades
https://github.com/PyAr/fadesI don't understand why it even uses virtualenv, when venv is a) part of the standard library, and b) the recommended way to create virtual environments in Python.
While the import from __future__ indicates that it's supposed to support Python 2, the shebang line is explicitly Python 3...
https://docs.python.org/3/reference/import.html#import-hooks