Conan: Get only package name and version via conan info

Created on 26 Jan 2017  路  8Comments  路  Source: conan-io/conan

Hi,

To upload only the package that is currently build on our CI Server, I would need to get the name and version from the conanfile. As the version number is created from a fixed version and a build number (from environment variables), i can't grep them out of the file.

The conanfile looks something like this:

from conans import ConanFile, CMake, os
build_name = "-build" + os.getenv("BUILD_ID", "-local")

class MyConan(ConanFile):
    name = "MyPackage"
    version_number = "0.1.1-alpha"
    settings = "os", "compiler", "build_type", "arch"
    short_paths=True
    version = version_number + build_name
...

I would like something like conan info --name resulting in MyPackage/0.1.1-alpha-build12345

Is there already a way to do this?

Best,
Claas

Most helpful comment

I am in groovy, so still a one liner:

text.find('(\\S+)@PROJECT') { match, name -> return name; };

The --only features is not really well documented. for now, @worksforme @closed. :-)

All 8 comments

Are you asking for a conanfile.py in your user space?

Probably conan info is not a good candidate, because it outputs the dependency graph of the current conanfile, not just the conanfile. Or you mean the "PROJECT" string of the conan info command to properly show the package and version?

conan info --only none

will output just the names (including the dependencies, and the creation dates. Probably the creation dates could be hidden too, that seems a bug). Changing the PROJECT => Pkg/version would be good?

No, i meant the former.
I have the conanfile in my userspace, and I need to know the correct name and version.

conan info --none

outputs the following:

Version range '~0.2' required by 'None' resolved to 'CMakeMacros/0.2-build99@demo/unstable'
Version range '~1.9' required by 'None' resolved to 'My.Commons/1.9.0-alpha-build6@demo/unstable'
Version range '~1.8' required by 'None' resolved to 'My.Logging/1.8.0-alpha-build9@demo/unstable'
Version range '~0.2' required by 'My.Commons/1.9.0-alpha-build6@demo/unstable' resolved to 'CMakeMacros/0.2-build99@demo/unstable'
My.Logging/1.8.0-alpha-build9@demo/unstable requirement My.Commons/[~1.9]@demo/unstable overriden by your conanfile to My.Commons/1.9.0-alpha-build6@demo/unstable 
Version range '~0.2' required by 'My.Logging/1.8.0-alpha-build9@demo/unstable' resolved to 'CMakeMacros/0.2-build99@demo/unstable'
Version range '~1.9' required by 'My.Logging/1.8.0-alpha-build9@demo/unstable' valid for downstream requirement 'My.Commons/1.9.0-alpha-build6@demo/unstable'
Version range '~0.2' required by 'My.Commons/1.9.0-alpha-build6@demo/unstable' valid for downstream requirement 'CMakeMacros/0.2-build99@demo/unstable'
My.Application/1.8.0-alpha-build-local@PROJECT
My.Commons/1.9.0-alpha-build6@demo/unstable
    Creation date: 2017-01-20 09:10:54
My.Logging/1.8.0-alpha-build9@demo/unstable
    Creation date: 2017-01-20 09:42:19
CMakeMacros/0.2-build99@demo/unstable
    Creation date: 2017-01-19 15:53:24
CMakeMacros/0.2-build99@demo/unstable
    Creation date: 2017-01-19 15:53:24
CMakeMacros/0.2-build99@demo/unstable
    Creation date: 2017-01-19 15:53:24
CMakeMacros/0.2-build99@demo/unstable
    Creation date: 2017-01-19 15:53:24

If the first 8 lines would not be there, I could capture the first line and remove the @PROJECT, no problem there. But the first lines should not be there ...

EDIT:
I want to get the My.Application/1.8.0-alpha-build-local

Are you using python for the task? That would be one-liner:

re.search('(\S+)@PROJECT', text).group(1)

I am in groovy, so still a one liner:

text.find('(\\S+)@PROJECT') { match, name -> return name; };

The --only features is not really well documented. for now, @worksforme @closed. :-)

Submitted issue to docs: https://github.com/conan-io/docs/issues/143

Also, just submitted some improvement here: https://github.com/conan-io/conan/pull/908

With conan 1.6.1 I needed to adapt the command line a bit:

conan info conanfile.py --only None | grep @PROJECT$ | cut -d'@' -f1

In 1.8.3 in Jenkins Groovy:

 ret = sh(script: 'conan info conanfile.py --only None', returnStdout: true)
 env.PACKAGE_NAME = ret.find('(.*\n){1}@PROJECT') { match, name -> return match[1]; };

For reference, now there exist the conan inspect . command that allows easier retrieval of package name, version and other attributes.

Was this page helpful?
0 / 5 - 0 ratings