miyagawa / cpanminus

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

Module is not reinstalled despite `--reinstall` flag was provided #647

Closed KES777 closed 2 years ago

KES777 commented 2 years ago

start here I manually download 02packages.details.txt.gz into vendor/modules and rerun:

cpanm --force --reinstall --self-contained --sudo --notest --installdeps -v --from "$PWD/vendor/" .
...
==> Found dependencies: Unix::Getrusage, XML::Feed, Number::Phone
Searching Unix::Getrusage on mirror file:///usr/local/chimera/vendor ...
Downloading index file file:///usr/local/chimera/vendor/modules/02packages.details.txt.gz ...
Uncompressing index file...
--> Working on Unix::Getrusage
Fetching file:///usr/local/chimera/vendor/authors/id/T/TA/TAFFY/Unix-Getrusage-0.03.tar.gz ... OK
...
Successfully installed XML-Feed-0.63
Installing /opt/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/x86_64-linux/.meta/XML-Feed-0.63/install.json
Installing /opt/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/x86_64-linux/.meta/XML-Feed-0.63/MYMETA.json
Searching Number::Phone on mirror file:///usr/local/chimera/vendor ...
Found Number::Phone 3.8005 which doesn't satisfy == 3.7003.
! Installing the dependencies failed: Installed version (3.8005) of Number::Phone is not in range '== 3.7003'
! Bailing out the installation for ..
4 distributions installed

Module Number::Phone 3.8005 should be reinstalled because --reinstall flag was provided.

KES777 commented 2 years ago

Can not understand where it founds that module:

perl -MNumber::Phone -e0                   
Can't locate Number/Phone.pm in @INC (you may need to install the Number::Phone module) (@INC contains: /opt/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1/x86_64-linux /opt/perlbrew/perls/perl-5.34.1/lib/site_perl/5.34.1 /opt/perlbrew/perls/perl-5.34.1/lib/5.34.1/x86_64-linux /opt/perlbrew/perls/perl-5.34.1/lib/5.34.1).
BEGIN failed--compilation aborted.

Would be nice if -v also prints location where module was found:

Found Number::Phone 3.8005 which doesn't satisfy == 3.7003.
 print $INC{'Number::Phone'}
miyagawa commented 2 years ago

Module Number::Phone 3.8005 should be reinstalled because --reinstall flag was provided.

that's not what --reinstall is supposed to do.

You're probably pinning the Number::Phone module in cpanfile, but then pulled 02packages.details.txt.gz from CPAN, which does not have that version, because public CPAN only supports listings of current modules.

You really have to use Carmel for all this. Carmel allows you to manage these versions snapshotted and commit to your repo, and then use cpanm or cpm to deploy on a remote host.

https://metacpan.org/pod/Carmel#Production-Deployments

On your local environment, run:

carmel install
carmel package

this will create a bunch of new files, such as cpanfile.snapshot, and all tarballs and 02packages under vendor. Commit them to your repo, or zip them as you want.

On another machine, run:

cpanm -l local --installdeps . --from file://$PWD/vendor/cache

this will install all the modules, exactly the versions specified in cpanfile.snapshot, using the package files found in vendor/cache, to a library path ./local/lib/perl5.

KES777 commented 2 years ago

Probably that is wrong, because host requires to install modules into system perl. But this system already had newer 'Number::Phone' and installation fails (( Is there a way to workaround that?

miyagawa commented 2 years ago

Probably that is wrong, because host requires to install modules into system perl.

Technically speaking, you should be able to install modules to any location. There's no technical restriction from perl standpoint that you must install to system perl. You can continue to use system perl, then install modules to a separate directory, then point the library path (via use lib or PERL5LIB). This is a standard feature of perl, and it doesn't make sense you're saying "I can't use this standard perl feature."

Having said that, you might have a policy that you have to install modules to site_perl of your system perl. That is a weird policy with virtually no technical merits, but anyone has the freedom to implement such policy.

Either way,

cpanm -l local --installdeps . --from file://$PWD/vendor/cache

this was just an example. You can change the option (remove -l local) to install to site_perl, or use -L local (upper case L, to include --self-contained) to ignore the versions that are already in system perl's site_perl. Perhaps that's what you meant.