-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] How to integrate with setup.py? #209
Comments
You should be able to accomplish this with the code below. This will load the Pipfile from your current project and return the dependencies in a pip compatible list. from pipenv.project import Project
from pipenv.utils import convert_deps_to_pip
pfile = Project(chdir=False).parsed_pipfile
requirements = convert_deps_to_pip(pfile['packages'], r=False)
test_requirements = convert_deps_to_pip(pfile['dev-packages'], r=False) Let us know if you have any further questions :) |
The above is very helpful. I have run into issues with Should we |
Would it help to add |
Do not do this. |
@kennethreitz what do you mean by "this"? Do you mean the integration with setup.py, the @nateprewitt solution or the last two suggestions? |
So how do users should know they need pipenv installed? |
Since pipenv is a tool used to install things, not vice versa, there is no reason to require it in your setup.py. The thing Kenneth is warning against is importing pipenv in setup.py since it is a cli application and can cause problems.
… On Oct 17, 2017, at 9:37 AM, Iddan Ahahronson ***@***.***> wrote:
So how do users should know they need pipenv installed?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
so how can I use @nateprewitt -'s code in setup.py? |
@iddan: I have attempted to solve the Pipenv bootstrapping problem by just vendorizing a version of Pipenv into my project skeleton (https://github.com/elgertam/cookiecutter-pypackage/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/setup.py). So far I haven't had any issues, although I can't say I've had a lot of opportunities to test it out in a situation where I install a package using I can understand why we'd be worried about not running a CLI when loading setup.py, but from what I can tell, the code I'm using (copy-pasted from @nateprewitt's post here) is fairly safe. I figure this hack will no longer be necessary when |
@iddan, to be clear, that code is solely to convert a Pipfiles dependencies into a requirements.txt style format that pip will read. It looks like Kenneth redacted something from the original post but I'm not sure what. Pipenv is intended as an environment management and deployment tool, not for distribution like setup.py. We highly suggest documenting that you're using a Pipfile and possibly linking to pipenv.org for installation instructions. Treat this the same way you treat pip, it's not expected for a user to install pip every time they install a new Python package. |
I understand that perfectly. What I don't understand is what do you expect that would happen when a user downloads a package using this script and doesn't have pipenv installed |
@nateprewitt, if we want to distribute a package then (through the usual means, using |
To clarify, I assume the code in the first reply is meant to be run as part of a build, rather than actually being used in a |
Unless I'm badly mistaken, the code in https://github.com/kennethreitz/pipenv/issues/209#issuecomment-278185133 is safe to be used if you're building a wheel (=binary dist), but not if you're building sdist (=source dist). For wheels, With sdist, |
Oh, yes. @tuukkamustonen, my particular use case is an sdist. Since I don't want to require the package user to install |
If I'm reading correctly, I believe Kenneth and the other maintainers don't want us to treat That said, @isobit echoed my thoughts that
I'm personally using (3) (see https://github.com/kennethreitz/pipenv/issues/209#issuecomment-300550425) until Pipfile becomes more of a common standard, at which point I will not have any of my projects depend on Pipenv code directly, since Pipenv seems clearly meant to be a tool for managing a virtualenv based on a Pipfile, and not necessarily a Pipfile library itself. I hope this clarifies the issue based on what I've read here, but if I misspoke or said something egregious, please let me know @nateprewitt. |
I have the feeling that the issue here arise from an original misuse (IMO) of the I'm going to point to this wonderful article from Donald Stufft, setup.py v.s requirements.txt: TL;DR (but you really should read though): The
I think that's where the friction is coming from. I hope that make sense. |
I like that reply a lot, Vincent, and I absolutely agree on Having used Pipenv for a few months now, though, my usage of Perhaps this is just a peculiar way that I am using Pipenv, and I'm going against the grain (I also install my virtualenv in What am I missing here, @vphilippon? Why is |
Thanks for the info, @vphilippon. Perhaps we are going about this backwards, it sounds like what we really want is the reverse- a way use abstract deps from |
Is this already covered by the Pipfile syntax? I just noticed the requests library Pipfile uses |
First, disclaimer: My expertise is mainly with lib packages. I might miss some points. I hold the right to be wrong, and I'm ready to use it! Now, let's get to this. I'll start with this statement @elgertam:
You added
Surprisingly, your usage is not so different if you think about it:
And for that intended way to work, you want a Or, an example:
Your This may look a bit "useless", as right now its all drived by a single package, but let say you want to install your app, but with
And voilà, here's an example of the difference between your abstract requirements, and your concrete requirements. Same goes if you wanted to install
If I've explained this well enough, you can see that its just supposed to be the other way around. For I hope this all make sense somehow. |
@vphilippon You explained it quite well, and I think you've convinced me. TL;DR: Specify the abstract, absolutely necessary dependencies in |
A problem with https://github.com/kennethreitz/pipenv/issues/209#issuecomment-337409290 is that when we want to deploy our app to a server, we're not getting a reproducible environment. I mean normally, when developing a library that will be used in other projects, we want our (Manually declaring exact versions of transitive dependencies is not an on option - way too cumbersome.) In this use case, we ought to depend on a |
I'll quote Donald Stufft's article:
In other word: the app is not the package. The app is the environment, with a set of concrete dependencies installed. An app dependencies should be represented by a Personally, I would go as far as to say that the full set of pinned dependencies (including the transitive one) should be in a I have a strong feeling that Pipenv/Pipfile/Pipfile.lock follows this idea. @maintainers I'd like your input here to know if this indeed how you see all of this. I've been preaching a vision of how we should be treating dependencies, but I don't want to be talking in your stead either. |
@vphilippon I think there are different viewpoints and terminology. But ultimately, we want a list of pinned dependencies to install. So a With If there was |
@tuukkamustonen Sorry for the confusion, I was really only addressing the idea of the
I think the distinction is really important, but as you said, there's different viewpoints here. Let's agree to disagree for now. As a side note, it would be nice to have somewhere to keep going on the subject without adding noise to a specific issue. That's the kind of stuff that needs more discussion and sharing in the community, IMO.
Ah, I skipped that part at first, sorry. And it seems you're right: I'm not able to find a way to say EDIT: |
Phew, that was a lot to catch up on.
@tuukkamustonen this is intended only to be used in a standalone script for deployments, do not include it in your setup.py. This is a semi-hacky workaround from before we had
@elgertam it seems your opinions may have been swayed since this comment, but I would note that it's probably not a good idea to bundle
I think you're pretty well in line with what our vision has been for the length of the project. Thanks for compiling all of this an articulating it so well @vphilippon! It looks like the other relevant parts of this discussion have been moved into #942, so I think we're good here. Please ping me if I didn't address anything. |
Still finding out how Pipfile is meant to be used. See: https://github.com/kennethreitz/pipenv/issues/209
I followed up with a concrete proposal in pypa/pipfile#98 that I believe gives us something actionable and pragmatic that could improve DX for maintaining Python libraries. |
Thoughts? import json, jmespath
install_requires = []
with open('Pipfile.lock') as f:
context = json.loads(f.read())
install_requires.extend(map(
lambda n, v : n + v,
jmespath.search('default | keys(@)', context),
jmespath.search('default.*.version', context),
))
setup(
name='foobar',
packages=find_packages(),
setup_requires=['jmespath'],
install_requires=install_requires,
) |
@cornfeedhobo my understanding is that setup_requires does not play well with pip. Could you elaborate a bit on how you would suggest to use this sample? |
The sample will not work unless you install jmespath first because setup.py is evaluated as normal Python code. The I mentioned this in another issue, but can’t locate it atm (there are so many duplicated discussions all over the issue tracker it’s impossible to find anything anymore), so I’ll say it again: Please do not put anything not built-in inside setup.py unless you provide proper fallback, or have a perfect reason. A package containing the above |
@epot I was not aware of that @uranusjr Thanks for the well thought out answer with details. I am just exploring this whole issue, so I might return for more embarrassment. I'm also tracking pypa/pipfile#98 |
What if we don't require import json
install_requires = []
tests_require = []
with open('Pipfile.lock') as fd:
lock_data = json.load(fd)
install_requires = [
package_name + package_data['version']
for package_name, package_data in lock_data['default'].items()
]
tests_require = [
package_name + package_data['version']
for package_name, package_data in lock_data['develop'].items()
] |
@mschwager You don’t want to pin the version, or users will have a difficult time. #1921 is an example of a library using |
Thanks to @mschwager for the solution pypa/pipenv#209 (comment)
Thanks to @mschwager for the solution pypa/pipenv#209 (comment)
Thanks to @mschwager for the solution pypa/pipenv#209 (comment)
My apologies but whats the difference between using Would be great to get rid of |
No, there is no reason they have to be identical. That is quite a radical assumption, and many in the community would beg the differ. There are indeed, however, reasons that they can be identical. Pipenv does not exclude that. It is just out of the scope, and not supported by this project. You can totally build a library to support that, and leverage PEP 518, which is implrmrneted in pip 10.0, to provide build-time support. As you said, there is no reason not to allow setup.py to parse Pipfile. I look forward to you making that happen :) |
Understand that some people like the abstract libs of setup.py yet that is not a must have? I mean golang suffers from only having concrete requirements but still being able to substitute a required lib with your own fork just because it matches the name? Understandable that setup.py intergation is just not in scope. However, would be interesting to see what the long term roadmap of pipenv is. Would be great to see it become the go to tool in python. e.g. somehow replaces setup.py or generates an appropriate setup.py for the user, either way pipenv being de facto package manger is awesome. Just wondering if there is a possibility to extend the scope to include setup.py? If pipenv is like npm etc., then their package.json allows remote installation, no reason pipenv cant interact or replace setup.py, making it in scope. Am I making sense or does it sound like I am taking crazy pills? |
Thank you for thinking it be a must-have. With you considering it be so crucial, I believe we will be able to run a Pipfile-based build system in no time. |
Using
requirements.txt
I can do it:How can I do the same using Pipfile?
The text was updated successfully, but these errors were encountered: