hatch
hatch copied to clipboard
Cannot publish to private registry
The documentation is not clear about the -r option to hatch publish - like is it an alias in ~/.pypirc as ChatGPT suggests? (probably incorrectly, I surmise). Or could it be a URL? Who knows? I tried:
hatch -v publish -r myrepo
...where ~/.pypirc contained:
[distutils]
index-servers = myrepo
[myrepo]
repository = https://mycompany.com/pypi/private/artifactory
username = wolf
password = <artifactory-token>
...but I just got the error:
$ hatch -v publish -r myrepo
Enter your username [__token__]:
Enter your credentials:
dist/mypackage.tar.gz ... failed
Error uploading to repository: artifactory - Request URL is missing an 'http://' or 'https://' protocol.
So then I tried:
$ hatch -v publish -u wolf -a <artifactory-token> -r artifactory
...same error - then, assuming it doesn't look at ~/.pypirc as ChatGPT suggests, I added this section to
my pyproject.toml:
[publish.index.repos.artifactory]
url = "https://mycompany.com/pypi/private/artifactoryl"
user = "wolf"
auth = "<artifactory-token>"
then did: hatch -v publish -r myrepo - same errors as above.
Finally I tried:
$ hatch -v publish -u wolf -a <artifactory-token> -r https://mycompany.com/pypi/private/artifactory
dist/mypackage.tar-gz ...success
dist/mypackage..py3-none-any.whl ... success
That worked, but how can I supply at least the URL in a file?
Dupe of https://github.com/pypa/hatch/issues/948
The "publish" table of settings needs to be in your global configuration, not in the pyproject.toml.
Refer to https://hatch.pypa.io/latest/config/hatch/ for details on the location of the global config file.
Perhaps the docs should be updated to reflect that the documentation is referring to the global config. In it's current state and for someone who is just starting out witch hatch it is confusing.
I agree, the documentation is a bit sparse with respect to publishing.
Is there any reason that this config cannot be per project? It would be easier for my team if the publish configuration could be part of pyproject.toml, so when they clone the project repository from our private git server, they can also publish back to our private repository, independent of the team member's global Hatch config.
As it is now, I think I will create a script in the build env that calls twine and have users edit a .pypirc file with our private repository.