[PATCH 2 of 2 Cubicweb] [pkginfo] Retrive cube's version using pkg_resources

Philippe Pepiot philippe.pepiot at logilab.fr
Tue Jan 14 12:44:22 CET 2020


On 03/01/2020, Nsukami Patrick wrote:
> # HG changeset patch
> # User Nsukami Patrick <ptrck at nskm dot xyz>
> # Date 1578070985 0
> #      Fri Jan 03 17:03:05 2020 +0000
> # Node ID 5722e648c81fb651b5821511a722444872e98e75
> # Parent  a72c89e9ab363dba57434692ebcece975cffcc53
> [pkginfo] Retrive cube's version using pkg_resources
> 
> - update cwconfig.py to retrieve cube version using pkg_resources
> - update cwctl.py to use the updated cube_version function
> - add all the egg-info folders needed by pkg_resources to retrieve cube version during migration tests
> 
> diff --git a/cubicweb/cwconfig.py b/cubicweb/cwconfig.py
> --- a/cubicweb/cwconfig.py
> +++ b/cubicweb/cwconfig.py
> @@ -494,7 +494,23 @@
>          """return the version of the cube located in the given directory
>          """
>          from logilab.common.changelog import Version
> -        version = cls.cube_pkginfo(cube).numversion
> +
> +        try:
> +            distribution = pkg_resources.get_distribution(cube)
> +        except pkg_resources.DistributionNotFound:
> +            try:
> +                distribution = pkg_resources.get_distribution(_cube_pkgname(cube))
> +            except pkg_resources.DistributionNotFound:
> +                # how to pass current apphome to find_distributions?
> +                distribution_list = pkg_resources.find_distributions(sys.path[0])
> +                for dist in distribution_list:
> +                    if cube in dist.project_name:
> +                        distribution = dist
> +                        break
> +
> +        str_version = distribution.version
> +        version = tuple([int(x) for x in str_version.split('.')])
> +

There's a possible NameError on "distribution" if you ender in
DistributionNotFound exception handling.

Also I think we should always get_distribution() of _cube_pkgname(cube).

And I think we should get the cube package name from "cubicweb.cubes"
entrypoint. See available_cubes() from cwconfig.py.

> diff --git a/cubicweb/server/test/data-migractions/cubicweb_basket.egg-info/PKG-INFO b/cubicweb/server/test/data-migractions/cubicweb_basket.egg-info/PKG-INFO
> new file mode 100644
> --- /dev/null
> +++ b/cubicweb/server/test/data-migractions/cubicweb_basket.egg-info/PKG-INFO
> @@ -0,0 +1,14 @@
> +Metadata-Version: 1.1
> +Name: cubicweb-basket
> +Version: 1.2.3
> +Summary: Basket component
> +Home-page: http://www.cubicweb.org/project/basket
> +Author: Logilab
> +Author-email: contact at logilab.fr
> +License: LGPL3
> +Description: Long description
> +Platform: UNKNOWN
> +Classifier: Environment :: Web Environment
> +Classifier: Framework :: CubicWeb
> +Classifier: Programming Language :: Python
> +Classifier: Programming Language :: JavaScript

I think only some files with minimal content can do the trick

$ cd $(mktemp -d)
$ mkdir foo.egg-info
$ echo "Version: 1.2.3" > foo.egg-info/PKG-INFO
$ python3 -c "import pkg_resources; print(pkg_resources.get_distribution('foo'))"
foo 1.2.3

To make the cubicweb cubes entrypoint working:

echo "[cubicweb.cubes]\nsomecube = foo\n" > foo.egg-info/entry_points.txt

Also, "tox -e check-manifest" isn't happy with egg-info directories, you
will have to find a way to bypass this.



More information about the cubicweb-devel mailing list