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

Envs do not works #928

Closed
FrancescoSaverioZuppichini opened this issue Oct 14, 2022 · 8 comments
Closed

Envs do not works #928

FrancescoSaverioZuppichini opened this issue Oct 14, 2022 · 8 comments
Labels
support Users asking for help using twine

Comments

@FrancescoSaverioZuppichini
Copy link

Hi guys,

Setting the following env variables

TWINE_USERNAME="__token__"
TWINE_PASSWORD="...."
TWINE_NON_INTERACTIVE="true"

and then call

 twine upload dist/* 

results in twine asking me for credentials

Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: 

Thanks

@usrme
Copy link

usrme commented Oct 14, 2022

Someone correct me if I'm wrong, but you are starting Twine in a child process, so any variables created by writing, for example, TWINE_USERNAME="..." in a shell and pressing Enter will not persist for child processes started by that shell.

You need to either string together the creation of all of the required variables, as such:

TWINE_USERNAME="__token__" \
TWINE_PASSWORD="...." \
TWINE_NON_INTERACTIVE="true" \
twine upload dist/* 

Notice the separating backwards slashes.

Another option is to explicitly export them in either your current shell session or in somewhere like your personal .bashrc file:

export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="...."
export TWINE_NON_INTERACTIVE="true"

If you opt for export within the current shell, then remember that then those values will not persist until the next session.

Yet another option is to use a .pypirc file as described here: https://packaging.python.org/en/latest/specifications/pypirc/.

@FrancescoSaverioZuppichini
Copy link
Author

Thanks @usrme. Sorry for the lack of context, I've listed of variable I have set, not how I've set them. Setting the variables both inside an .env file (and sourcing it) or exporting them directly in the shell doesn't change the issue

@usrme
Copy link

usrme commented Oct 15, 2022

Just a few questions:

  • what shell are you using?
  • what version of Twine are you using?
  • what version of Python are you using?
  • are you able to echo any of the variables?
    • for example: echo "$TWINE_USERNAME"
  • does chaining the setting of the variables and directly calling the command not work either?
    • for example: TWINE_USERNAME="__token__" TWINE_PASSWORD="...." TWINE_NON_INTERACTIVE="true" twine upload dist/*
  • have you tried using python -m twine instead of just twine?

@FrancescoSaverioZuppichini
Copy link
Author

what shell are you using?

zsh, but it shouldn't matter

what version of Twine are you using?

twine version 4.0.1 (importlib-metadata: 5.0.0, keyring: 23.9.3, pkginfo: 1.8.3, requests: 2.28.1, requests-toolbelt: 0.10.0, urllib3: 1.26.12)

what version of Python are you using?

Python 3.9.13e

are you able to echo any of the variables?

yes

does chaining the setting of the variables and directly calling the command not work either?

It doesn't work

have you tried using python -m twine instead of just twine?
yes, still the issue persist

@FrancescoSaverioZuppichini
Copy link
Author

Forcing the user and ps with variables, works

twine upload -r testpypi dist/* -u ${TWINE_USERNAME} -p ${TWINE_PASSWORD}

@bhrutledge bhrutledge added the support Users asking for help using twine label Dec 5, 2022
@bewczardski
Copy link

I'm experiencing the same issues as @FrancescoSaverioZuppichini, for my issue I have the following Jenkinsfile:

    agent {
        kubernetes {
            inheritFrom 'k8s-agent'
            yamlMergeStrategy merge()
            defaultContainer 'python311'
            yaml """\
                spec:
                  containers:
                    - name: python311
                      image: python:3.11-slim-bookworm
                      imagePullPolicy: Always
                      command:
                        - cat
                      tty: true
                    """.stripIndent()
        }
    }
    stages {
        stage('Package/Upload') {
            environment {
                JFROG_CRED = credentials('artifactory')
                TWINE_USER = "$JFROG_CRED_USR"
                TWINE_PASSWORD = "$JFROG_CRED_PSW"
                TWINE_REPOSITORY_URL = '<repo url>'
                TWINE_NON_INTERACTIVE = 'true'
            }
            steps {
                sh '''pip install twine setuptools build
                      python -m build
                      twine upload dist/*'''
            }
        }
    }
}

This results in �[31mERROR �[0m NonInteractive: Credential not found for username.

If I modify the twine upload command to include username/password flags it works without issue.
twine upload dist/* --username $TWINE_USER --password $TWINE_PASSWORD

@bewczardski
Copy link

Sorry I just realized where my issue was, I was using the wrong ENV Variable name, TWINE_USER vs the expected TWINE_USERNAME.

For what its worth, correcting the env variable name worked without issue.

@sigmavirus24
Copy link
Member

I suspect that @usrme actually likely diagnosed the original issue correctly. Unless the variables are exported properly, trying may not actually see them in the environment described in the original issue description. As such, I'm making this as completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Users asking for help using twine
Projects
None yet
Development

No branches or pull requests

5 participants