-
Hi, I'm quite new to Poetry, so please be patient ;-) I'm developing a library in Poetry which will be published on PyPi later. In addition, I have some example scripts which are using my Poetry developed library. But these files are in another folder, outside the Poetry project as I don't want to publish them was part of the library. But of course they need to import the new library already and I have no clue how I can achieve this: scripts in a folder a with an import like this: import MYLIBRARY where MYLIBRARY is a Peotry project in another folder b somewhere else? First publishing the lib to PyPi and then installing it would work, but during development, I don't want to publsih permanently ... I'm quite sure there is a simple solution for this, but I can't find it ;-) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Here is an example that hopefully demonstrates what you are attempting to do. I am using the latest preview release for this. But should work for latest stable as well. Create new projectI am using the source layout here since its cleaner, and prevents package imports working by virtue of python adding CWD to your PYTHONPATH. $ poetry new --src foobar
Created package foobar in foobar
$ tree foobar/
foobar/
├── pyproject.toml
├── README.md
├── src
│ └── foobar
│ └── __init__.py
└── tests
└── __init__.py
3 directories, 4 files Create example script$ cd foobar/
$ mkdir -p contrib/examples
$ cat > contrib/examples/hello.py <<EOF
> if __name__ == '__main__':
import foobar
print(foobar)
> EOF Ensure virtualenv is created and project installedThis is the step where poetry will install your project as an editable package to your project virtual environment. $ poetry install
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
Installing the current project: foobar (0.1.0) Run sample script$ poetry run python contrib/examples/hello.py
<module 'foobar' from '/tmp/foobar/src/foobar/__init__.py'> Here, the Alternatively you can also use |
Beta Was this translation helpful? Give feedback.
Here is an example that hopefully demonstrates what you are attempting to do. I am using the latest preview release for this. But should work for latest stable as well.
Create new project
I am using the source layout here since its cleaner, and prevents package imports working by virtue of python adding CWD to your PYTHONPATH.
Create example script