如何更新自定义软件包版本?

huangapple go评论62阅读模式
英文:

How to update custom package version?

问题

我正在尝试创建一个可以在其他项目中重复使用的Python包。我按照这个教程进行操作:创建您自己的自定义私有Python包,可以从Git存储库中进行PIP安装

它能正常工作,但当我更新我的包的代码,然后尝试更新使用该包的项目时,它不会更新。

因此,我有一个包含我的包的Git存储库,位于https://github.com/vincent2303/myCustomPackage,包含以下文件:

  • myCustomPackage/functions.py,其中包含以下函数:
def say_foo():
    print('Foo')
  • setup.py文件,内容如下:
import setuptools

setuptools.setup(
    name='myCustomPackage',
    version='0.0.1',
    author='Vincent2303',
    description='Testing installation of Package',
    long_description_content_type="text/markdown",
    license='MIT',
    packages=['myCustomPackage'],
    install_requires=[],
)

然后,我创建了一个测试项目,包括以下内容:

  • main.py文件:
from myCustomPackage import functions

functions.say_foo()
  • 一个Pipfile文件(我运行了pipenv shell,然后运行了pipenv install git+https://github.com/vincent2303/myCustomPackage.git#egg=myCustomPackage):
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
mycustompackage = {git = "https://github.com/vincent2303/myCustomPackage.git"}

[requires]
python_version = "3.8"

到目前为止,它能正常工作,我可以使用say_foo

然后,我在myCustomPackage中添加了一个新函数say_bar(在myCustomPackage/functions.py中)。我在setup.py中将版本从0.0.1增加到0.0.2,然后进行了提交和推送。

在使用myCustomPackage的项目中,我运行了pipenv install,我期望pip检查版本,检测到有新版本并进行更新,但它没有更新。我无法使用say_bar(我收到错误消息:AttributeError: module 'myCustomPackage.functions' has no attribute 'say_bar')。

我还尝试重新运行了pipenv install git+https://github.com/vincent2303/myCustomPackage.git#egg=myCustomPackage,但它没有更新。

我如何在使用该包的项目中更新myCustomPackage的版本?

英文:

I am trying to create a python package that I can reuse in other projects. I did follow this tutorial: Create Your Custom, private Python Package That You Can PIP Install From Your Git Repository.

It works but when I update the code of my package and then try to update the package on a project that uses this package, it does not update.

So I have a git repo with my package at https://github.com/vincent2303/myCustomPackage with following files:

  • myCustomPackage/functions.py with the following function:
def say_foo():
    print('Foo')
  • A setup.py file with:
import setuptools

setuptools.setup(
    name='myCustomPackage',
    version='0.0.1',
    author='Vincent2303',
    description='Testing installation of Package',
    long_description_content_type="text/markdown",
    license='MIT',
    packages=['myCustomPackage'],
    install_requires=[],
)

Then I created a test project, with:

  • A main.py file:
from myCustomPackage import functions

functions.say_foo()
  • A Pipfile (I did pipenv shell then pipenv install git+https://github.com/vincent2303/myCustomPackage.git#egg=myCustomPackage):
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
mycustompackage = {git = "https://github.com/vincent2303/myCustomPackage.git"}

[requires]
python_version = "3.8"

At this point it works well, I can use say_foo.

Then I added a new function say_bar on myCustomPackage (in myCustomPackage/functions.py). I did increment version from 0.0.1 to 0.0.2 in setup.py. I did commit and push.

In my project that uses myCustomPackage I did run pipenv install, I expect pip to check version, detect that there is a new version and update it but it does not. I can't use say_bar (I get error: AttributeError: module 'myCustomPackage.functions' has no attribute 'say_bar')

I tried as well to re run pipenv install git+https://github.com/vincent2303/myCustomPackage.git#egg=myCustomPackage. It does not update.

How can I update the version of myCustomPackage in projects that uses this package ?

答案1

得分: 1

如果pipenv的工作方式与一般的pip相似,问题可能出在你说:“是的,请从那个仓库获取mycustompackage,我不关心版本”,对于这种情况,pip的解决方法是#egg= URL 片段

pip install https://github.com/vincent2303/myCustomPackage.git#egg=myCustomPackage==0.0.2

也就是告诉pip,你将从这个 git URL 获取一个要求myCustomPackage==0.0.2,这就是你的要求。

你还可以使用一个不同的ref(参考),而不是隐含的“默认分支的HEAD”;如果你在 Git 上标记了新版本(正如你应该为发布版本所做的那样,以便能够轻松查看贡献给它的代码),可以使用该标签,例如,如果标签是v0.0.2

https://github.com/vincent2303/myCustomPackage.git@v0.0.2#egg=myCustomPackage==0.0.2

但你也可以使用提交 ID(这恰好是你的0.0.3提交的ID):

https://github.com/vincent2303/myCustomPackage.git@ff65083ff#egg=myCustomPackage==0.0.3

最后,将这个内容翻译到你的pipenv文件中,尝试:

mycustompackage = {git = "https://github.com/vincent2303/myCustomPackage.git@ff65083ff#egg=myCustomPackage==0.0.3";}
英文:

If pipenv works like pip in general, the issue here is you're saying "yeah, get mycustompackage from that repo, I don't care which version", for which the pip remedy is the #egg= URL fragment:

pip install https://github.com/vincent2303/myCustomPackage.git#egg=myCustomPackage==0.0.2

, i.e. tell pip that you're about to get a requirement myCustomPackage==0.0.2 from this git URL, and that's your requirement.

You could/should also use a distinct ref instead of the implicit "HEAD of the default branch"; if you have tagged your new version on Git (as you should do for released versions so it's easy to see what code has contributed to it), use that tag, e.g. if the tag is v0.0.2,

https://github.com/vincent2303/myCustomPackage.git@v0.0.2#egg=myCustomPackage==0.0.2

but you could just as well use a commit ID (this just so happens to be the ID for your 0.0.3 commit):

https://github.com/vincent2303/myCustomPackage.git@ff65083ff#egg=myCustomPackage==0.0.3

Finally, translating this to your pipenv file, try

mycustompackage = {git = "https://github.com/vincent2303/myCustomPackage.git@ff65083ff#egg=myCustomPackage==0.0.3"}

huangapple
  • 本文由 发表于 2023年3月7日 23:50:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75664217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定