Steps to use the azure artifact for customised pip packages with versioning

1) Need to create personal access token (PAT) to upload and download the package to azure artifact. 

–> Go to the Personal Access Tokens screen in <user_icon> => User (icon in top right)  

–> REF:  https://dev.azure.com/<Org_Name>/_usersSettings/tokens 

2) Generate a new token, with at least Packages/Read permissions selected 

3) we already created an artifact named “<Artifact_Name>” 

–> REF:  https://dev.azure.com/<Org_Name>/<Project_Name>/_artifacts/feed/<Artifact_Name> 

### Lets try to upload cs-utils latest version ### 

4) Create a file called pypirc in the home folder, 
=> open a file vi ~/.pypirc  

=> Replace the below content to the file, and replace username and password with your details. 

[distutils] 

Index-servers = <Org_Name> 

[<Org_Name>] 

Repository = https://pkgs.dev.azure.com/<Org_Name>/<Project_Name>/_packaging/<Artifact_Name>/pypi/upload/&nbsp;

username:<your_mail_id> 

password:<PAT> 

### Now install the required packages for uploading the pip package ### 

Pre-Requisites: 

Python – 3.0 or above 

Pip – 19.0 or above 

For other package versions please refer the below URL, 
REF: https://pypi.org/project/artifacts-keyring/ 

 
-> python -m pip install –upgrade pip 

-> pip install keyring artifacts-keyring twine 
  

5) Now clone the “<Repo’s_Packages>” repo and inside the folder run the following commands to create dist files and push it to the artifact, 
Note: 
For dependency package (requirement.txt) installation along with the main package need to update the setup.py file. kindly refer the attachment of setup.py file in the mail. Need to update the setup.py before running below commands. 

Before upload the package need to update the version in __init.py__ and remove the dist folder if already exists. 
python3 setup.py sdist bdist_wheel  
(you need to have wheel package to run this command. you can install it directly by pip command) 

python3 -m twine upload -r <Org_Name> dist/* –verbose 

6) Now go to artifact page and click on “connect to feed” to download the package or you can also refer this URL “https://dev.azure.com/<Org_Name>/<Project_Name>/_artifacts/feed/<Artifact_Name>/connect/pip” 

7) Create a pip.conf (mac/linux) or pip.ini (windows) file. Pip.conf can be created either in /etc or home folder.  
$HOME/.config/pip/pip.conf 
/etc/pip.conf 

8) Paste the snippet below into that file, and save it. Kindly don’t forgot to change the username and password. 

[global] 

index-url=https://<mail_id>:<PAT>@pkgs.dev.azure.com/<Org_Name>/<Project_Name>/_packaging/<Artifact_Name>/pypi/simple/ 

 
9) Now just run pip install {myPackage}, and it should work without a prompt. 
 

Leave a comment