Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload the python packages to Nexus sonartype private repo

Tags:

python

pypi

nexus

I have configured the Nexus-OSS-3.14 private Python artifact server on aws cloud. I want to be maintain all my project related Python packages on my private repository server.

I downloaded the all the Python packages on my local Linux box and I want to be upload all the Python packages to private Python artifact server.

I have tried curl put request and I didn't upload and your help is needed to complete this.

I have tried curl put request:

curl -v -u admin:admin --upload-file boto3-1.9.76-py2.py3-none-any.whl https://artifact.example.com/repository/ASAP-Python-2.7-Hosted/

When I used that command and I get 404 response.

like image 428
Anand Palani Avatar asked Jun 14 '19 06:06

Anand Palani


People also ask

How do I add artifacts to sonatype nexus?

To upload a pom file and its associated artifacts add all the files into the upload screen at the same time. Be sure to specify the extension of the pom file as pom ; this will let Nexus Repository know it should be taking the coordinates from the pom file, not the UI.

How do I publish a private package in python?

Build the python package twine : publishes the package on a package registry (a private one or PyPi). Install the requirements. To keep things simple, we will use the python virtual environment. Create a file setup.py and fill it with the information about your package.


2 Answers

Pip (yarn) for download. Twine for upload. Configuration:

be careful with trailing slashes!

Download with pip (yarn)

pip config edit [--editor [nano|code|...]] [--global|--user] for edit config

[global]
index = https://nexus.your.domain/repository/pypi/pypi
index-url = https://nexus.your.domain/repository/pypi/simple

Or set environment variables. Dockerfile for example:

ENV \
  PIP_INDEX=https://nexus.your.domain/repository/pypi/pypi \
  PIP_INDEX_URL=https://nexus.your.domain/repository/pypi/simple

Or use command line args pip install --index

Upload with twine

Edit .pypirc:

[distutils]
index-servers =
pypi
[pypi]
repository: https://nexus.your.domain/repository/pypi-hosted/
username: nexususername
password: nexuspassword 

Or environment

ENV \
  TWINE_REPOSITORY_URL=https://nexus.your.domain/repository/pypi-hosted/ \
  TWINE_USERNAME=nexususername \
  TWINE_PASSWORD=nexuspassword

Or command line

twine upload --repository-url

like image 144
pavel.smolkin Avatar answered Oct 22 '22 07:10

pavel.smolkin


I think the recommended approach is to use twine, something like this should work:

pip install twine
twine upload --repository https://artifact.example.com/repository/ASAP-Python-2.7-Hosted/ boto3-1.9.76-py2.py3-none-any.whl

It should ask for your username and password. To make life a bit easier you can create $HOME/.pypirc file with the URL, username and password

[nexus]
repository: https://artifact.example.com/repository/ASAP-Python-2.7-Hosted/
username: admin
password: admin

Then when you call twine, do so like this:

twine upload --repository nexus boto3-1.9.76-py2.py3-none-any.whl

It's not a hard requirement, but if you're on multi user system and you've put a password in the file you should probably do

chmod 600 $HOME/.pypirc 
like image 45
Michael Robinson Avatar answered Oct 22 '22 08:10

Michael Robinson