Conan: [Feature request] Can we WARN when a user changes `user_home_short` to same as `path`?

Created on 16 Sep 2019  路  6Comments  路  Source: conan-io/conan

A colleague was working fine with Conan for weeks, then started getting the following error even for simple operations such as conan search:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>conan search
ERROR: Value provided for package version, '1' (type Version), is too short. Valid names must contain at least 2 characters.

I see similar https://github.com/conan-io/conan/issues/5606 -- is this the same issue?

Windows Server 2012 R2, conan 1.16.1

To help us debug your issue please explain:

  • [x] I've read the CONTRIBUTING guide.
  • [x] I've specified the Conan version, operating system version and any tool that can be relevant.
  • [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.
Hacktoberfest low ux good first issue low queue

Most helpful comment

Welcome @cctechwiz !!

I am having a look to see where would be the easiest location to implement this. There are very simple hacks, but I am going to propose what I think is the right solution aligned with the future design of Conan (where we want to get rid of environment variables for internal configuration)

  1. Implement a property in the ConanClientConfigParser, called short_paths_home
    This will be very similar to the default_package_id_mode property.

  2. Add a check to that property, based on the self.filename, using os.path.dirname() to get the folder location that contains the conan.conf file that is being parsed. That is the location of the conan cache. Raise an error (ConanException) if the short_paths_home is a subfolder of it

  3. Call self.config.short_paths_home in the __init__ of ClientCache, to ensure that the cache cannot be instantiated which such a broken configuration (I don't think this would be a warning, it is a very broken configuration)

You can test manually if you want, lets leave tests for later, lets see how it goes. Don't hesitate to ask if you have any question! Thanks!!

All 6 comments

Hi! I'm not sure what can be happening there, Conan has had always a limitation for all the components in a reference to be at least two characters in length.

The issue you are linking is related to recipes without user/channel. Older Conan client will raise an error because of the single _ that is used to represent the None value in the filesystem.

Your colleague has a wrong reference in the cache, a reference has 1 as version and it is not supported by Conan, I don't know how it could have arrived at the Conan cache... I would love to know it if it is a Conan issue.

Meanwhile, to discover the offending package you can look for it by hand (list the versions of every package in the Conan cache: by default, they are inside ~/.conan/data/<every-package>/) or you can run a python script:

import os

basedir = os.path.expanduser("~/.conan/data")  # Use the path to Conan cache
ret = []
for root, dirs, _ in os.walk(basedir):
    rel_path = os.path.relpath(root, basedir)
    if rel_path == ".":
        continue
    dir_split = rel_path.split(os.sep)
    if len(dir_split) == 2:
        if len(dir_split[1]) == 1:
            print("Offender: {}".format(dir_split))
        dirs[:] = []  # Stop iterate subdirs

Maybe, with the name of the package, you can know how it has arrived in the Conan cache. Thanks!

I think I figured out the colleague's issue. He had his user_home_short set to same directory as his path:

[general]
user_home_short = f:\DevelopBp\<user>\.conan
[...]
[storage]
path = f:\DevelopBp\<user>\.conan

Is there something we could do to alert with clear logging when a user makes this mistake?

Ouch! It looks like something easy to add and can keep some headache away. 馃憤

I would like to take a crack at this one if you don't mind.

At first glance it seems like either conans/utils/windows.py or conans/utils/config_parser.py (or somewhere that makes use of ConfigParser) would be the appropriate location to implement this check / warning. Does that seem correct?

This is my first attempt at contributing to an open source project, as such any and all feedback is welcome!


On second thought, the storage_path function on line 404 of conans\client\conf\__init__.py looks promising.

Welcome @cctechwiz !!

I am having a look to see where would be the easiest location to implement this. There are very simple hacks, but I am going to propose what I think is the right solution aligned with the future design of Conan (where we want to get rid of environment variables for internal configuration)

  1. Implement a property in the ConanClientConfigParser, called short_paths_home
    This will be very similar to the default_package_id_mode property.

  2. Add a check to that property, based on the self.filename, using os.path.dirname() to get the folder location that contains the conan.conf file that is being parsed. That is the location of the conan cache. Raise an error (ConanException) if the short_paths_home is a subfolder of it

  3. Call self.config.short_paths_home in the __init__ of ClientCache, to ensure that the cache cannot be instantiated which such a broken configuration (I don't think this would be a warning, it is a very broken configuration)

You can test manually if you want, lets leave tests for later, lets see how it goes. Don't hesitate to ask if you have any question! Thanks!!

Was this page helpful?
0 / 5 - 0 ratings