miyagawa / cpanminus

cpanminus - get, unpack, build and install modules from CPAN
http://cpanmin.us
746 stars 213 forks source link

Installing the dependencies failed: Missing version info for module 'Digest' #641

Open wollmers opened 2 years ago

wollmers commented 2 years ago

Environment

OS: macOS Catalina Version 10.15.6 (19G73)

$ perlbrew version
/Users/helmut/perl5/perlbrew/bin/perlbrew  - App::perlbrew/0.95

$ cpanm --version
cpanm (App::cpanminus) version 1.7046 (/Users/helmut/perl5/perlbrew/bin/cpanm)
perl version 5.034001 (/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/bin/perl)

  %Config:
    archname=darwin-2level
    installsitelib=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1
    installsitebin=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/bin
    installman1dir=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/man/man1
    installman3dir=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/man/man3
    sitearchexp=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/darwin-2level
    sitelibexp=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1
    archlibexp=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1/darwin-2level
    privlibexp=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1
  %ENV:
    PERL5LIB=/usr/local/bin:/usr/local/lib
    PERLBREW_HOME=/Users/helmut/.perlbrew
    PERLBREW_MANPATH=/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/man
    PERLBREW_PATH=/Users/helmut/perl5/perlbrew/bin:/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/bin
    PERLBREW_PERL=perl-5.34.1
    PERLBREW_ROOT=/Users/helmut/perl5/perlbrew
    PERLBREW_SHELLRC_VERSION=0.94
    PERLBREW_VERSION=0.95
  @INC:
    FatPacked::140476871229568=HASH(0x7fc352024080)
    /usr/local/bin
    /usr/local/lib
    /Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/darwin-2level
    /Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1
    /Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1/darwin-2level
    /Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1

Symptom

$ cpanm Digest; cpanm Digest; cpanm --reinstall Path::Tiny
--> Working on Digest
Fetching http://www.cpan.org/authors/id/T/TO/TODDR/Digest-1.20.tar.gz ... OK
Configuring Digest-1.20 ... OK
Building and testing Digest-1.20 ... OK
Successfully installed Digest-1.20
1 distribution installed
--> Working on Digest
Fetching http://www.cpan.org/authors/id/T/TO/TODDR/Digest-1.20.tar.gz ... OK
Configuring Digest-1.20 ... OK
Building and testing Digest-1.20 ... OK
Successfully installed Digest-1.20
1 distribution installed
--> Working on Path::Tiny
Fetching http://www.cpan.org/authors/id/D/DA/DAGOLDEN/Path-Tiny-0.122.tar.gz ... OK
Configuring Path-Tiny-0.122 ... OK
==> Found dependencies: Digest
--> Working on Digest
Fetching http://www.cpan.org/authors/id/T/TO/TODDR/Digest-1.20.tar.gz ... OK
Configuring Digest-1.20 ... OK
Building and testing Digest-1.20 ... OK
Successfully installed Digest-1.20
! Installing the dependencies failed: Missing version info for module 'Digest'
! Bailing out the installation for Path-Tiny-0.122.
1 distribution installed

Additional diagnostics

$ perl -e  'use Digest;print $Digest::VERSION,"\n";'
1.20

$ perldoc -l Digest
/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/Digest.pm

$ perl -e 'use Module::Metadata; my $info=Module::Metadata->new_from_file("/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/Digest.pm");print $info->version,"\n";'
1.20

$ perl -e 'use Module::Metadata;my $meta= Module::Metadata->new_from_module("Digest",inc => ["/Users/helmut/perl5/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/"]);print $meta->version,"\n";'
1.20
miyagawa commented 2 years ago

PERL5LIB=/usr/local/bin:/usr/local/lib

Try running it without this environment variable set.

miyagawa commented 2 years ago

I can't repro on perl 5.34.1 with a similar setup.

