Code Monkey home page Code Monkey logo

Comments (28)

beorn avatar beorn commented on July 17, 2024 117
% poetry init
% poetry add `cat requirements.txt`

from poetry.

sdispater avatar sdispater commented on July 17, 2024 78

Release 0.10.0 adds a new init command which covers this use case.

from poetry.

StevenACoffman avatar StevenACoffman commented on July 17, 2024 75

This works for me in bash:

$ poetry init
$ for item in $(cat requirements.txt); do   poetry add "${item}"; done

from poetry.

sdispater avatar sdispater commented on July 17, 2024 71

There is no way currently to migrate a project to poetry without building your pyproject.toml file by hand.

And, to be honest, I don't think it's a feature I will add since there are multiple ways to declare your dependencies in Python at the moment (which I want to standardized with poetry): in a requirements.txt file, in setup.py, in setup.cfg.

So, hopefully, you do not have too many dependencies and it should be a quick process with the poetry add command.

from poetry.

alairock avatar alairock commented on July 17, 2024 42

This. So much this. This is absolutely needed for a CLI like this.

from poetry.

sdispater avatar sdispater commented on July 17, 2024 33

Currently, no, it's not possible but that's something I'd like to add.

I will see if I can add it in the next feature release.

from poetry.

tajnymag avatar tajnymag commented on July 17, 2024 21

@sdispater I didn't mean to migrate a project. I meant to init poetry in an existing directory. Similar to what "git init" or "npm init" do.

from poetry.

ST33LDI9ITAL avatar ST33LDI9ITAL commented on July 17, 2024 21

from poetry.

rhtenhove avatar rhtenhove commented on July 17, 2024 10

How is this an issue if you can just do:

  1. cd project
  2. poetry init -n
  3. Realize your dependency management was awful so far
  4. poetry add package for each of your project dependencies
  5. poetry add -D package for each of your development dependencies
  6. Be done and happy you took the time to provide some sensible structure to your project, and suddenly have this great overview after thinking through what your project really depends on.

The other stuff, such as README.rst, project/ and tests/, doesn't make sense for an existing project since those are already there, or your project needs a manual cleanup. poetry can not ever know how to fix up your current project structure, because it did not adhere to the poetry expected standard, so it can be anything.

You can of course do poetry new project_name and move your stuff in there, if you really want the base structure. But again, can't do this automatically, because poetry wouldn't be able to know what to do with existing conflicting files.

from poetry.

craynic avatar craynic commented on July 17, 2024 9

Hope that CLI could support reading package list from stdin to install, something like cat requirements.txt | poetry add -

from poetry.

ST33LDI9ITAL avatar ST33LDI9ITAL commented on July 17, 2024 9

FOR /F "usebackq delims==" %i IN (cat requirements.txt) DO poetry add %i
on Windows

from poetry.

vcheckzen avatar vcheckzen commented on July 17, 2024 7

Windows PowerShell

Get-Content requirements.txt | ForEach-Object { poetry add $_.split('==')[0] }

from poetry.

ST33LDI9ITAL avatar ST33LDI9ITAL commented on July 17, 2024 7

from poetry.

jha-prateek avatar jha-prateek commented on July 17, 2024 4

FOR /F "usebackq delims==" %i IN (cat requirements.txt) DO poetry add %i
on Windows

This worked for me.
for /F "tokens=*" %i in (requirements.txt) do poetry add %i

from poetry.

sinoroc avatar sinoroc commented on July 17, 2024 3

@cglacet I didn't read the older messages in details, but yes, seems like potentially "dangerous" advice.

It depends what requirements.txt contains exactly. Sometimes it is the raw output of pip freeze sometimes it is a meaningful list. There is no rule. People can put whatever they want in it.

If it is a carefully curated list of direct top level install dependencies (i.e. import dependencies), then it is all good. Otherwise, it could lead to issues down the line.

For sure do not add the output of pip freeze to your pyproject.toml.

from poetry.

ekhaydarov avatar ekhaydarov commented on July 17, 2024 2

I happened to have an existing pyproject.toml file and it just throws an error that it already exists. meaning i manually need to add the poetry stuff. Small thing, but some feedback nonetheless

from poetry.

kakulukia avatar kakulukia commented on July 17, 2024 1

I was just about to ask the same question. Being turned down by pipenv multiple times now (it still has not earned even the 1.0 release stamp), id like to try poetry, but i dont want to create the toml file by hand. I wont bother calling poetry add a few times, but i dont wanna mess with the files syntax by hand. Looking forward to that feature!

from poetry.

sinoroc avatar sinoroc commented on July 17, 2024 1

@cglacet

Build dependencies go into the requires field of thebuild-system section. Typically for a poetry project the only build dependency is poetry itself or poetry-core for more recent projects:

[build-system]
requires = ['poetry-core>=1.0.0']
# ...

Install dependencies are the things that you want to be installed alongside your project, typically because your code imports them at run time. So the recommendation is to list only the libraries your code actually imports directly. Those belong in the [tool.poetry.dependencies] section.
And you definitely should not add the dependencies of your dependencies to that section.

Development dependencies are typically the tools you use while working on your code, so things like pytest, pylint, black, etc. and they belong in the tool.poetry.dev-dependencies section.

pip freeze would give you everything that is currently installed in the environment, so it contains your dependencies but also the dev dependencies and the dependencies of your direct dependencies and the dependencies of your dev dependencies. So pip freeze is definitely not the thing that you want.

from poetry.

emlazzarin avatar emlazzarin commented on July 17, 2024 1

There are many projects that already have pyproject.toml but lack a Poetry section, leading to an error like:

[tool.poetry] section not found in /Users/elazzarin/code/pytrends/pyproject.toml

It seems relatively straightforward to resolve by hand, so may be helpful to add to the poetry init process if someone wants to migrate to Poetry smoothly.

from poetry.

tajnymag avatar tajnymag commented on July 17, 2024

@sdispater OK, thank you.

from poetry.

jared-mackey avatar jared-mackey commented on July 17, 2024

+1

from poetry.

kakulukia avatar kakulukia commented on July 17, 2024

Awesome .. gonna try this tomorrow!

from poetry.

caleb15 avatar caleb15 commented on July 17, 2024
FOR /F "usebackq delims==" %i IN (cat requirements.txt) DO poetry add %i

This doesn't add packages with version pinning.

ex: it adds Django instead of Django==1.11.20

I would suggest removing the "usebackq delims=="

from poetry.

jaepil-choi avatar jaepil-choi commented on July 17, 2024

Yeah init command was added but what I would expect is installing all stocks components - .toml, foo_projectname/, test_foo_projectanme/, README.rst. Current init option prompts an empty .toml file, which doesn't seem necessary.

from poetry.

cglacet avatar cglacet commented on July 17, 2024

Are we really supposed to put all requirements in poetry (pip freeze output)? Or are we only supposed to add build dependencies?

from poetry.

cglacet avatar cglacet commented on July 17, 2024

@sinoroc Thanks for the very quick and precise answer. I was questioning the answers proposing to directly add everything from requirements.txt which I think in practice often contains the whole pip freeze output.

from poetry.

CarlosLugones avatar CarlosLugones commented on July 17, 2024

from poetry.

github-actions avatar github-actions commented on July 17, 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.

from poetry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.