Skip to content
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

Export requirements.txt #100

Closed
Tonkonozhenko opened this issue May 11, 2018 · 14 comments
Closed

Export requirements.txt #100

Tonkonozhenko opened this issue May 11, 2018 · 14 comments

Comments

@Tonkonozhenko
Copy link

Hi @sdispater

I want to use poetry for managing my dependencies for AWS Lambda functions with serverless.
For this, it would be awesome to have export to requirements.txt to use it in serverless plugin.

WDYT about this?

@jacebrowning
Copy link
Contributor

I also need something like this to deploy on Heroku.

@jacebrowning
Copy link
Contributor

jacebrowning commented May 17, 2018

I added this to my tooling as a workaround:

# Makefile

requirements.txt: pyproject.lock
	poetry run pip freeze > $@

@Tonkonozhenko
Copy link
Author

It doesn't work for me:

$ poetry run pip freeze    
                                 
[ImportError]     
No module named utils.appdirs  
                                 
run <args> (<args>)...

@jacebrowning
Copy link
Contributor

@Tonkonozhenko Have $ poetry lock and $ poetry install run successfully?

@cauebs
Copy link
Contributor

cauebs commented Jun 27, 2018

If the sole purpose is deploying to Heroku, exporting Pipfile and Pipfile.lock would also work.

@kadrach
Copy link

kadrach commented Aug 2, 2018

I am also using poetry together with tools for Lambda functions (chalice in this case) that require a requirements file. Native support in either poetry or chalice would be nice, but I currently work around this by generating the requirements file in a specific Make target:

# See https://github.com/sdispater/poetry/issues/100
define get_requirements
import tomlkit
with open('pyproject.lock') as t:
    lock = tomlkit.parse(t.read())
    for p in lock['package']:
        if not p['category'] == 'dev':
            print(f"{p['name']}=={p['version']}")
endef
export get_requirements

requirements.txt: pyproject.lock
        python -c "$$get_requirements" > $@

While not extensively tested, this works by explicitly pinning all transitive requirements in the requirements file.

@yunti
Copy link

yunti commented Sep 5, 2018

@cauebs That would work but as per the project readme is probably better to go with exporting requirements.txt rather than the proprietary pipfile.
Having this feature together with the already existing one of being able to specify the location of a virtualenv (eg /venv #213) would mean pretty much full backward compatibility to work with any cloud platform or tooling (eg pycharm etc...).

It would be ideal if the requirements.txt could be automatically kept in sync with the pyproject.toml file as that would make things less likely to be messed up.

@etienned
Copy link

etienned commented Sep 21, 2018

I'm deploying with Docker and having a requirements.txt is much simpler for this. Currently I'm using pipenv to create this requirements.txt but I definitely prefer to work withpoetry. I have prototyped a function to export a requirements.txt from poetry with markers (platform and python_version) and package source (git, etc.). It looks to work well but I'm sure I don't cover all the cases (in for platform, etc.). Also I didn't add a CLI command for the moment, but this command could be perhaps named freeze. A possibility to keep it in sync as suggested by @yunti is also a good idea but this needs more thinking (optional or not, sync when running which commands, etc?). I'm open to comments and can do a pull request if needed. But if @sdispater or someone else want to incorporate and adapt my code, I'll be happy!

Here's my code: https://gist.github.com/etienned/686d6743d66415eb39a715bb369fe2f6

@etienned
Copy link

etienned commented Jan 8, 2019

For information, this is added here: #675.

@Tonkonozhenko
Copy link
Author

@etienned thanks for the notification.
@sdispater thanks for the implementation.

@Congee
Copy link

Congee commented Feb 6, 2019

FYI, export current appends hash to an editable source repo, to which pip install fails
see pypa/pip#4995

@r0fls
Copy link

r0fls commented Oct 21, 2019

Is this going to be backported to the python 2 version of poetry?

@epogrebnyak
Copy link

FYI, export current appends hash to an editable source repo, to which pip install fails

poetry export --without-hashes > requirements.txt works now.

Copy link

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants