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

Environment variable POETRY_PYPI_TOKEN_<NAME> not used by poetry publish -r <name> #2210

Closed
3 tasks done
esciara opened this issue Mar 20, 2020 · 10 comments · Fixed by #9119
Closed
3 tasks done

Environment variable POETRY_PYPI_TOKEN_<NAME> not used by poetry publish -r <name> #2210

esciara opened this issue Mar 20, 2020 · 10 comments · Fixed by #9119
Labels
area/publishing Related to PyPI/PEP 503 publishing kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@esciara
Copy link

esciara commented Mar 20, 2020

  • I am on the latest Poetry version.

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

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: 10.15.3 Mac OS X

  • Poetry version: 1.0.5

  • Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/esciara/dfc058348e597f8586d4f678cc163182

Issue

After setting the following environment variables and verifying the system is correctly set:

$ export POETRY_REPOSITORIES_TESTPYPI_URL=https://test.pypi.org/legacy/
$ export POETRY_PYPI_TOKEN_TESTPYPI=<token>
$ env | grep POETRY
POETRY_REPOSITORIES_TESTPYPI_URL=https://test.pypi.org/legacy/
POETRY_PYPI_TOKEN_TESTPYPI=<token>

and building my package:

$ poetry build
Building mypackage (0.0.1)
 - Building sdist
 - Built mypackage-0.0.1.tar.gz

 - Building wheel
 - Built mypackage-0.0.1-py3-none-any.whl

I am asked for a username a password when attempting to publish, event thought the token is passed through the environment variable:

$ poetry publish -r testpypi

Publishing mypackage (0.0.1) to testpypi
Username:

I checked the doc (section on environment variables) and it should work.

Workaround

The following workaround using username and password works:

$ export POETRY_REPOSITORIES_TESTPYPI_URL=https://test.pypi.org/legacy/
$ export POETRY_HTTP_BASIC_TESTPYPI_USERNAME=__token__
$ export POETRY_HTTP_BASIC_TESTPYPI_PASSWORD=<token>
@esciara esciara added the kind/bug Something isn't working as expected label Mar 20, 2020
@esciara
Copy link
Author

esciara commented Mar 20, 2020

Same problem occurs when using pypi through a straight poetry publish.

@esciara
Copy link
Author

esciara commented Mar 20, 2020

Can't reproduce the pb with the unit tests:

def test_publish_temp(app, environ, app_tester):
    os.environ["POETRY_REPOSITORIES_TESTREPO_URL"] = "<your_test_repo_url>"
    os.environ["POETRY_PYPI_TOKEN_TESTREPO"] = "<your_test_repo_token>"

    exit_code = app_tester.execute("publish -r testrepo")

    # should pass with 'assert exit_code == 0" or 
    # 'assert exit_code == 1" and an error message indicating a conflict 
    # if you are publishing the same package a second time

Provided you give valid <your_test_repo_url> and <your_test_repo_token>, this test will work (either success if package was never publish on testrepo or failure with error message indicating a conflict if you are publishing the same package a second time)

@hukkin
Copy link

hukkin commented Jan 7, 2021

Here's a one-liner workaround that works for me:

poetry config http-basic.pypi "__token__" "${POETRY_PYPI_TOKEN_PYPI}"

@janhurst
Copy link

seeing the same behaviour as the OP. I was expecting to only need to set the POETRY_PYPI_TOKEN_TESTPYPI environment variable

HacKanCuBa added a commit to HacKanCuBa/blake2signer that referenced this issue Jun 11, 2021
There's an still open issue where Poetry doesn't properly reads the env
variable to get the PyPi token:
python-poetry/poetry#2210
HacKanCuBa added a commit to HacKanCuBa/blake2signer that referenced this issue Jun 11, 2021
There's an still open issue where Poetry doesn't properly reads the env
variable to get the PyPi token:
python-poetry/poetry#2210
HacKanCuBa added a commit to HacKanCuBa/blake2signer that referenced this issue Jun 11, 2021
There's an still open issue where Poetry doesn't properly reads the env
variable to get the PyPi token:
python-poetry/poetry#2210
@HacKanCuBa
Copy link

Here's a one-liner workaround that works for me:

poetry config http-basic.pypi "__token__" "${POETRY_PYPI_TOKEN_PYPI}"

Doing poetry config pypi-token.pypi "$POETRY_PYPI_TOKEN_PYPI" as stated in the docs also works.

@tupui
Copy link

tupui commented Jul 12, 2021

I actually had the issue and found that it was due to the URL path!

I had this, with the URL ending with simple.

poetry config repositories.mypypi https://pypi.mypypi.com/simple/

It is working fine for the pyproject.toml but not for the env variables. Removing simple does the trick.

poetry config repositories.mypypi https://pypi.mypypi.com

So @esciara I think that in the doc it should say poetry config repositories.foo https://foo.bar instead of poetry config repositories.foo https://foo.bar/simple/

@whg517
Copy link

whg517 commented Aug 23, 2022

hi, guys.

I think the best practice is this:

first pass env:

export POETRY_HTTP_BASIC_TEST_USERNAME=__token__
export POETRY_HTTP_BASIC_TEST_PASSWORD=pypi-AgENdGVzdC5weX
# poetry not use `POETRY_REPOSITORIES_TEST`
export POETRY_REPOSITORIES_TEST=https://test.pypi.org/legacy/

config poetry repo. eg: ci action

poetry config repositories.test ${POETRY_REPOSITORIES_TEST}

publish

poetry publish -r test

@abn
Copy link
Member

abn commented Mar 5, 2024

This should have been resolved with #9015.

@abn
Copy link
Member

abn commented Mar 5, 2024

#9119 should add regression coverage for this issue.

@abn abn closed this as completed Mar 5, 2024
Copy link

github-actions bot commented Apr 5, 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 Apr 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/publishing Related to PyPI/PEP 503 publishing kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants