Skip to content

Add support for poetry. #308

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

Merged
merged 1 commit into from
Feb 5, 2019
Merged

Add support for poetry. #308

merged 1 commit into from
Feb 5, 2019

Conversation

squaresurf
Copy link
Contributor

Why:

  • poetry is a Python dependency
    management and packaging tool.

This change addresses the need by:

  • Taking the same approach as pipenv.

Side effects:

  • There may be conflicts or oddities if there is a Pipfile and a
    pyproject.toml.

Copy link
Contributor

@dschep dschep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a few questions and changes

appveyor.yml Outdated
@@ -1,6 +1,7 @@
version: '{build}'
init:
- cmd: pip install pipenv
- cmd: curl https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py -o get-poetry.py && python get-poetry.py --preview --yes && rm get-poetry.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for installing the prerelease?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The export command is currently only in the prerelease version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great reason. Could you also document that in the readme as to avoid bug reports from users of the stable version of poetry.

lib/poetry.js Outdated

this.serverless.cli.log('Generating requirements.txt from pyproject.toml...');

const res = spawnSync('poetry', ['export', '-f', 'requirements.txt'], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to export 'export', '-f', path.join(this.servicePath, '.serverless', 'requirements.txt') directly and avoid having to move it later?

Copy link
Contributor Author

@squaresurf squaresurf Feb 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-f stands for format not file. The only format supported right now is requirements.txt which places the exported requirements.txt in the current directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! gotcha 👍

@@ -0,0 +1,20 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file and add a .gitignore in the tests/poetry dir to avoid checking it in since it's generated by the test process

function pyprojectTomlToRequirements() {
if (
!this.options.usePoetry ||
!fse.existsSync(path.join(this.servicePath, 'pyproject.toml'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more question. Should this check the contents of the pyproject.toml file since other tools are configured with it too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Do you know what other tools might be configured to use it as well? I thought that file was introduced by poetry.

I did add support to disable this functionality so if someone is using a pyproject.toml without poetry, then they can tell this plugin to ignore the file.

If I were to check the contents, that would most likely add another dep to this plugin so I can parse the toml. Is that something you really want me to do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what other tools might be configured to use it as well?

The only tool I know of currently is flit, but I don't think that's for installation, only publication.

I thought that file was introduced by poetry.

Not sure which introduced it, but it's specified in PEP518 and there's nothing stopping someone from making a new packaging tool that uses it

If I were to check the contents, that would most likely add another dep to this plugin so I can parse the toml. Is that something you really want me to do?

fair point. Probably not. Lets leave it like this for now and we can revisit if another package manager leveraging pep518 pops up

@squaresurf
Copy link
Contributor Author

@dschep this is nearly ready for another review, but I'm struggling to get the windows tests to pass as I'm not familiar with appveyor or windows development. Please excuse all the force pushes to this branch for now as I'm working out how to get the windows system to see the poetry install for tests.

Why:

* [poetry](https://github.com/sdispater/poetry) is a Python dependency
  management and packaging tool.

This change addresses the need by:

* Taking the same approach as pipenv.
* Install poetry on CircleCI and AppVeyor for tests.
* Use chmodSync in test.js as it works better cross platform for setting
  exact permissions on files.
  See: nodejs/node#1104

Side effects:

* There may be conflicts or oddities if there is a Pipfile and a
  pyproject.toml.
@squaresurf
Copy link
Contributor Author

@dschep sorry for the noise today with all the force pushes. I figured out a way to test on windows by installing poetry with pip which is not the ideal method as it then shares deps with other pip installed packages, but tests now pass across the board.

This PR is now ready for another review and potential merge. Thank you for all your feedback.

Copy link
Contributor

@dschep dschep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Hopefully I'll be able to merge #310 soon too, and then I'll publish v4.3.0!

@dschep dschep merged commit 2756915 into serverless:master Feb 5, 2019
@squaresurf
Copy link
Contributor Author

Oh man! #310 looks awesome 🎉

@squaresurf squaresurf deleted the poetry branch February 6, 2019 00:51
@dschep
Copy link
Contributor

dschep commented Feb 13, 2019

Hmm, @squaresurf looks like pip might already be using pyproject.toml too 😬 https://www.bernat.tech/pep-517-and-python-packaging/

@squaresurf
Copy link
Contributor Author

Interesting. Should we add a toml parser to this so we can read the purpose of the pyproject.toml? We may even want to use the pyproject.toml for pip as well in the future.

@dschep
Copy link
Contributor

dschep commented Feb 13, 2019

Yup, I think it's reasonable to add a toml parser 👍

@squaresurf
Copy link
Contributor Author

Do you have any recommendations? I'm not super deep in the node ecosystem.

@dschep
Copy link
Contributor

dschep commented Feb 13, 2019

not really. https://www.npmjs.com/package/@iarna/toml and https://www.npmjs.com/package/toml seem to be the most used, but the later only supports toml 0.4, not sure what pep517 specifies

@canassa
Copy link

canassa commented Feb 13, 2019

Hello, I would like to know if it's possible to disable this behavior? we use poetry for our local development but we export a requirement.txt from it. Your CI/CD machines don't have poetry installed on them and we are using a forked version of poetry anyway, so installing it a bit tricky.

EDIT:

Nevermind my previous comment, I just found the usePoetry option.

But I double checked and I just noticed that we are not even using Poetry at all for this project, but we do have a pyproject.toml file in order to configure Black. Maybe serverless-python-requirements is assuming that if a project has a pyproject.toml file it, therefore, is using Poetry?

@dschep
Copy link
Contributor

dschep commented Feb 13, 2019

@squaresurf
Copy link
Contributor Author

@dschep heads up that I may not be able to get to this for a while.

@dschep
Copy link
Contributor

dschep commented Feb 15, 2019

Ok. Thanks for letting me know @squaresurf

@squaresurf
Copy link
Contributor Author

I just opened #344 to address this as well as #324.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants