-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support for Poetry #17
Comments
Having poetry support would be ideal for us. Are you able to share how you tested this backend with the branch / PR here python-poetry/poetry#4086? Any guidance you can give would be greatly appreciated. |
@jamesthompson I installed Poetry from that users branch like so:
I wouldn't recommend this for production or even local development, as it's untrusted code that could be changed or go away at any time. But it does work! |
I'm assuming you have to set up the |
@jamesthompson No, you should follow Poetry's docs here instead: https://python-poetry.org/docs/repositories/#using-a-private-repository |
I worked around the issue by adding some scripts to my Dockerfile by adding: |
@Algirdyz did you fix that error? |
Update, for those following this thread: python-poetry/poetry#4086 was released in |
@di thank you for the comment I am going to test it. |
@di I've just managed to build and install I'm doing the following: adding the following dependencies to my [tool.poetry.dependencies]
python = "^3.8"
"keyrings.google-artifactregistry-auth" = "^0.0.3"
keyring = "^23.0.1" running running Then running the then and it's still prompting for the uername, so I added
If you get chance would you be able to confirm if we need to set up any other files or environment variables to have the keyring library pick up the gcloud auth login creds it writes to the local environment. Any basic guidance on the steps needed to publish to a GCP artifacts registry would be greatly appreciated. |
Hi @jamesthompson, here's what I did to test this, starting from an empty directory:
And then to install the package as a dependency of another project:
No other files or configuration should be necessary. |
@jamesthompson make sure you authenticate to google cloud first. It worked for me as well. check my testing in this repo: https://github.com/Bharathkumarraju/poetry-gcp-pypi |
@Bharathkumarraju Yeah no I got this to work fine as well. Thanks a lot @di for the quick help, it's really appreciated. |
I cannot get it to work. Do I have to export GOOGLE_APPLICATION_CREDENTIALS or do gcloud auth login? I've tried both of them but with no luck. poetry --version |
@TaridaGeorge you can try to run this |
@TaridaGeorge how did you install poetry? With pip or installation script? If the latter one - poetry will be installed in it's own venv and you have to add GCP keyring in there with |
I had it installed via pipx and I taught that this could be the problem. I've installed the keyrings.google-artifactregistry-auth package into the pipx created venv for the poetry app but with no results. I've then uninstalled the poetry from the pipx and I've installed it according to the github page:
Is not working.
If I try to publish my package via twine with the |
@TaridaGeorge I had exactly the same problem. Even by doing what @Kreshu mentionned with: poetry plugin add keyrings.google-artifactregistry-auth Didn't solve the problem. pip install poetry==1.2.0a2
pip install keyrings.google-artifactregistry-auth
gcloud auth application-default login
poetry config repositories.google https://europe-python.pkg.dev/project_id/repo-name
poetry publish -r google You don't put Hope that helps. |
This is exactly the approach that worked for me. After a fair amount of struggling trying to get it work with poetry installed from the script I finally removed it manually (on OSX with zsh+oh-my-zsh) by deleting |
I tried again on my side and saw something really interesting. Normally, when running: poetry plugin add keyrings.google-artifactregistry-auth
But, from the documentation, keyring.backends.Windows.WinVaultKeyring (priority: 5)
keyring.backends.fail.Keyring (priority: 0)
keyring.backends.chainer.ChainerBackend (priority: -1) Something is happening with I tried then to install the package from poetry's pip install keyrings.google-artifactregistry-auth And checked the output again: keyring.backends.chainer.ChainerBackend (priority: 10)
keyrings.gauth.GooglePythonAuth (priority: 9)
keyring.backends.fail.Keyring (priority: 0)
keyring.backends.Windows.WinVaultKeyring (priority: 5) I then simply configured poetry's to use another registry for publishing: poetry config repositories.google https://europe-python.pkg.dev/project_id/repo-name
poetry build
poetry publish -r google and it worked as expected! Also, for retrieving, you'll need to add: [[tool.poetry.source]]
name = "google"
url = "https://europe-python.pkg.dev/project_id/repo-name/simple/" and sadly, because poetry creates a new venv for you, you'll need to add "keyrings.google-artifactregistry-auth" as a dependency. (i am putting it as a dev dependency for now) |
Just to be clear; it is not possible to use google python artifact registry with poetry 1.1.12? It is only possible with bleeding edge poetry (which is not recommended in production AFAIK)? |
@mr-bjerre To me yes, poetry |
For people like me that tried to make this work, I finally have found a very reproducible way that you could propagate to your teams in case you really need the keyring to work properly, Personally I am using pip freeze > unins ; pip uninstall -y -r unins ; del unins Install pip install git+https://github.com/python-poetry/poetry.git@master Installing from the master branch is a MUST if you are working on Windows as the last pre-release version is missing a crucial fix: python-poetry/poetry#4549 Install the Google keyring helper: pip install keyrings.google-artifactregistry-auth If you're using pyenv rehash Finally, log in with your user credentials (you will require the correct permissions in GCP for pull/push packages) gcloud auth login From there, go over your [[tool.poetry.source]]
name = "private-pypi"
url = "https://europe-python.pkg.dev/<PROJECT_ID>/<REPO_NAME>/simple/"
secondary = true You should be able to fetch private package from this registry. To publish packages, simply configure poetry config repositories.private-pypi https://europe-python.pkg.dev/<PROJECT_ID>/<REPO_NAME>/ and then publish with poetry publish -r private-pypi --build I hope this helps. |
Thanks a lot @MadJlzz for the replicate. I had been having trouble with poetry catching up with the gcloud's keyring and it seems that performing |
@Vichoko I started working on a plugin for poetry that would install automatically I made it work with the last commit present on curl -sSL https://install.python-poetry.org | python3 - --git https://github.com/python-poetry/poetry.git@master and poetry plugin add poetry-artifactregistry-plugin |
@MadJlzz , you are a hero, thank you. Quick question: I have to run this command to get it to install my private artifact repo package, otherwise it simply looks in PyPi public and fails with 404 Not Found. Am I potentially doing something wrong? Command:
I tried Thanks again for your posts, very helpful sir. |
@japerry911 Here's what I have on my side: [[tool.poetry.source]]
name = "<name>"
url = "https://europe-python.pkg.dev/<google-project-id>/ngt-python/simple/"
default = false
secondary = true The |
Thanks for your help! I was able to get it to work in Cloud Build woohoo! |
Is there any estimated time for the first stable Poetry 1.2 release? |
Not sure if this will help anyone but to get this to work with poetry installed from the installer (instead of pip), you can run |
This is the way to go indeed when 1.2.0 will be released! To rephrase, |
You can also install preview version using this command: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - -p Also side note for someone using docker: don't forget to update lock file, adding packages by hands into |
What worked for me locally (combination of things from comments above):
[[tool.poetry.source]]
name = "company-common-repo"
url = "https://europe-python.pkg.dev/my_project_id/company-common-repo/simple"
secondary = true
default = false
company-common-package = {version = "0.1.0", source = "company-common-repo"} Additional For publishing:
For installing packages from private repo in Dockerfile: FROM python:3.9.12
WORKDIR /app
RUN pip3 install --upgrade pip
RUN pip install poetry==1.2.0b3
RUN pip3 install keyrings.google-artifactregistry-auth
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false
RUN --mount=type=secret,id=google_creds,target=/app/google_creds.json export GOOGLE_APPLICATION_CREDENTIALS="/app/google_creds.json" && poetry install --no-dev --no-interaction --no-ansi --no-root
COPY ./src/ /app/src/
# Install root package now, it will help caching when building locally.
RUN poetry install --no-dev --no-interaction --no-ansi
USER 1001
ENTRYPOINT ["python3"]
CMD ["-m", "company_common"] To build with docker:
Gitlab pipeline for publishing package to artifacts on pushing tag. #!/bin/bash
# To be run from gitlab CI
set -euo pipefail
pip install poetry==1.2.0b3
CURRENT_PACKAGE_VERSION=`poetry version -s`
echo "Package version in poetry: $CURRENT_PACKAGE_VERSION"
TAG=$CI_COMMIT_TAG
if [[ "v$CURRENT_PACKAGE_VERSION" != "$TAG" ]]; then
echo "Tag and Poetry package version mismatch, please check both."
exit 1
fi
# Build and push
pip3 install keyrings.google-artifactregistry-auth
poetry config repositories.company-common-repo https://europe-python.pkg.dev/my_project_id/company-common-repo/
poetry publish -r company-common-repo --build
echo "Done."
echo "https://console.cloud.google.com/artifacts/python/my_project_id/europe/company-common/company-common-package/$CURRENT_PACKAGE_VERSION?project=my_project_id" |
To flag, Poetry 1.2 has now been released. However, with the latest version of # Part of pyproject.toml
[[tool.poetry.source]]
name = "<name>"
url = "https://europe-python.pkg.dev/<google-project-id>/ngt-python/simple/"
default = false
secondary = true poetry self add "keyrings.google-artifactregistry-auth"
poetry add <package_name> Error message:
If you replace the above poetry self add "keyrings.google-artifactregistry-auth==1.0.0" everything seems to work fine. |
Sorry about that, I think the issue was due to a dependency from the keyring library. Could you try with the latest version of Thanks! |
Thanks for the rapid response @megan-kuo!! Seems to have fixed it! |
Seems that the support is done then! Should we close this @di ? |
@MadJlzz - should clarify, I've not tested publishing a package to Google Artifact Registry with Poetry 1.2, only reading from it! Might be a few days/weeks before I get to it (I last checked with Poetry 1.2.0b2, and it was working). |
I don't work on this project anymore, I'll defer to @megan-kuo! |
Sure thing!
@ESKYoung, I just tried on Windows 11 with Poetry poetry source add demo https://europe-west1-python.pkg.dev/madsanbox/poetry-120-demo/simple/ # this is used for pulling packages
poetry config repositories.demo https://europe-west1-python.pkg.dev/madsanbox/poetry-120-demo/ # this is used for pushing packages If it helps, I can provide a working example as a kickstart. |
@MadJlzz sounds good! I've confirmed package publication works on macOS as well! |
@megan-kuo I think we can close this one |
will do, thanks! |
still facing with 1.2.2: |
Works with version 1.2.0 and 1.2.2 but not with version 1.3.0 |
it looks like we have issue #36 open tracking this issue. I'm not very familiar with poetry but if you would be willing to send over a pull request I'd be happy to take a look. thanks! |
Such a great contribution @adamwojt (#17 (comment)) Thank you so much. 🎉 ❓ Just a few questions regarding:
👉 Is it a service account credentials json? The point is to allow access by user to the artifactory and not creating a single service account for everybody as it carries certain security risks. |
@Matesanz Thanks! |
So we have migrated all our private dependencies from git to the artifact registry. And most of the team has it working already. But we have some people having lots of issues installing the python, poetry & gcloud auth correctly. I've personally assisted these people and mimicked the exact steps but it seems that the keyring is failing to retrieve My steps are the following:
This fails with a bunch of 401 Unauthorized errors. The user has all permissions on the artifact registry. I feel the keyring isn't retrieving gcloud credentials, because if I run the following code: import keyring
# Get the Google Cloud credentials from the keyring
credentials = keyring.get_password("google-artifactregistry-auth", "default")
if credentials:
print("Credentials found in the keyring.")
# Do something with the credentials, such as decoding them and checking their contents
else:
print("Credentials not found in the keyring.") It prints: |
Unable to publish to a private GCR without Steps to reproduce:
This works fine in my local environment where I have gcloud configured. |
Realiving this thread for a recent update. The
At which point, your poetry binaries will be able to find the gauth keyrings module. Surprisingly the docs are scanty on this approach completely. Can we please update the docs on this? Similar issue mentioned here python-poetry/poetry#8618 |
This project does not currently officially support Poetry (https://github.com/python-poetry/poetry).
The ability to support Poetry is currently blocked on python-poetry/poetry#4086.
If/when that issue is resolved, we should revisit this issue and determine if Poetry is something we're able to officially support.
The text was updated successfully, but these errors were encountered: