nexus twine模块打包python项目上传pypi pip打包

思考:

每个服务的公共代码抽取出来做成pip包,上传到仓库并供下载使用(下载时不要输入账号密码),docker部署环境也需要能够安装此pip包

另外pip包需要做单独的版本管理,上传至git仓库。

 

twine模块打包python项目上传pypi

 https://blog.csdn.net/mouday/article/details/80736312

为世界贡献你的轮子-pipy打包

https://blog.csdn.net/mouday/article/details/79611454

packaging.python

https://packaging.python.org/guides/using-testpypi/

手动建pypi-server(亲测)

https://liqiang.io/post/build-your-own-pip-source

手动建pypi-server的问题:

1 htpasswd命令报错

[root@shen ~]# htpasswd 
-bash: htpasswd: command not found

解决:

[root@shen pip]# yum -y install httpd
[root@shen pip]# htpasswd -c htpasswd.txt admin

https://www.cnblogs.com/zhaobin-diray/p/10936188.html

PS:

设置pypi-server和启动

开启防火墙8080端口:

[root@shen pip]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@shen pip]# firewall-cmd --reload

pypirc文件配置:

$HOME/.pypirc文件:
[distutils]
index-servers=
    pypiserver


[pypiserver]
repository: http://10.1.252.30:8080
username: admin
password: admin

上传:

(drf-venv-3.7) D:\shen\python\PythonWebDev\pip包\extradrf>twine upload dist\extradrf-0.0.1.tar.gz -r pypiserver
Uploading distributions to http://10.1.252.30:8080
Uploading extradrf-0.0.1.tar.gz
100%|█████████████████████████████████████████████████████████| 27.3k/27.3k [00:00<00:00, 905kB/s] 

安装

pip install -i http://10.1.252.30:8080/simple/ --trusted-host 10.1.252.30 extradrf

打包:

>python setup.py sdist

注意extra文件夹下一定要有__init__.py

使用nexus

上传

nexus web上传

nexus开启匿名下载

twine上传

(data_dict_venv3.7) D:\shen\python\PythonWebDev\pip包\extradrf>twine upload --repository-url http://10.1.252.30:8081/repository/pypi/ dist/*
Uploading distributions to http://10.1.252.30:8081/repository/pypi/
Enter your username: admin
Enter your password: admin123
Uploading extradrf-0.0.3.tar.gz
100%|█████████████████████████████████████████████| 27.4k/27.4k [00:00<00:00, 171kB/s]

下载安装

pip安装

方式一:

pip install -i http://10.1.252.30:8081/repository/pypi/simple extra  

方式二: 

复制链接

http://10.1.252.30:8081/repository/pypi/packages/extra/0.0.1/extra-0.0.1.tar.gz

pip install http://10.1.252.30:8081/repository/pypi/packages/extra/0.0.1/extra-0.0.1.tar.gz

web安装

http://10.1.252.30:8081/service/rest/repository/browse/pypi/extradrf/0.0.3/

(data_dict_venv3.7) D:\shen\python\PythonWebDev\web_develop\DRF\tianshu\data_dict>
pip install C:\Users\shen\Downloads\extradrf-0.0.3.tar.gz

使用

from extradrf.response import DefaultResponse as TestDefaultResponse

...

@action(methods=['POST'], detail=False)
    def device_conn(self, request):
        """  """
        ....
        return TestDefaultResponse({"name": res}, status=status.HTTP_200_OK)
发布了105 篇原创文章 · 获赞 33 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/github_38596081/article/details/104063985