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

How to use poetry when developing a package #3979

Closed
2 tasks done
FenryrMKIII opened this issue Apr 20, 2021 · 5 comments
Closed
2 tasks done

How to use poetry when developing a package #3979

FenryrMKIII opened this issue Apr 20, 2021 · 5 comments
Labels
area/docs/faq Frequently duplicated/potential addition to FAQ kind/question User questions (candidates for conversion to discussion)

Comments

@FenryrMKIII
Copy link

FenryrMKIII commented Apr 20, 2021

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

I am currently developing a package with poetry. My package uses a structure such as this one :

--my_package
   --bin
   --src
      --my_package

I have well understood the use of Poetry I think. I also succeeded in installing the package in a test environment. In my .toml file I have the following lines to handle my particular hierarchy:

packages = [ 
	{include = 'my_package', from='src'}
	]

What I struggle with is how to use Poetry during development for my case.

Indeed, in my case, I have a bin directory.
This directory contains launch scripts that needs to import my_package to call specific functions/methods. The idea is to provide the user with examples.
I would like to be able to test my_package "online" along with the launch scripts without the need to use commands such as poetry build/poetry install in a separate test environments.
And I don't see a clean way of making this work with poetry unless I modify the sys.path variable during development to include the src directory.
Does anyone have a clean way of handling such a use case ? Or am I missing something ?

@FenryrMKIII
Copy link
Author

FenryrMKIII commented Apr 20, 2021

To try to make things work, I stumbled across this discussion #3962 and thought this might be the solution.

I created a new virtual environment with poetry

 poetry env use python

and spawned a new shell

 poetry shell

Then I installed my package in this new environment :

 poetry install

which installed the dependencies and the package itself.

I tested with

import my_package

and it works. It also automatically takes the updates I make to the package online. All this without putting the following line in my toml file :

[tool.poetry.dependencies]
my_package = {path = "../../my_package", develop = true}

I don't understand why it works. But it works.

@gc-ss
Copy link

gc-ss commented Apr 24, 2021

You found the solution.

You can now generate the my_package = {path = "../../my_package", develop = true} entry using the --editable option that was merged in this week.

@FenryrMKIII
Copy link
Author

You found the solution.

You can now generate the my_package = {path = "../../my_package", develop = true} entry using the --editable option that was merged in this week.

Hey thanks for the reply. But do you understand why it works without this line? That’s why I am bit puzzled :)

@finswimmer
Copy link
Member

Hello @FenryrMKIII,

when you run poetry install these things happens:

  1. create a venv if no one already exists or is activated
  2. if no poetry.lock file exists: resolves your dependencies and write the result in the poetry.lock
  3. install the packages locked in the poetry.lock
  4. install the current project in an editable mode

Step 4 is the reasons why you have no problem to import your packages modules if you are in the activated environment.

fin swimmer

@finswimmer finswimmer added kind/question User questions (candidates for conversion to discussion) area/docs/faq Frequently duplicated/potential addition to FAQ labels Jun 23, 2021
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
area/docs/faq Frequently duplicated/potential addition to FAQ kind/question User questions (candidates for conversion to discussion)
Projects
None yet
Development

No branches or pull requests

3 participants