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

Make twine get password from an env variable #144

Closed
jankatins opened this issue Oct 22, 2015 · 2 comments
Closed

Make twine get password from an env variable #144

jankatins opened this issue Oct 22, 2015 · 2 comments
Milestone

Comments

@jankatins
Copy link
Contributor

I used twine with AppVoyer/travis and had to call it with --password %PYPI_PASS%, but this leaks the Password to the log :-(

I found a way not to leak it (calling it as @twine ... in batch files and set+x; twine ...; set -x in bash scripts), but it would be much easier if twine could get the things from environment variables...

@sigmavirus24 sigmavirus24 modified the milestone: next Oct 28, 2015
@jankatins jankatins changed the title Make twine get password form a env variable Make twine get password from an env variable Nov 5, 2015
@johnnoone
Copy link

It would be a nice improvement for any CI. For example it would let create specialized docker containers for building / publishing or let define masked variables into .travis.yml.

It is easy to implement this directly into argparse. here is a snippet that will fetch a value from --my-param cli parameter or a MY_PARAM environment variable:

import argparse


class EnvDefault(argparse.Action):
    """Get default from environment variable
    """

    def __init__(self, env, required=True, default=None, **kwargs):
        default = os.environ.get(env, default)
        self.env = env
        if default:
            required = False
        super().__init__(default=default, required=required, **kwargs)

    def __call__(self, parser, namespace, values, option_string=None):
        setattr(namespace, self.dest, values)


parser = argparse.ArgumentParser()
parser.add_argument('--my-param', action=EnvDefault, env='MY_PARAM',
                    help=('can also be specified using %(env)s '
                          'environment variable'))

@jankatins
Copy link
Contributor Author

@johnnoone you should add this to the argparse directly, this is great!

I'll will to to make a PR for this and #143 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants