How to update custom package version?

Question:

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 ?

Asked By: Vince M

||

Answers:

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/[email protected]#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"}
Answered By: AKX