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

Add two new optional configuration locations to consider. #350

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Andrew Watts <andrewwatts@gmail.com>
Anna Martelli Ravenscroft <annaraven@gmail.com>
Sumana Harihareswara <sh@changeset.nyc>
Dustin Ingram <di@di.codes> (https://di.codes)
Gary Reynolds <gary.reynolds@optiver.com.au>
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ For completeness, its usage:
containing the private key and the certificate in PEM
format.

Configuration File
^^^^^^^^^^^^^^^^^^

Twine will search for a `.pypirc` file in the following locations when it is not
specified on the command line.

1. In the twine folder of the user's configuration directory
2. In the user's home directory
3. In the twine folder of the system configuration directory


Environment Variables
^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


install_requires = [
"appdirs >= 1.4.3",
"first >= 2.0.1",
"tqdm >= 4.14",
"pkginfo >= 1.4.2",
"requests >= 2.5.0, != 2.15, != 2.16",
Expand Down
2 changes: 1 addition & 1 deletion twine/commands/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def main(args):
)
parser.add_argument(
"--config-file",
default="~/.pypirc",
default=utils.PYPIRC,
help="The .pypirc config file to use.",
)
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion twine/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def main(args):
)
parser.add_argument(
"--config-file",
default="~/.pypirc",
default=utils.PYPIRC,
help="The .pypirc config file to use.",
)
parser.add_argument(
Expand Down
33 changes: 29 additions & 4 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
from __future__ import absolute_import, division, print_function
from __future__ import unicode_literals

import os
import os.path
import argparse
import functools
import getpass
import os
import os.path
import sys
import argparse
import warnings

from appdirs import site_config_dir, user_config_dir
from first import first

try:
import configparser
except ImportError: # pragma: no cover
Expand All @@ -41,11 +44,33 @@
input_func = raw_input


# Pick up a .pypirc from the first place we find it. Use appdirs to produce
# sensible locations on various platforms. Similar to pip (although they use a
# vendored version of appdirs with customisations).
DEFAULT_PYPIRC = '~/.pypirc' # backwards compatible location
PYPIRC = first(
[
# twine specific user configuration has highest precedence. On Windows
# the user may be part of a network environment with a roaming profile;
# we will prefer a local profile to a roaming one, but check for each.
# The `roaming` option has no effect on other platforms and both these
# paths will be the same.
os.path.join(
user_config_dir('twine', False, roaming=False), '.pypirc'),
os.path.join(user_config_dir('twine', False, roaming=True), '.pypirc'),
# the historical default is $HOME/.pypirc so take it next
os.path.expanduser(DEFAULT_PYPIRC),
# introduce a twine specific location to allow system wide config
os.path.join(site_config_dir('twine', False), '.pypirc'),
],
default=DEFAULT_PYPIRC,
key=os.path.exists)

DEFAULT_REPOSITORY = "https://upload.pypi.org/legacy/"
TEST_REPOSITORY = "https://test.pypi.org/legacy/"


def get_config(path="~/.pypirc"):
def get_config(path=PYPIRC):
# Expand user strings in the path
path = os.path.expanduser(path)

Expand Down