-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathtest_install.py
1904 lines (1600 loc) · 66.5 KB
/
test_install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import distutils
import glob
import os
import re
import shutil
import ssl
import sys
import textwrap
from os.path import curdir, join, pardir
import pytest
from pip._internal.cli.status_codes import ERROR, SUCCESS
from pip._internal.models.index import PyPI, TestPyPI
from pip._internal.utils.misc import rmtree
from tests.lib import (
_create_svn_repo,
_create_test_package,
create_basic_wheel_for_package,
create_test_package_with_setup,
need_bzr,
need_mercurial,
need_svn,
path_to_url,
pyversion,
pyversion_tuple,
requirements_file,
skip_if_not_python2,
skip_if_python2,
windows_workaround_7667,
)
from tests.lib.filesystem import make_socket_file
from tests.lib.local_repos import local_checkout
from tests.lib.path import Path
from tests.lib.server import (
file_response,
make_mock_server,
package_page,
server_running,
)
@pytest.mark.parametrize('command', ('install', 'wheel'))
@pytest.mark.parametrize('variant', ('missing_setuptools', 'bad_setuptools'))
def test_pep518_uses_build_env(script, data, common_wheels, command, variant):
if variant == 'missing_setuptools':
script.pip("uninstall", "-y", "setuptools")
elif variant == 'bad_setuptools':
setuptools_mod = script.site_packages_path.joinpath("setuptools.py")
with open(setuptools_mod, 'a') as f:
f.write('\nraise ImportError("toto")')
else:
raise ValueError(variant)
script.pip(
command, '--no-index', '-f', common_wheels, '-f', data.packages,
data.src.joinpath("pep518-3.0"),
)
def test_pep518_build_env_uses_same_pip(
script, data, pip_src, common_wheels, deprecated_python):
"""Ensure the subprocess call to pip for installing the
build dependencies is using the same version of pip.
"""
with open(script.scratch_path / 'pip.py', 'w') as fp:
fp.write('raise ImportError')
script.run(
'python', pip_src / 'src/pip', 'install', '--no-index',
'-f', common_wheels, '-f', data.packages,
data.src.joinpath("pep518-3.0"),
expect_stderr=deprecated_python,
)
def test_pep518_refuses_conflicting_requires(script, data):
create_basic_wheel_for_package(script, 'setuptools', '1.0')
create_basic_wheel_for_package(script, 'wheel', '1.0')
project_dir = data.src.joinpath("pep518_conflicting_requires")
result = script.pip_install_local('-f', script.scratch_path,
project_dir, expect_error=True)
assert (
result.returncode != 0 and (
'Some build dependencies for {url} conflict '
'with PEP 517/518 supported '
'requirements: setuptools==1.0 is incompatible with '
'setuptools>=40.8.0.'
.format(url=path_to_url(project_dir))) in result.stderr
), str(result)
def test_pep518_refuses_invalid_requires(script, data, common_wheels):
result = script.pip(
'install', '-f', common_wheels,
data.src.joinpath("pep518_invalid_requires"),
expect_error=True
)
assert result.returncode == 1
assert "does not comply with PEP 518" in result.stderr
def test_pep518_refuses_invalid_build_system(script, data, common_wheels):
result = script.pip(
'install', '-f', common_wheels,
data.src.joinpath("pep518_invalid_build_system"),
expect_error=True
)
assert result.returncode == 1
assert "does not comply with PEP 518" in result.stderr
def test_pep518_allows_missing_requires(script, data, common_wheels):
result = script.pip(
'install', '-f', common_wheels,
data.src.joinpath("pep518_missing_requires"),
expect_stderr=True
)
# Make sure we don't warn when this occurs.
assert "does not comply with PEP 518" not in result.stderr
# We want it to go through isolation for now.
assert "Installing build dependencies" in result.stdout, result.stdout
assert result.returncode == 0
assert result.files_created
@pytest.mark.incompatible_with_test_venv
def test_pep518_with_user_pip(script, pip_src, data, common_wheels):
"""
Check that build dependencies are installed into the build
environment without using build isolation for the pip invocation.
To ensure that we're not using build isolation when installing
the build dependencies, we install a user copy of pip in the
non-isolated environment, and break pip in the system site-packages,
so that isolated uses of pip will fail.
"""
script.pip("install", "--ignore-installed",
"-f", common_wheels, "--user", pip_src)
system_pip_dir = script.site_packages_path / 'pip'
assert not system_pip_dir.exists()
system_pip_dir.mkdir()
with open(system_pip_dir / '__init__.py', 'w') as fp:
fp.write('raise ImportError\n')
script.pip(
'wheel', '--no-index', '-f', common_wheels, '-f', data.packages,
data.src.joinpath("pep518-3.0"),
)
def test_pep518_with_extra_and_markers(script, data, common_wheels):
script.pip(
'wheel', '--no-index',
'-f', common_wheels,
'-f', data.find_links,
data.src.joinpath("pep518_with_extra_and_markers-1.0"),
)
def test_pep518_with_namespace_package(script, data, common_wheels):
script.pip(
'wheel', '--no-index',
'-f', common_wheels,
'-f', data.find_links,
data.src.joinpath("pep518_with_namespace_package-1.0"),
use_module=True,
)
@pytest.mark.timeout(60)
@pytest.mark.parametrize('command', ('install', 'wheel'))
@pytest.mark.parametrize('package', ('pep518_forkbomb',
'pep518_twin_forkbombs_first',
'pep518_twin_forkbombs_second'))
def test_pep518_forkbombs(script, data, common_wheels, command, package):
package_source = next(data.packages.glob(package + '-[0-9]*.tar.gz'))
result = script.pip(
command, '--no-index', '-v',
'-f', common_wheels,
'-f', data.find_links,
package,
expect_error=True,
)
assert '{1} is already being built: {0} from {1}'.format(
package, path_to_url(package_source),
) in result.stderr, str(result)
@pytest.mark.network
def test_pip_second_command_line_interface_works(
script, pip_src, data, common_wheels, deprecated_python):
"""
Check if ``pip<PYVERSION>`` commands behaves equally
"""
# Re-install pip so we get the launchers.
script.pip_install_local('-f', common_wheels, pip_src)
# On old versions of Python, urllib3/requests will raise a warning about
# the lack of an SSLContext.
kwargs = {'expect_stderr': deprecated_python}
if pyversion_tuple < (2, 7, 9):
kwargs['expect_stderr'] = True
args = ['pip{pyversion}'.format(**globals())]
args.extend(['install', 'INITools==0.2'])
args.extend(['-f', data.packages])
result = script.run(*args, **kwargs)
egg_info_folder = (
script.site_packages /
'INITools-0.2-py{pyversion}.egg-info'.format(**globals())
)
initools_folder = script.site_packages / 'initools'
result.did_create(egg_info_folder)
result.did_create(initools_folder)
def test_install_exit_status_code_when_no_requirements(script):
"""
Test install exit status code when no requirements specified
"""
result = script.pip('install', expect_error=True)
assert "You must give at least one requirement to install" in result.stderr
assert result.returncode == ERROR
def test_install_exit_status_code_when_blank_requirements_file(script):
"""
Test install exit status code when blank requirements file specified
"""
script.scratch_path.joinpath("blank.txt").write_text("\n")
script.pip('install', '-r', 'blank.txt')
@pytest.mark.network
def test_basic_install_from_pypi(script):
"""
Test installing a package from PyPI.
"""
result = script.pip('install', 'INITools==0.2')
egg_info_folder = (
script.site_packages /
'INITools-0.2-py{pyversion}.egg-info'.format(**globals())
)
initools_folder = script.site_packages / 'initools'
result.did_create(egg_info_folder)
result.did_create(initools_folder)
# Should not display where it's looking for files
assert "Looking in indexes: " not in result.stdout
assert "Looking in links: " not in result.stdout
# Ensure that we don't print the full URL.
# The URL should be trimmed to only the last part of the path in it,
# when installing from PyPI. The assertion here only checks for
# `https://` since that's likely to show up if we're not trimming in
# the correct circumstances.
assert "https://" not in result.stdout
def test_basic_editable_install(script):
"""
Test editable installation.
"""
result = script.pip('install', '-e', 'INITools==0.2', expect_error=True)
assert (
"INITools==0.2 is not a valid editable requirement"
in result.stderr
)
assert not result.files_created
@need_svn
def test_basic_install_editable_from_svn(script):
"""
Test checking out from svn.
"""
checkout_path = _create_test_package(script)
repo_url = _create_svn_repo(script, checkout_path)
result = script.pip(
'install',
'-e', 'svn+' + repo_url + '#egg=version-pkg'
)
result.assert_installed('version-pkg', with_files=['.svn'])
def _test_install_editable_from_git(script, tmpdir):
"""Test cloning from Git."""
pkg_path = _create_test_package(script, name='testpackage', vcs='git')
args = [
'install', '-e',
'git+{url}#egg=testpackage'.format(url=path_to_url(pkg_path)),
]
result = script.pip(*args)
result.assert_installed('testpackage', with_files=['.git'])
def test_basic_install_editable_from_git(script, tmpdir):
_test_install_editable_from_git(script, tmpdir)
def test_install_editable_from_git_autobuild_wheel(
script, tmpdir, with_wheel):
_test_install_editable_from_git(script, tmpdir)
@pytest.mark.network
def test_install_editable_uninstalls_existing(data, script, tmpdir):
"""
Test that installing an editable uninstalls a previously installed
non-editable version.
https://github.com/pypa/pip/issues/1548
https://github.com/pypa/pip/pull/1552
"""
to_install = data.packages.joinpath("pip-test-package-0.1.tar.gz")
result = script.pip_install_local(to_install)
assert 'Successfully installed pip-test-package' in result.stdout
result.assert_installed('piptestpackage', editable=False)
result = script.pip(
'install', '-e',
'{dir}#egg=pip-test-package'.format(
dir=local_checkout(
'git+https://github.com/pypa/pip-test-package.git', tmpdir,
)),
)
result.assert_installed('pip-test-package', with_files=['.git'])
assert 'Found existing installation: pip-test-package 0.1' in result.stdout
assert 'Uninstalling pip-test-package-' in result.stdout
assert 'Successfully uninstalled pip-test-package' in result.stdout
def test_install_editable_uninstalls_existing_from_path(script, data):
"""
Test that installing an editable uninstalls a previously installed
non-editable version from path
"""
to_install = data.src.joinpath('simplewheel-1.0')
result = script.pip_install_local(to_install)
assert 'Successfully installed simplewheel' in result.stdout
simple_folder = script.site_packages / 'simplewheel'
result.assert_installed('simplewheel', editable=False)
result.did_create(simple_folder)
result = script.pip(
'install', '-e',
to_install,
)
install_path = script.site_packages / 'simplewheel.egg-link'
result.did_create(install_path)
assert 'Found existing installation: simplewheel 1.0' in result.stdout
assert 'Uninstalling simplewheel-' in result.stdout
assert 'Successfully uninstalled simplewheel' in result.stdout
assert simple_folder in result.files_deleted, str(result.stdout)
@need_mercurial
def test_basic_install_editable_from_hg(script, tmpdir):
"""Test cloning and hg+file install from Mercurial."""
pkg_path = _create_test_package(script, name='testpackage', vcs='hg')
url = 'hg+{}#egg=testpackage'.format(path_to_url(pkg_path))
assert url.startswith('hg+file')
args = ['install', '-e', url]
result = script.pip(*args)
result.assert_installed('testpackage', with_files=['.hg'])
@need_mercurial
def test_vcs_url_final_slash_normalization(script, tmpdir):
"""
Test that presence or absence of final slash in VCS URL is normalized.
"""
pkg_path = _create_test_package(script, name='testpackage', vcs='hg')
args = [
'install',
'-e', 'hg+{url}/#egg=testpackage'.format(url=path_to_url(pkg_path))]
result = script.pip(*args)
result.assert_installed('testpackage', with_files=['.hg'])
@need_bzr
def test_install_editable_from_bazaar(script, tmpdir):
"""Test checking out from Bazaar."""
pkg_path = _create_test_package(script, name='testpackage', vcs='bazaar')
args = [
'install',
'-e', 'bzr+{url}/#egg=testpackage'.format(url=path_to_url(pkg_path))]
result = script.pip(*args)
result.assert_installed('testpackage', with_files=['.bzr'])
@pytest.mark.network
@need_bzr
def test_vcs_url_urlquote_normalization(script, tmpdir):
"""
Test that urlquoted characters are normalized for repo URL comparison.
"""
script.pip(
'install', '-e',
'{url}/#egg=django-wikiapp'.format(
url=local_checkout(
'bzr+http://bazaar.launchpad.net/'
'%7Edjango-wikiapp/django-wikiapp'
'/release-0.1',
tmpdir,
)),
)
@pytest.mark.parametrize("resolver", ["", "--use-feature=2020-resolver"])
def test_basic_install_from_local_directory(script, data, resolver):
"""
Test installing from a local directory.
"""
args = ["install"]
if resolver:
args.append(resolver)
to_install = data.packages.joinpath("FSPkg")
args.append(to_install)
result = script.pip(*args)
fspkg_folder = script.site_packages / 'fspkg'
egg_info_folder = (
script.site_packages /
'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(fspkg_folder)
result.did_create(egg_info_folder)
@pytest.mark.parametrize("test_type,editable", [
("rel_path", False),
("rel_path", True),
("rel_url", False),
("rel_url", True),
("embedded_rel_path", False),
("embedded_rel_path", True),
])
def test_basic_install_relative_directory(script, data, test_type, editable):
"""
Test installing a requirement using a relative path.
"""
egg_info_file = (
script.site_packages /
'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**globals())
)
egg_link_file = (
script.site_packages / 'FSPkg.egg-link'
)
package_folder = script.site_packages / 'fspkg'
# Compute relative install path to FSPkg from scratch path.
full_rel_path = Path(
os.path.relpath(data.packages.joinpath('FSPkg'), script.scratch_path)
)
full_rel_url = (
'file:' + full_rel_path.replace(os.path.sep, '/') + '#egg=FSPkg'
)
embedded_rel_path = script.scratch_path.joinpath(full_rel_path)
req_path = {
"rel_path": full_rel_path,
"rel_url": full_rel_url,
"embedded_rel_path": embedded_rel_path,
}[test_type]
# Install as either editable or not.
if not editable:
result = script.pip('install', req_path,
cwd=script.scratch_path)
result.did_create(egg_info_file)
result.did_create(package_folder)
else:
# Editable install.
result = script.pip('install', '-e' + req_path,
cwd=script.scratch_path)
result.did_create(egg_link_file)
def test_install_quiet(script, data):
"""
Test that install -q is actually quiet.
"""
# Apparently if pip install -q is not actually quiet, then it breaks
# everything. See:
# https://github.com/pypa/pip/issues/3418
# https://github.com/docker-library/python/issues/83
to_install = data.packages.joinpath("FSPkg")
result = script.pip('install', '-qqq', to_install)
assert result.stdout == ""
assert result.stderr == ""
def test_hashed_install_success(script, data, tmpdir):
"""
Test that installing various sorts of requirements with correct hashes
works.
Test file URLs and index packages (which become HTTP URLs behind the
scenes).
"""
file_url = path_to_url(
(data.packages / 'simple-1.0.tar.gz').resolve())
with requirements_file(
'simple2==1.0 --hash=sha256:9336af72ca661e6336eb87bc7de3e8844d853e'
'3848c2b9bbd2e8bf01db88c2c7\n'
'{simple} --hash=sha256:393043e672415891885c9a2a0929b1af95fb866d6c'
'a016b42d2e6ce53619b653'.format(simple=file_url),
tmpdir) as reqs_file:
script.pip_install_local('-r', reqs_file.resolve())
def test_hashed_install_failure(script, tmpdir):
"""Test that wrong hashes stop installation.
This makes sure prepare_files() is called in the course of installation
and so has the opportunity to halt if hashes are wrong. Checks on various
kinds of hashes are in test_req.py.
"""
with requirements_file('simple2==1.0 --hash=sha256:9336af72ca661e6336eb87b'
'c7de3e8844d853e3848c2b9bbd2e8bf01db88c2c\n',
tmpdir) as reqs_file:
result = script.pip_install_local('-r',
reqs_file.resolve(),
expect_error=True)
assert len(result.files_created) == 0
def assert_re_match(pattern, text):
assert re.search(pattern, text), (
"Could not find {!r} in {!r}".format(pattern, text)
)
@pytest.mark.network
@pytest.mark.fails_on_new_resolver
def test_hashed_install_failure_later_flag(script, tmpdir):
with requirements_file(
"blessings==1.0\n"
"tracefront==0.1 --hash=sha256:somehash\n"
"https://files.pythonhosted.org/packages/source/m/more-itertools/"
"more-itertools-1.0.tar.gz#md5=b21850c3cfa7efbb70fd662ab5413bdd\n"
"https://files.pythonhosted.org/"
"packages/source/p/peep/peep-3.1.1.tar.gz\n",
tmpdir,
) as reqs_file:
result = script.pip(
"install", "-r", reqs_file.resolve(), expect_error=True
)
assert_re_match(
r'Hashes are required in --require-hashes mode, but they are '
r'missing .*\n'
r' https://files\.pythonhosted\.org/packages/source/p/peep/peep'
r'-3\.1\.1\.tar\.gz --hash=sha256:[0-9a-f]+\n'
r' blessings==1.0 --hash=sha256:[0-9a-f]+\n'
r'THESE PACKAGES DO NOT MATCH THE HASHES.*\n'
r' tracefront==0.1 .*:\n'
r' Expected sha256 somehash\n'
r' Got [0-9a-f]+',
result.stderr,
)
def test_install_from_local_directory_with_symlinks_to_directories(
script, data):
"""
Test installing from a local directory containing symlinks to directories.
"""
to_install = data.packages.joinpath("symlinks")
result = script.pip('install', to_install)
pkg_folder = script.site_packages / 'symlinks'
egg_info_folder = (
script.site_packages /
'symlinks-0.1.dev0-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(pkg_folder)
result.did_create(egg_info_folder)
@pytest.mark.skipif("sys.platform == 'win32' or sys.version_info < (3,)")
def test_install_from_local_directory_with_socket_file(script, data, tmpdir):
"""
Test installing from a local directory containing a socket file.
"""
egg_info_file = (
script.site_packages /
"FSPkg-0.1.dev0-py{pyversion}.egg-info".format(**globals())
)
package_folder = script.site_packages / "fspkg"
to_copy = data.packages.joinpath("FSPkg")
to_install = tmpdir.joinpath("src")
shutil.copytree(to_copy, to_install)
# Socket file, should be ignored.
socket_file_path = os.path.join(to_install, "example")
make_socket_file(socket_file_path)
result = script.pip("install", "--verbose", to_install)
result.did_create(package_folder)
result.did_create(egg_info_file)
assert str(socket_file_path) in result.stderr
def test_install_from_local_directory_with_no_setup_py(script, data):
"""
Test installing from a local directory with no 'setup.py'.
"""
result = script.pip('install', data.root, expect_error=True)
assert not result.files_created
assert "is not installable." in result.stderr
assert "Neither 'setup.py' nor 'pyproject.toml' found." in result.stderr
def test_editable_install__local_dir_no_setup_py(
script, data, deprecated_python):
"""
Test installing in editable mode from a local directory with no setup.py.
"""
result = script.pip('install', '-e', data.root, expect_error=True)
assert not result.files_created
msg = result.stderr
if deprecated_python:
assert 'File "setup.py" not found. ' in msg
else:
assert msg.startswith('ERROR: File "setup.py" not found. ')
assert 'pyproject.toml' not in msg
def test_editable_install__local_dir_no_setup_py_with_pyproject(
script, deprecated_python):
"""
Test installing in editable mode from a local directory with no setup.py
but that does have pyproject.toml.
"""
local_dir = script.scratch_path.joinpath('temp')
local_dir.mkdir()
pyproject_path = local_dir.joinpath('pyproject.toml')
pyproject_path.write_text('')
result = script.pip('install', '-e', local_dir, expect_error=True)
assert not result.files_created
msg = result.stderr
if deprecated_python:
assert 'File "setup.py" not found. ' in msg
else:
assert msg.startswith('ERROR: File "setup.py" not found. ')
assert 'A "pyproject.toml" file was found' in msg
@skip_if_not_python2
@pytest.mark.xfail
def test_install_argparse_shadowed(script):
# When argparse is in the stdlib, we support installing it
# even though that's pretty useless because older packages did need to
# depend on it, and not having its metadata will cause pkg_resources
# requirements checks to fail // trigger easy-install, both of which are
# bad.
# XXX: Note, this test hits the outside-environment check, not the
# in-stdlib check, because our tests run in virtualenvs...
result = script.pip('install', 'argparse>=1.4')
assert "Not uninstalling argparse" in result.stdout
@pytest.mark.network
@skip_if_python2
def test_upgrade_argparse_shadowed(script):
# If argparse is installed - even if shadowed for imported - we support
# upgrading it and properly remove the older versions files.
script.pip('install', 'argparse==1.3')
result = script.pip('install', 'argparse>=1.4')
assert "Not uninstalling argparse" not in result.stdout
def test_install_curdir(script, data):
"""
Test installing current directory ('.').
"""
run_from = data.packages.joinpath("FSPkg")
# Python 2.4 Windows balks if this exists already
egg_info = join(run_from, "FSPkg.egg-info")
if os.path.isdir(egg_info):
rmtree(egg_info)
result = script.pip('install', curdir, cwd=run_from)
fspkg_folder = script.site_packages / 'fspkg'
egg_info_folder = (
script.site_packages /
'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(fspkg_folder)
result.did_create(egg_info_folder)
def test_install_pardir(script, data):
"""
Test installing parent directory ('..').
"""
run_from = data.packages.joinpath("FSPkg", "fspkg")
result = script.pip('install', pardir, cwd=run_from)
fspkg_folder = script.site_packages / 'fspkg'
egg_info_folder = (
script.site_packages /
'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(fspkg_folder)
result.did_create(egg_info_folder)
@pytest.mark.network
def test_install_global_option(script):
"""
Test using global distutils options.
(In particular those that disable the actual install action)
"""
result = script.pip(
'install', '--global-option=--version', "INITools==0.1",
expect_stderr=True)
assert 'INITools==0.1\n' in result.stdout
assert not result.files_created
def test_install_with_hacked_egg_info(script, data):
"""
test installing a package which defines its own egg_info class
"""
run_from = data.packages.joinpath("HackedEggInfo")
result = script.pip('install', '.', cwd=run_from)
assert 'Successfully installed hackedegginfo-0.0.0\n' in result.stdout
@pytest.mark.network
def test_install_using_install_option_and_editable(script, tmpdir):
"""
Test installing a tool using -e and --install-option
"""
folder = 'script_folder'
script.scratch_path.joinpath(folder).mkdir()
url = 'git+git://github.com/pypa/pip-test-package'
result = script.pip(
'install', '-e', '{url}#egg=pip-test-package'
.format(url=local_checkout(url, tmpdir)),
'--install-option=--script-dir={folder}'.format(**locals()),
expect_stderr=True)
script_file = (
script.venv / 'src' / 'pip-test-package' /
folder / 'pip-test-package' + script.exe
)
result.did_create(script_file)
@pytest.mark.network
@need_mercurial
@windows_workaround_7667
def test_install_global_option_using_editable(script, tmpdir):
"""
Test using global distutils options, but in an editable installation
"""
url = 'hg+http://bitbucket.org/runeh/anyjson'
result = script.pip(
'install', '--global-option=--version', '-e',
'{url}@0.2.5#egg=anyjson'.format(url=local_checkout(url, tmpdir)),
expect_stderr=True)
assert 'Successfully installed anyjson' in result.stdout
@pytest.mark.network
def test_install_package_with_same_name_in_curdir(script):
"""
Test installing a package with the same name of a local folder
"""
script.scratch_path.joinpath("mock==0.6").mkdir()
result = script.pip('install', 'mock==0.6')
egg_folder = (
script.site_packages /
'mock-0.6.0-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(egg_folder)
mock100_setup_py = textwrap.dedent('''\
from setuptools import setup
setup(name='mock',
version='100.1')''')
def test_install_folder_using_dot_slash(script):
"""
Test installing a folder using pip install ./foldername
"""
script.scratch_path.joinpath("mock").mkdir()
pkg_path = script.scratch_path / 'mock'
pkg_path.joinpath("setup.py").write_text(mock100_setup_py)
result = script.pip('install', './mock')
egg_folder = (
script.site_packages /
'mock-100.1-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(egg_folder)
def test_install_folder_using_slash_in_the_end(script):
r"""
Test installing a folder using pip install foldername/ or foldername\
"""
script.scratch_path.joinpath("mock").mkdir()
pkg_path = script.scratch_path / 'mock'
pkg_path.joinpath("setup.py").write_text(mock100_setup_py)
result = script.pip('install', 'mock' + os.path.sep)
egg_folder = (
script.site_packages /
'mock-100.1-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(egg_folder)
def test_install_folder_using_relative_path(script):
"""
Test installing a folder using pip install folder1/folder2
"""
script.scratch_path.joinpath("initools").mkdir()
script.scratch_path.joinpath("initools", "mock").mkdir()
pkg_path = script.scratch_path / 'initools' / 'mock'
pkg_path.joinpath("setup.py").write_text(mock100_setup_py)
result = script.pip('install', Path('initools') / 'mock')
egg_folder = (
script.site_packages /
'mock-100.1-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(egg_folder)
@pytest.mark.network
def test_install_package_which_contains_dev_in_name(script):
"""
Test installing package from PyPI which contains 'dev' in name
"""
result = script.pip('install', 'django-devserver==0.0.4')
devserver_folder = script.site_packages / 'devserver'
egg_info_folder = (
script.site_packages /
'django_devserver-0.0.4-py{pyversion}.egg-info'.format(**globals())
)
result.did_create(devserver_folder)
result.did_create(egg_info_folder)
def test_install_package_with_target(script):
"""
Test installing a package using pip install --target
"""
target_dir = script.scratch_path / 'target'
result = script.pip_install_local('-t', target_dir, "simple==1.0")
result.did_create(Path('scratch') / 'target' / 'simple')
# Test repeated call without --upgrade, no files should have changed
result = script.pip_install_local(
'-t', target_dir, "simple==1.0", expect_stderr=True,
)
result.did_not_update(Path('scratch') / 'target' / 'simple')
# Test upgrade call, check that new version is installed
result = script.pip_install_local('--upgrade', '-t',
target_dir, "simple==2.0")
result.did_update(Path('scratch') / 'target' / 'simple')
egg_folder = (
Path('scratch') / 'target' /
'simple-2.0-py{pyversion}.egg-info'.format(**globals()))
result.did_create(egg_folder)
# Test install and upgrade of single-module package
result = script.pip_install_local('-t', target_dir, 'singlemodule==0.0.0')
singlemodule_py = Path('scratch') / 'target' / 'singlemodule.py'
result.did_create(singlemodule_py)
result = script.pip_install_local('-t', target_dir, 'singlemodule==0.0.1',
'--upgrade')
result.did_update(singlemodule_py)
@pytest.mark.parametrize("target_option", ['--target', '-t'])
def test_install_package_to_usersite_with_target_must_fail(script,
target_option):
"""
Test that installing package to usersite with target
must raise error
"""
target_dir = script.scratch_path / 'target'
result = script.pip_install_local(
'--user', target_option, target_dir, "simple==1.0", expect_error=True
)
assert "Can not combine '--user' and '--target'" in result.stderr, (
str(result)
)
def test_install_nonlocal_compatible_wheel(script, data):
target_dir = script.scratch_path / 'target'
# Test install with --target
result = script.pip(
'install',
'-t', target_dir,
'--no-index', '--find-links', data.find_links,
'--only-binary=:all:',
'--python', '3',
'--platform', 'fakeplat',
'--abi', 'fakeabi',
'simplewheel',
)
assert result.returncode == SUCCESS
distinfo = Path('scratch') / 'target' / 'simplewheel-2.0-1.dist-info'
result.did_create(distinfo)
# Test install without --target
result = script.pip(
'install',
'--no-index', '--find-links', data.find_links,
'--only-binary=:all:',
'--python', '3',
'--platform', 'fakeplat',
'--abi', 'fakeabi',
'simplewheel',
expect_error=True
)
assert result.returncode == ERROR
def test_install_nonlocal_compatible_wheel_path(
script,
data,
use_new_resolver
):
target_dir = script.scratch_path / 'target'
# Test a full path requirement
result = script.pip(
'install',
'-t', target_dir,
'--no-index',
'--only-binary=:all:',
Path(data.packages) / 'simplewheel-2.0-py3-fakeabi-fakeplat.whl',
expect_error=use_new_resolver
)
if use_new_resolver:
assert result.returncode == ERROR
else:
assert result.returncode == SUCCESS
distinfo = Path('scratch') / 'target' / 'simplewheel-2.0.dist-info'
result.did_create(distinfo)
# Test a full path requirement (without --target)
result = script.pip(
'install',
'--no-index',
'--only-binary=:all:',
Path(data.packages) / 'simplewheel-2.0-py3-fakeabi-fakeplat.whl',
expect_error=True
)
assert result.returncode == ERROR
def test_install_with_target_and_scripts_no_warning(script, with_wheel):
"""
Test that installing with --target does not trigger the "script not
in PATH" warning (issue #5201)
"""
target_dir = script.scratch_path / 'target'
pkga_path = script.scratch_path / 'pkga'
pkga_path.mkdir()
pkga_path.joinpath("setup.py").write_text(textwrap.dedent("""
from setuptools import setup
setup(name='pkga',
version='0.1',
py_modules=["pkga"],
entry_points={
'console_scripts': ['pkga=pkga:main']
}
)
"""))
pkga_path.joinpath("pkga.py").write_text(textwrap.dedent("""
def main(): pass
"""))
result = script.pip('install', '--target', target_dir, pkga_path)
# This assertion isn't actually needed, if we get the script warning
# the script.pip() call will fail with "stderr not expected". But we
# leave the assertion to make the intention of the code clearer.
assert "--no-warn-script-location" not in result.stderr, str(result)
def test_install_package_with_root(script, data):
"""
Test installing a package using pip install --root
"""
root_dir = script.scratch_path / 'root'
result = script.pip(
'install', '--root', root_dir, '-f', data.find_links, '--no-index',
'simple==1.0',