You might want to add some debugging info to your cpanm executable around CPAN::Meta::Check, to get a better diagnosis where the error comes from. This seems to be some issue with the bundled CPAN::Meta::Check version (Changelog sayd it's fixed in the latest release) but I'm curious how it doesn't happen with my setup.

wollmers commented 2 years ago

The cpanm executable of perlbrew

$ which cpanm
/Users/helmut/perl5/perlbrew/bin/cpanm

seems to have CPAN::Meta::Check version 0.012

$fatpacked{"CPAN/Meta/Check.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'CPAN_META_CHECK';
  package CPAN::Meta::Check;$CPAN::Meta::Check::VERSION='0.012';use [...]
CPAN_META_CHECK

and not the latest 0.014 with

0.014     2016-11-25 13:09:01+01:00 Europe/Amsterdam
          - Undef versions are now passed through to CPAN::Meta::Requirements
            for the check, rather than failing with "Missing version" errors.

Sorry for just repeating in my own words what you already have written.

The diff of CPAN::Meta::Check tells us it should work?

~/github/perl/CPAN-Meta-Check-0.012$ diff lib/CPAN/Meta/Check.pm ../CPAN-Meta-Check-0.014/lib/CPAN/Meta/Check.pm
2c2
< $CPAN::Meta::Check::VERSION = '0.012';
---
> $CPAN::Meta::Check::VERSION = '0.014';
21a22
> 
23,24c24,26
<   return "Missing version info for module '$module'" if $reqs->requirements_for_module($module) and not $version;
<   return sprintf 'Installed version (%s) of %s is not in range \'%s\'', $version, $module, $reqs->requirements_for_module($module) if not $reqs->accepts_module($module, $version || 0);
---
>   return sprintf 'Installed version (%s) of %s is not in range \'%s\'',
>           (defined $version ? $version : 'undef'), $module, $reqs->requirements_for_module($module)
>       if not $reqs->accepts_module($module, $version || 0);
31a34
> 
33,34c36,38
<   return "Missing version info for module '$module'" if not $version;
<   return sprintf 'Installed version (%s) of %s is in range \'%s\'', $version, $module, $reqs->requirements_for_module($module) if $reqs->accepts_module($module, $version);
---
>   return sprintf 'Installed version (%s) of %s is in range \'%s\'',
>           (defined $version ? $version : 'undef'), $module, $reqs->requirements_for_module($module)
>       if $reqs->accepts_module($module, $version);
79c83
< version 0.012
---
> version 0.014

OK, will try to boil it down with diagnostic messages before patching.

miyagawa commented 2 years ago

Yeah, if anything, I think upgrading CPAN::Meta::Check will hide the issue from you - seems to be you're getting an undef version for Digest.pm from your install path.

wollmers commented 2 years ago

Is it possible that this one is used (Mac is case insensitive):

/usr/local/bin$ la digest
lrwxr-xr-x  1 helmut  admin    29B 24 Apr  2021 digest -> ../Cellar/nss/3.60/bin/digest

This seems to have a valid VERSION:

~/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1$  perl -e 'use Module::Metadata; my $info=Module::Metadata->new_from_file("Digest.pm");print $info->version,"\n";'
1.19
miyagawa commented 2 years ago

It's possible - that's why I suggested earlier to remove it from your PERL5LIB. At least worth trying.

wollmers commented 2 years ago

It's it, reproducable now:

/usr/local/bin$ mv digest digest_removeMe

/usr/local/bin$ cpanm Digest; cpanm Digest
Digest is up to date. (1.20)
Digest is up to date. (1.20)

helmut@mbp:/usr/local/bin$ mv digest_removeMe digest

helmut@mbp:/usr/local/bin$ cpanm Digest; cpanm Digest
--> Working on Digest
Fetching file:///usr/local/Cellar/nss/3.60/bin/digest ... OK
tar: Error opening archive: Unrecognized archive format
! Failed to unpack digest: no directory
! Failed to fetch distribution 
--> Working on Digest
Fetching file:///usr/local/Cellar/nss/3.60/bin/digest ... OK
tar: Error opening archive: Unrecognized archive format
! Failed to unpack digest: no directory
! Failed to fetch distribution 

Using a fresh shell without [Dd]igest in ./:

~$ cpanm Digest; cpanm Digest
--> Working on Digest
Fetching http://www.cpan.org/authors/id/T/TO/TODDR/Digest-1.20.tar.gz ... OK
Configuring Digest-1.20 ... OK
Building and testing Digest-1.20 ... OK
Successfully installed Digest-1.20
1 distribution installed
--> Working on Digest
Fetching http://www.cpan.org/authors/id/T/TO/TODDR/Digest-1.20.tar.gz ... OK
Configuring Digest-1.20 ... OK
Building and testing Digest-1.20 ... OK
Successfully installed Digest-1.20
1 distribution installed

~$ mv /usr/local/bin/digest /usr/local/bin/digest_removeMe

~$ cpanm Digest; cpanm Digest
Digest is up to date. (1.20)
Digest is up to date. (1.20)

~$ mv /usr/local/bin/digest_removeMe /usr/local/bin/digest

Potentially this can happen with all targets that have homonyms.

miyagawa commented 2 years ago

I don't think you're supposed to have bin directory in your PERL5LIB now, so I'd say that's an invalid configuration. Though it's interesting It tries to load the version from the digest binary file (without .pm suffix) and it might be something to look into.

miyagawa commented 2 years ago
helmut@mbp:/usr/local/bin$ cpanm Digest; cpanm Digest
--> Working on Digest
Fetching file:///usr/local/Cellar/nss/3.60/bin/digest ... OK
tar: Error opening archive: Unrecognized archive format
! Failed to unpack digest: no directory
! Failed to fetch distribution 
--> Working on Digest
Fetching file:///usr/local/Cellar/nss/3.60/bin/digest ... OK
tar: Error opening archive: Unrecognized archive format
! Failed to unpack digest: no directory
! Failed to fetch distribution 

I mean this is red herring and is not the same as what you initially reported. cpanm tries to load the file in the current directory with the same name in the argument list is a known issue.

For your original issue, remove /usr/local/bin from PERL5LIB and i believe it should be fixed.

wollmers commented 2 years ago

I mean this is red herring and is not the same as what you initially reported. cpanm tries to load the file in the current directory with the same name in the argument list is a known issue.

I know and did a test without digest in the current directory. See second half of my posting.

For your original issue, remove /usr/local/bin from PERL5LIB and i believe it should be fixed.

If I remove /usr/local/bin from PERL5LIB than it's obvious that the problem is not triggered:

~$ cpanm --version | grep PERL5LIB
    PERL5LIB=
~$ cpanm Digest; cpanm Digest;
Digest is up to date. (1.20)
Digest is up to date. (1.20)

But that's more like a work-around.

miyagawa commented 2 years ago

Yep, just confirming that you're describing two different issues.

One is that cpanm Module would read a file named Module from the current directory if it exists. Known issue #564 difficult to fix without breaking backward compatibility.

Another is the original issue, which is that Module::Metadata would fail to look up a version from a file in your PERL5LIB path.

But that's more like a work-around.

I don't consider it a workaround. You specify a path /usr/local/bin to PERL5LIB which doesn't actually have any perl5 libraries, to confuse perl's include path. It definitely is worth looking why Module::Metadata tries to read the file digest (and not Digest.pm) and fail to extract the info, like I stated above.

wollmers commented 2 years ago

I don't consider it a workaround. You specify a path /usr/local/bin to PERL5LIB which doesn't actually have any perl5 libraries, to confuse perl's include path.

That's true. I checked what's in /usr/local/bin (old cpanm and perlbrew) and it seems a relict, that it is set in .profile to PERL5LIB.

It definitely is worth looking why Module::Metadata tries to read the file digest (and not Digest.pm) and fail to extract the info, like I stated above.

Read the wrong file should not happen. Maybe similar cases were the reason for the change in version 0.014 of CPAN::Meta::Check, which IMHO does not solve the problem in all cases, and makes it harder to locate the real problem.

miyagawa commented 2 years ago

Maybe similar cases were the reason for the change in version 0.014 of CPAN::Meta::Check

I think the CPAN::Meta::Check change is that if a module depends on a module Foo::Bar (for any version), and if Foo/Bar.pm exists but has no $VERSION set (common for sub modules inside a distribution), that should be handled as a success, rather than a failure. That's an OK change to bring in, but as you said it could masquerade the real issue in some cases.