]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/_distutils/config.py
3 Provides the PyPIRCCommand class, the base class for the command classes
4 that uses .pypirc in the distutils.command package.
7 from configparser
import RawConfigParser
9 from .cmd
import Command
22 class PyPIRCCommand(Command
):
23 """Base command that knows how to handle the .pypirc file"""
25 DEFAULT_REPOSITORY
= 'https://upload.pypi.org/legacy/'
26 DEFAULT_REALM
= 'pypi'
31 ('repository=', 'r', "url of repository [default: %s]" % DEFAULT_REPOSITORY
),
32 ('show-response', None, 'display full response text from server'),
35 boolean_options
= ['show-response']
37 def _get_rc_file(self
):
38 """Returns rc file path."""
39 return os
.path
.join(os
.path
.expanduser('~'), '.pypirc')
41 def _store_pypirc(self
, username
, password
):
42 """Creates a default .pypirc file."""
43 rc
= self
._get
_rc
_file
()
44 with os
.fdopen(os
.open(rc
, os
.O_CREAT | os
.O_WRONLY
, 0o600), 'w') as f
:
45 f
.write(DEFAULT_PYPIRC
% (username
, password
))
47 def _read_pypirc(self
): # noqa: C901
48 """Reads the .pypirc file."""
49 rc
= self
._get
_rc
_file
()
50 if os
.path
.exists(rc
):
51 self
.announce('Using PyPI login from %s' % rc
)
52 repository
= self
.repository
or self
.DEFAULT_REPOSITORY
54 config
= RawConfigParser()
56 sections
= config
.sections()
57 if 'distutils' in sections
:
58 # let's get the list of servers
59 index_servers
= config
.get('distutils', 'index-servers')
62 for server
in index_servers
.split('\n')
63 if server
.strip() != ''
66 # nothing set, let's try to get the default pypi
67 if 'pypi' in sections
:
70 # the file is not properly defined, returning
73 for server
in _servers
:
74 current
= {'server': server
}
75 current
['username'] = config
.get(server
, 'username')
79 ('repository', self
.DEFAULT_REPOSITORY
),
80 ('realm', self
.DEFAULT_REALM
),
83 if config
.has_option(server
, key
):
84 current
[key
] = config
.get(server
, key
)
86 current
[key
] = default
88 # work around people having "repository" for the "pypi"
89 # section of their config set to the HTTP (rather than
91 if server
== 'pypi' and repository
in (
92 self
.DEFAULT_REPOSITORY
,
95 current
['repository'] = self
.DEFAULT_REPOSITORY
99 current
['server'] == repository
100 or current
['repository'] == repository
103 elif 'server-login' in sections
:
105 server
= 'server-login'
106 if config
.has_option(server
, 'repository'):
107 repository
= config
.get(server
, 'repository')
109 repository
= self
.DEFAULT_REPOSITORY
111 'username': config
.get(server
, 'username'),
112 'password': config
.get(server
, 'password'),
113 'repository': repository
,
115 'realm': self
.DEFAULT_REALM
,
120 def _read_pypi_response(self
, response
):
121 """Read and decode a PyPI HTTP response."""
124 content_type
= response
.getheader('content-type', 'text/plain')
125 encoding
= cgi
.parse_header(content_type
)[1].get('charset', 'ascii')
126 return response
.read().decode(encoding
)
128 def initialize_options(self
):
129 """Initialize options."""
130 self
.repository
= None
132 self
.show_response
= 0
134 def finalize_options(self
):
135 """Finalizes options."""
136 if self
.repository
is None:
137 self
.repository
= self
.DEFAULT_REPOSITORY
138 if self
.realm
is None:
139 self
.realm
= self
.DEFAULT_REALM