479 points · by shakna · 10y ago · 179 comments
There are arguments for and against, but in general I think a configuration file should be human readable and editable, as well as easily understood by an IDE without having to run an interpreter. So something like YAML or TOML, or even a simple INI would be better than the function calls in the Pipfile. However, the lock file isn't meant to be edited by hand or really ever looked at, so it being in JSON or something less human readable is fine.
Also, why doesn't pip just make it, by default, look for the requirements.txt or the Pipfile? It's silly having to type pip install -r requirements.txt and I will also find it silly having to type pip -p. It's how NPM, Bundler, and many other package managers work; why do I need to call a flag to install requirements?
Many packages have abused the executable nature of setup.py files by importing obscure packages or adding otherwise fragile logic. I would hate to see Pipfiles go the same way.
Strong +1 to making it a declarative format like YAML or TOML instead of something executable.
Why do you prefer using ``pip`` despite ``pip install`` using the package's ``setup.py`` (and therefore is an eval)?
Further, if you're using a package manager, I expect you won't be combing through the source to check for malicious code anyway.
This is also why wheels (the new python package format) use a static file instead of setup.py. The Python ecosystem has been trying to get off of "just eval setup.py" for years.
Because pip is used extensively as a manual command to install something - you don't expect something like DIR or ls to automatically get its list of files to list from a DIR.txt or a ls.txt file, do you?
So it would follow that tools do their thing based on the current directory, as specified by package.json/Makefile/Gulpfile/Dockerfile/Vagrantfile et all.
Flexibility?
if soandso:
package("pack1")
else:
...
?Py2/3 compatibility? I've never had to do this, interested what the use-case is.
Requirements.txt is very pythonic in the sense that it's as simple as possible, but no simpler.
Accepted standards.
The main problem with requirements.txt, as I see it, is that you don't get exact versions unless you specify it in your requirements.txt. So you'd have to have a loose requirements.txt and then generate a second requirements file after having done `pip install -r requirements.txt` to get the exact versions that were installed.
Further, if you happen to "accidentally" `pip install some-package` in your virtual environment, your app might now be using different packages locally without you noticing. With Pipfile the need for virtual environments is pretty much gone, assuming that at runtime it will automatically load the version of a package specified in the lockfile, which is not clear to me yet from the README.
pip freeze > requirements.txt
it will have all the files' versions specifiedgenerate a second requirements file after having done `pip install -r requirements.txt` to get the exact versions that were installed
So you'd need to have a `requirements.txt` with loose versions suitable for upgrading your apps deps, run `pip install -r requirements.txt` and then `pip freeze > requirements.locked.txt`. Then everyone should be using `pip install -r requirements.locked.txt` as well as during your build. But that's cumbersome and error prone and doesn't free you from having the wrong version of a dep in case you `pip install some-package` later on.
$ pip install pip-chill
$ pip-chill > requirements.txt
Note: I built it because I got tired of reading through long auto-generated requirements files.But that's not always an option. Bower exists for a reason - all that duplication / bloat is unacceptable for browsers to download. It can also mean hell for static initialization / mutable state, because there's no longer a single owner of the global resource.
It's identical because bundler mostly got it right and dependency management in Ruby, while still not great/perfet, is better than just about everywhere else.
Kudos to python for moving forward.
I'm sitting here thinking, "what the hell is wrong?". I've honestly only experienced trouble with Ruby while being completely satisified with how python virtualenv works.
I guess if anything this proves that it's about habit. Habitual use of something makes it the easiest product for the habitual user. Ruby is something I force myself through when I want to try a product while Python is something I develop my own products in.
I tried to pitch the Gemfile and lockfile approach when we were developing our own internal packaging system but nobody seemed to "get it" or see the value. I also tried to pitch database versioning (which alembic seems to do), but again, no takers.
I feel like it was a failing on my part to communicate or show the value in these things...they came randomly out of meetings and I probably botched the concept when pitching it.
I've stumbled with requirements.txt and setting up a new package. I'm also picky and don't like installing packages to my system (and I'm not always using virtualenv) so I have to look up how to install to my homedir. So I've stumbled with Python packaging (although, I think everyone can admit it has a bit of a hodgepodge) while I liked how Ruby did it.
I think this is the product of people who got to know both Python and Ruby very well and found Python lacking here. There are lots of things Ruby developers were gifted from people who also know Python and found Ruby lacking. Python is generally something I force myself through so I'm not one of those people but so glad they exist.
BTW, Ruby has tools similar to virtualenv: chruby, rbenv, and rvm all do basically the same thing.
Take zulip for example, they do use requirements but they go their own way in most other things.
Managing an application is much easier if it uses standard build system. Setup.py, requirements.txt and so forth.
Gitlab is an example of a very complex packaging for a ruby application, but it works! It's complex but solid.
People are tugging in all kinds of different directions. My bad experiences with Ruby and node usually include seeing a loooong list of dependencies being installed and then at dependency #187 it suddenly stops for some reason like one rogue commit breaking compatibility with other packages.
This is hell to someone who doesn't develop in the language regularly, it's a bad packaging system for users.
To be clear, I'm not saying Python is better. I'm just identifying the issues I've had. The only reason Python is easier for me is because I've decided to use it more than the other languages.
On the one hand you can build a complex but solid system like Gitlab has, on the other you can use more standardized systems to distribute your app that require more steps and are less automated. But they're well documented and established methods used for that language.
I've been using pip-tools with tox for a couple of years now. I maintain a requirements.in and requirements.testing.in, and then I can run
$ tox -e pip-compile
to generate my fully qualified requirements. The pip-compile command is handled by a tox.ini section. [testenv:pip-compile]
commands =
pip-compile {posargs}
pip-compile -o requirements.testing.txt {posargs} requirements.testing.in
deps =
pip
pip-tools
The remaining nasty part is automated extraction requirements for setup.py's install_requires and dependency_links. I wrote a function to handle VCS links and other complicated syntax that I'm copying around to all of my projects. Otherwise, pip-tools has been a great solution.It seems to me that that's where we should be heading towards.
All that said, I have no clue what Pipfile is adding. The rationale appears to be that people sometimes don't use requirements.txt properly? Can one of the very enthusiastic commentators explain their enthusiasm?
That hasn't been settled yet. It's being actively discussed [0].
> Or is the idea to eventually get rid of setup.py?
Yes, a replacement for setup.py has already been agreed on in PEP 518 [1]. It's called pyproject.toml.
https://pypi.python.org/pypi/flit
Looks quite nice, a flat .ini file for specifying deps, though it only builds wheels.
There is another discussion on the Pipfile repo about this that may also clarify things for you [0]. The example I posted there [1], which I'll post again here, is:
---
A project can only have 1 set of abstract dependencies (setup.py/pyproject.toml), but different users working with that project can have different sets of concrete dependencies (requirements.txt/Pipfile) which allow them to fulfill those abstract dependencies from PyPI mirrors, private package indexes, personal forks on GitHub, or somewhere else.
So if project Car depends on Engine (an abstract dependency), I can choose to install Car but grab Engine specifically from a fork I made on GitHub (a concrete dependency) that has some performance improvements. Meanwhile, someone else working at a big company that doesn't want to depend on external services to build and deploy their internal Python projects can choose to install both Car and Engine from their private package index as opposed to PyPI (another concrete dependency).
You can't merge these two types of dependencies together into one file without hampering people's ability to choose where to get their dependencies from.
---
According to another commenter on that issue [2], both Rust and Ruby have a similar split in how they specify dependencies.
[0] https://github.com/pypa/pipfile/issues/27
[1] https://github.com/pypa/pipfile/issues/27#issuecomment-26228...
[2] https://github.com/pypa/pipfile/issues/27#issuecomment-26226...
...however, I strongly disagree on the benefit of making the `Pipfile` executable python. Just read this gist: https://gist.github.com/kennethreitz/4745d35e57108f5b766b8f6...
- This file will be "compiled" down to json.
Then why does it exist?We know it'll be abused; and we should have learnt our lesson from scons and setup.py that it wasn't a great idea before, and still isn't a great idea using python code itself as a declarative DSL. Just use a standard hierarchical file format (json, toml, xml, whatever)
Features of introspecting and editing `Pipfile.lock` should be rolled into pip and exported as a core python module; an api for editing pipfile.lock is a good idea, but executing a `Pipefile`, is not.
[1] this is quite a large number of cases, but they are significant drawbacks.
I do sort of like node's ability to recursively nest dependencies to avoid dependency hell. Though that has it's downsides too.. you will never know what is in your modules dir.
There are a lot of mentions of deterministic builds, but that is already very achievable with pip-compile (part of pip-tools) or just pip freeze.
The grouping functionality allows you to have just one requirements file instead of one per environment (i.e. production, test, development, etc) which is mostly just a personal preference IMO. This isn't particularly compelling to me, but that could be because I'm already used to the traditional "pythonic" way of having one file per environment. Using the -r command within a requirement file allows one to recursively include other requirements files to avoid duplication of common dependencies across environments.
The difference in syntax between traditional requirements files and Pipfiles is indeed pretty large. The Pipfile syntax is quite a bit more verbose which I'm personally not a fan of, but this will come down to personal preference and what one is familiar with.
It's unclear if Pipfiles as proposed here is meant to include the dependency resolution functionality of the pip-compile command provided by pip-tools. That is a very critical step as vanilla pip makes no guarantees about respecting version pins of nested dependencies; only that some version of a nested dependency will be present but not necessarily the one intended.
Another big unknown that others have asked about as well is how Pipfiles can be used to manage requirements for a library in a way that allows other libraries/apps that do not use Pipfiles themselves to still list said library in their requirements.txt.
Apologies if my comments comes across as overly negative or dismissive; I applaud any effort to improve the tooling around Python dependencies. But as someone already familiar with the Python/pip ecosystem, it's not clear how this would improve or simplify the solutions that are already out there.
In my python workflow everything lives within a project virtualenv. Dependencies are defined in setup.py with install_requires, extras_require and tests_require. I build against latest, version constraints are added mostly when the latest version of a package has a problem.
Now when i commit to dev, stage or prod branch our ci generates a version pinned requirements.txt which is used to install the virtualenv on stage/prod.
I don't really see the improvements in Pipfile, feels like https://xkcd.com/927/.
>In my python workflow everything lives within a project virtualenv
Were you using rbenv or rvm with Ruby?
For Python, there's `pipsi` for automatically creating unique virtualenvs for binaries - that's the right approach, and it's worth adopting ASAP for future sanity. It even lets you mix python 2 and 3 binaries without any issues. I don't know what the equivalent would be for Ruby.
#!/bin/bash -x WHEELHOUSE="/usr/local/wheelhouse" [ -d "$WHEELHOUSE" ] || ( sudo mkdir -p /usr/local/wheelhouse/ ; sudo chmod -R 0777 /usr/local/wheelhouse/ ) deactivate set -e cd .requirements for reqfile in requirements*txt ; do TEMPDIR="$(mktemp -d)" virtualenv -ppython3 "$TEMPDIR" . "$TEMPDIR"/bin/activate pip install -U pip pip install -U wheel pip wheel --find-links="$WHEELHOUSE" --wheel-dir="$WHEELHOUSE" -r $reqfile pip install --find-links="$WHEELHOUSE" -r $reqfile pip freeze | grep -v "pkg-resources" | sort > "../$reqfile" rm -rf "$TEMPDIR" done wait
I welcome any improvement to python packaging, but I'd start with improving pip itself & making it into a library that tools can wrap around.
If you don't control all the projects involved, this needs some quite convoluted inheritance chains to work around.
I can't tell if this change will fix that.
But I'm sure I'm missing something. Please feel free to convince me I'm wrong :)
I know that it's just a few simple operations for me to do it myself, but npm has spoiled me.
This is a missing feature, there are various hacks but nothing concrete.
If you're working on a large project you have to keep track of all your dependencies and preferably only add the main dependency, not its dependencies, into requirements.
I tend to avoid doing pip freeze > requirements.txt because it lists packages I know shouldn't be in requirements.
Like civilian, my main ask for an improved pip would be a way to save a single explicit package into my requirements.txt by adding a --save flag when installing it.
I don't want to include sub-dependencies in my requirements.txt.
Another benefit is named groups, which allow you to more succinctly specify dependencies for various environments (dev/test/production/etc.) Along with this you get the benefits of the lock file so you can be assured the subset of libraries you use in production will be the exact tested libraries you use in your larger dev/test environment.
in fact, there's already a library for this called pip-tools (https://github.com/nvie/pip-tools) that generates a requirements.txt (the lock file) from a requirements.in (your direct dependencies)
To fix that, you'd need something like Nix.
Installing the project would cause it to be built from the lock file (assuming the Pipefile hasn't changed). This will mean your users won't get "some version" of a library you depend on between verion 1.0 and 2.0 or whatever range you specified. They'll get the exact package you last successfully used and checked in yourself, right down to the git commit if applicable.
Once you modify the Pipfile then pip will resolve your dependencies and try to make the specified changes by adding/removing/upgrading packages. If Pypa continues following bundler conventions this will be done by making the fewest changes possible from your existing versions in your lock file. You'll also have an upgrade mode where pip will rebuild you project from the Pipfile looking for the most recent versions of all libraries or a specified library within your specified version ranges. When done and your app/tests are working, check in the new version and you can ensure all your users/environments will be able to upgrade cleanly.
https://caremad.io/posts/2013/07/setup-vs-requirement/ covers it pretty well. Or https://medium.com/@sdboyer/so-you-want-to-write-a-package-m... for a fantastic read and a LOT more context.
Grouping of sub-dependency groups (e.g. a testing group).
That seems like an improvement over having multiple requirement files. Then again, I'm perfectly happy with separate dev/testing files.It'd be nice to be able to mark a dependency as being conditional based on some expression, e.g. `$PYTHON_VERSION_MAJOR >= 3`.
From the original prototype's comments: https://gist.github.com/dstufft/2904d2e663461f010bbf
"- If there's a corner case not thought of, file is still Python and allows people to easily extend"
... and ...
"- Using Python file might cause the same problems as setup.py"
Ugh.
Also, how is the "lock file" actually distributed? Unless you can pip install a wheel and have it include an embedded lock file, then you've still got to have some out-of-band mechanism for copying the lock file around like you would a requirements.txt or even a fully-fledged virtual environment.
Don't be so scared. Ruby developers have been doing this for over 7 years now. Trust us, this is much better. Your Python friends at Pypa are copying Ruby because dependencies are less painful there than just about anywhere. They are still painful, but this will help.
Having a more complex requirements system that what we have with requirements.txt is good, but at what cost? Is Python doing this just because other languages to it this way? I think it is actually
Also, I'm not sure how a lock file in source control will help me when someone who is not checking out source wants to pip install my project using said lock file.
There seem to be a lot of strange fears from python developers about this approach and my comment on age was an attempt to assuage those fears. Since ruby developers are quite happy with bundler (at least in comparison to other communities) and have been for some time it's a reasonable point and not the only one I made.
I'm not sure how pip plans to use the lock file for projects distributed via pip. They may very well have a solution planned for that.
However, for projects that are distributed by source (which are many) the lock file ensures deterministic builds, and requirements.txt generally doesn't without being pedantic with your versions.
SomeProject==5.4; python_version < '2.7'
SomeProject; sys.platform == 'win32'
In my view, that's already out of hand, and isn't even really parsable without some bespoke library.I'm a big fan of this idea of having a requirements.lock. I can call pip to do the parsing, then I can parse the lock which is just json.
The fact that you need to parse the requirements.txt feels like a design issue with pip to me. (Of course, I'm coming from Rubyland.) As for setup.py, setup.py is broken because it conflates build scripting with package metadata and dependencies. Now that tox exists things are better (but the fact that tox is not a general-purpose programming language is IMO unfortunate coming from Rake/Ruby/Bundler/Gemfiles.)
Was that really necessary? You just moved the tone of your reply to a less pleasant manner.
The poster isn't scared. They, like me, are failing to see the necessity of this compared to the more simple, straightforward, already-working, KISS-principle-following requirements.txt, which was my immediate reaction to reading the description of this project on the github link.
Maybe my tone came across condescending. That wasn't the intent. It was meant in jest in hopes the reader would second guess the fear.
KISS is great, but this project is here because it's not already working for everyone. There is benefit to a flexible dependency system that keeps the concepts of "acceptable versions" separate from "actual versions last used" while also adopting an extendible DSL ready for edge cases that haven't been thought of.
I think the condescending tone is quite unnecessary ("Trust us, this is much better. Your Python friends at Pypa")..
In my experience Ruby is a a far worse culprit than Python for breaking things. First of all `rvm` and `rbenv` are both bloated and rather unreasonable invasions of the shell (hi-jacking `cd` seriously?) Secondly, the fact that Ruby modules are globally shared -- can cause endless breakage from a few misbehaving packages, especially with ones that like to monkey-patch std-lib classes (refinements should improve the the later but it will take a while for the ecosystem to catch-up).
If this Pipfile.lock approach allows me to always have the correct package versions without virtualenv, it's a huge step forward.
Just one request: please, please add a --save option to pip like npm's.
What does that even mean?
A .txt file is meant for human readable sentences, yet this file is meant to be consumed by pip. You can only "customize" it working within the confines of pip freeze. If you were new to programming, would you suspect that requirements.txt was somehow linked to Python? Probably not.
Why can't ruby or JavaScript or any language make use of requirements.txt? They could, and make the same claim you just made, which would break pip install -r.
For a comparision, NPM has a packages.json which is hand-editable, and lots of people do customize it by hand to get their NPM scripts running, but:
a) If you're new to programming, you might be confused by which language it belongs to just like a requirements.txt
b) if you peek into it, you may not think it's generated, consumed, or editted by machines because JSON format is so readable
I've used it in countless projects and it just works. It's also simple to understand.
This facilitates that.