Live data from Hacker News

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

github.com

11–20 of 49 posts

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

#11

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…

[deleted]

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

#12

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…

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 programmers who do use it in production down a path that hurts them in the long run.

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

#13

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…

To comment further, I believe you take offense at the snarkiness of my original comment. That's fair. I think I could have phrased it in a more respectful way. I'm sorry.

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

#14
I can't say I really like the idea of a "magic" import, but I'm sure some people might find it handy. It just sounds like a recipe for having things break later in mysterious ways but if it's just a one-time use sort of thing I can see the appeal.

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

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

#15
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".

An IDE like PyCharm should be able to suggest the import for you.

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

#16
The downside of such an approach is that it hides the inevitable complexity of dependency management. Things like version constraints, licensing and platform specifica are important. If developers don't see them, they won't learn about them.

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.

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

#17
this is a good example of a "simple versus easy" trade off [1] , i.e. this is something that is easier to get started at some expense of simplicity: it is over-complicated & hides complexity behind a simple interface, but not in a way that is reliable - so eventually things will break and then you'll be strictly more confused than if you did things in a less easy but simpler way - learning a bit about dependency management & setting up a reproducible environment for running your python script/app.

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.

[1] https://www.infoq.com/presentations/Simple-Made-Easy/

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

#18
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".

D has import std; which just imports the whole standard library in one go (for writing). You might be able to write your own (not sure if python has public imports)

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

#19

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…

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.

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

#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/
Post reply on HN