The default server in the distutils server configuration is in ~ / .pypirc

I want to have multiple PyPI servers in my ~/.pypirc , so I can easily publish to different servers depending on the project.

My use case: I have some internal projects that I want to publish on the internal PyPI server ( https://pypi.internal ), and I have some public projects that I want to publish in public PyPI.

This is my current attempt, but it does not work. I want the default internal , and I need to add the -r pypi command (to the setup.py command) if I want to publish to a public server.

 [distutils] index-servers = internal pypi [internal] repository: https://pypi.internal username: brad [pypi] username: brad 

Where am I going wrong?

+4
source share
2 answers

It is strange that there is no built-in support for the default installation, but there are two options here that can help you get around it.

Option 1: Perhaps the easiest solution would be to leave your ~ / .pypirc script intact and create shell aliases for your internal and public downloads. This can give you more control over customization for your workflow.

Given this .pypirc file:

 [distutils] index-servers = pypi internal [pypi] repository: http://pypi.python.org/pypi username: brad password: <pass> [internal] repository: http://localhost:8080 username: brad password: <pass> 

Create shell aliases (put these definitions in your rcfile shell, for example ~ / .bashrc ):

 alias ppup_internal='python setup.py bdist_egg sdist upload -r internal' alias ppup_public='python setup.py bdist_egg sdist upload' 

Using:

 % ppup_internal ... running upload Submitting dist/foo-0.0.0.tar.gz to http://localhost:8080 Server response (200): OK 

Option 2: Hack: You can bypass the default settings by setting the default repository name at the top of the setup.py scripts.

 from distutils import config config.PyPIRCCommand.DEFAULT_REPOSITORY = 'internal' from setuptools import setup setup( name='foo', ... 

Output:

 % python setup.py sdist upload ... running upload Submitting dist/foo-0.0.0.tar.gz to http://localhost:8080 Server response (200): OK % python setup.py sdist upload -r pypi ... running upload Submitting dist/foo-0.0.0.tar.gz to http://pypi.python.org/pypi Server response (200): OK 

Background:. If you specify the [distutils] switch in .pypirc , the default pypi url for the boot command is when the -r [repo] argument is omitted. The corresponding code is in distutils.config.PyPIRCCommand :

 class PyPIRCCommand(Command): DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi' def _read_pypirc(self): if os.path.exists(rc): self.announce('Using PyPI login from %s' % rc) repository = self.repository or self.DEFAULT_REPOSITORY realm = self.realm or self.DEFAULT_REALM 

In the old .pypirc format, the [server-login] section was expected, which was much less flexible since it only defines one target repository. This is not a feasible option, as the [pypi] section below will be unusable:

 [server-login] repository: http://localhost:8080 username: brad password: <pass> [pypi] repository: http://pypi.python.org/pypi username: brad password: <pass> 

Now, by default, distutils will use this target:

 % python setup.py sdist upload ... running upload Submitting dist/foo-0.0.0.tar.gz to http://localhost:8080 Server response (200): OK 

But you cannot access any other repositories: it uses the properties [server-login] by default:

 % python setup.py sdist upload -r pypi ... running upload Submitting dist/foo-0.0.0.tar.gz to http://localhost:8080 Server response (200): OK 
+12
source

A similar problem is when you want to install the internal PyPI package repository. In this scenario using pip install -e . , not python setup.py develop completely fixes this problem. See Can I use `pip` instead of` easy_install` for the python setup.py install` dependency?

0
source

Source: https://habr.com/ru/post/1345648/


All Articles