forked from conda/grayskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pypi.py
More file actions
1603 lines (1385 loc) · 54.6 KB
/
test_pypi.py
File metadata and controls
1603 lines (1385 loc) · 54.6 KB
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 hashlib
import json
import os
import sys
from unittest.mock import patch
import pytest
from colorama import Fore, Style
from souschef.jinja_expression import get_global_jinja_var
from souschef.recipe import Recipe
from grayskull.base.factory import GrayskullFactory
from grayskull.base.pkg_info import normalize_pkg_name
from grayskull.cli import CLIConfig
from grayskull.cli.parser import parse_pkg_name_version
from grayskull.config import Configuration
from grayskull.main import create_python_recipe
from grayskull.strategy.py_base import (
clean_deps_for_conda_forge,
generic_py_ver_to,
get_compilers,
get_entry_points_from_sdist,
get_extra_from_requires_dist,
get_name_version_from_requires_dist,
get_sdist_metadata,
get_setup_cfg,
get_test_entry_points,
get_test_imports,
parse_extra_metadata_to_selector,
py_version_to_limit_python,
py_version_to_selector,
update_requirements_with_pin,
)
from grayskull.strategy.pypi import (
PypiStrategy,
check_noarch_python_for_new_deps,
compose_test_section,
extract_optional_requirements,
extract_requirements,
get_all_selectors_pypi,
get_pypi_metadata,
get_sha256_from_pypi_metadata,
get_url_filename,
merge_pypi_sdist_metadata,
normalize_requirements_list,
remove_all_inner_nones,
remove_selectors_pkgs_if_needed,
sort_reqs,
update_recipe,
)
from grayskull.utils import PyVer, format_dependencies, generate_recipe
@pytest.fixture
def pypi_metadata():
path_metadata = os.path.join(
os.path.dirname(__file__), "data", "pypi_pytest_metadata.json"
)
with open(path_metadata) as f:
return json.load(f)
@pytest.fixture
def freeze_py_cf_supported():
return [
PyVer(3, 6),
PyVer(3, 7),
PyVer(3, 8),
PyVer(3, 9),
PyVer(3, 10),
PyVer(3, 11),
]
@pytest.fixture
def recipe_config():
config = Configuration(
name="pytest",
py_cf_supported=[
PyVer(3, 6),
PyVer(3, 7),
PyVer(3, 8),
PyVer(3, 9),
PyVer(3, 10),
PyVer(3, 11),
PyVer(3, 12),
],
supported_py=[
PyVer(2, 7),
PyVer(3, 6),
PyVer(3, 7),
PyVer(3, 8),
PyVer(3, 9),
PyVer(3, 10),
PyVer(3, 11),
],
)
recipe = Recipe(name="pytest")
return recipe, config
@pytest.fixture
def pypi_metadata_with_extras():
path_metadata = os.path.join(
os.path.dirname(__file__), "data", "pypi_dask_metadata.json"
)
with open(path_metadata) as f:
return json.load(f)
def test_extract_pypi_requirements(pypi_metadata, recipe_config):
recipe, config = recipe_config
pypi_metadata["info"]["setup_requires"] = ["tomli >1.0.0 ; python_version >=3.11"]
pypi_reqs = extract_requirements(pypi_metadata["info"], config, recipe)
assert sorted(pypi_reqs["host"]) == sorted(
["python", "pip", "tomli >1.0.0 # [py>=311]"]
)
assert sorted(pypi_reqs["run"]) == sorted(
[
"python",
"py >=1.5.0",
"packaging",
"attrs >=17.4.0",
"more-itertools >=4.0.0",
"pluggy <1.0,>=0.12",
"wcwidth",
"pathlib2 >=2.2.0 # [py<36]",
"importlib-metadata >=0.12 # [py<38]",
"atomicwrites >=1.0 # [win]",
"colorama # [win]",
]
)
def test_get_pypi_metadata(pypi_metadata):
recipe = Recipe(name="pytest")
config = Configuration(name="pytest", version="5.3.1", is_strict_cf=True)
metadata = get_pypi_metadata(config)
PypiStrategy.fetch_data(recipe, config)
assert metadata["name"] == "pytest"
assert metadata["version"] == "5.3.1"
assert "pathlib2 >=2.2.0 # [py<36]" not in recipe["requirements"]["run"]
def test_get_name_version_from_requires_dist():
assert get_name_version_from_requires_dist("py (>=1.5.0)") == (
"py",
">=1.5.0",
)
def test_get_extra_from_requires_dist():
assert get_extra_from_requires_dist(' python_version < "3.6"') == [
(
"",
"python_version",
"<",
"3.6",
"",
"",
)
]
assert get_extra_from_requires_dist(
" python_version < \"3.6\" ; extra =='test'"
) == [
("", "python_version", "<", "3.6", "", ""),
("", "extra", "==", "test", "", ""),
]
assert get_extra_from_requires_dist(
' (sys_platform =="win32" and python_version =="2.7") and extra =="socks"'
) == [
("(", "sys_platform", "==", "win32", "", "and"),
("", "python_version", "==", "2.7", ")", "and"),
("", "extra", "==", "socks", "", ""),
]
@pytest.fixture(scope="module")
def dask_sdist_metadata():
config = Configuration(name="dask")
return get_sdist_metadata(
"https://pypi.org/packages/source/d/dask/dask-2022.6.1.tar.gz",
config,
)
def test_get_extra_requirements(dask_sdist_metadata):
received = {
extra: set(req_lst)
for extra, req_lst in dask_sdist_metadata["extras_require"].items()
}
expected = {
"array": {"numpy >= 1.18"},
"bag": set(),
"dataframe": {"pandas >= 1.0", "numpy >= 1.18"},
"distributed": {"distributed == 2022.6.1"},
"diagnostics": {"bokeh >= 2.4.2", "jinja2"},
"delayed": set(),
"complete": {
"bokeh >= 2.4.2",
"numpy >= 1.18",
"distributed == 2022.6.1",
"pandas >= 1.0",
"jinja2",
},
"test": {"pytest-xdist", "pytest-rerunfailures", "pre-commit", "pytest"},
}
assert received == expected
def test_extract_optional_requirements(dask_sdist_metadata):
config = Configuration(name="dask")
received = extract_optional_requirements(dask_sdist_metadata, config)
assert not received
all_optional_reqs = {
"array": {"numpy >=1.18"},
"complete": {
"distributed ==2022.6.1",
"pandas >=1.0",
"numpy >=1.18",
"bokeh >=2.4.2",
"jinja2",
},
"dataframe": {"numpy >=1.18", "pandas >=1.0"},
"diagnostics": {"bokeh >=2.4.2", "jinja2"},
"distributed": {"distributed ==2022.6.1"},
"test": {"pytest-xdist", "pre-commit", "pytest-rerunfailures", "pytest"},
}
config.extras_require_all = True
received = extract_optional_requirements(dask_sdist_metadata, config)
received = {k: set(v) for k, v in received.items()}
expected = {k: set(v) for k, v in all_optional_reqs.items()}
assert received == expected
config.extras_require_all = True
config.extras_require_include = None
config.extras_require_exclude = ["complete"]
received = extract_optional_requirements(dask_sdist_metadata, config)
received = {k: set(v) for k, v in received.items()}
expected = {k: set(v) for k, v in all_optional_reqs.items() if k != "complete"}
assert received == expected
config.extras_require_all = False
config.extras_require_include = ["complete"]
config.extras_require_exclude = None
received = extract_optional_requirements(dask_sdist_metadata, config)
received = {k: set(v) for k, v in received.items()}
expected = {k: set(v) for k, v in all_optional_reqs.items() if k == "complete"}
assert received == expected
config.extras_require_all = True
config.extras_require_include = ["complete"]
config.extras_require_exclude = None
received = extract_optional_requirements(dask_sdist_metadata, config)
received = {k: set(v) for k, v in received.items()}
expected = {k: set(v) for k, v in all_optional_reqs.items()}
assert received == expected
config.extras_require_all = True
config.extras_require_include = None
config.extras_require_exclude = ["complete", "test"]
received = extract_optional_requirements(dask_sdist_metadata, config)
received = {k: set(v) for k, v in received.items()}
expected = {
k: set(v) for k, v in all_optional_reqs.items() if k not in ("complete", "test")
}
assert received == expected
config.extras_require_all = True
config.extras_require_include = None
config.extras_require_exclude = ["complete", "test"]
config.extras_require_test = "test"
received = extract_optional_requirements(dask_sdist_metadata, config)
received = {k: set(v) for k, v in received.items()}
expected = {k: set(v) for k, v in all_optional_reqs.items() if k != "complete"}
assert received == expected
def test_compose_test_section_with_console_scripts():
config = Configuration(name="pytest", version="7.1.2")
metadata1 = get_pypi_metadata(config)
metadata2 = get_sdist_metadata(
"https://pypi.org/packages/source/p/pytest/pytest-7.1.2.tar.gz", config
)
metadata = merge_pypi_sdist_metadata(metadata1, metadata2, config)
test_requirements = []
test_section = compose_test_section(metadata, test_requirements)
test_section = {k: set(v) for k, v in test_section.items()}
expected = {
"imports": {"pytest"},
"commands": {"pip check", "py.test --help", "pytest --help"},
"requires": {"pip"},
}
assert test_section == expected
def test_compose_test_section_with_requirements(dask_sdist_metadata):
config = Configuration(name="dask", version="2022.7.1")
metadata = get_pypi_metadata(config)
test_requirements = dask_sdist_metadata["extras_require"]["test"]
test_section = compose_test_section(metadata, test_requirements)
test_section = {k: set(v) for k, v in test_section.items()}
expected = {
"imports": {"dask"},
"commands": {"pip check", "pytest --pyargs dask"},
"requires": {
"pip",
"pytest",
"pytest-xdist",
"pytest-rerunfailures",
"pre-commit",
},
}
assert test_section == expected
def test_get_include_extra_requirements():
base_requirements = [
"cloudpickle >=1.1.1",
"fsspec >=0.6.0",
"packaging >=20.0",
"partd >=0.3.10",
"python >=3.8",
"pyyaml >=5.3.1",
"toolz >=0.8.2",
]
host_requirements = ["python >=3.8", "pip"]
extras = {}
extras["array"] = ["numpy >=1.18"]
extras["distributed"] = ["distributed ==2022.6.1"]
extras["diagnostics"] = ["bokeh >=2.4.2", "jinja2"]
extras["dataframe"] = ["numpy >=1.18", "pandas >=1.0"]
extras["test"] = ["pytest-xdist", "pytest", "pytest-rerunfailures", "pre-commit"]
extras["complete"] = [
"distributed ==2022.6.1",
"jinja2",
"numpy >=1.18",
"bokeh >=2.4.2",
"pandas >=1.0",
]
def set_of_strings(sequence):
return set(map(str, sequence))
# extras are not used
config = Configuration(name="dask", version="2022.6.1")
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["outputs"]) == set()
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set(recipe["requirements"]["run"]) == set(base_requirements)
assert set(recipe["test"]["requires"]) == {"pip"}
# all extras are included in the requirements
config = Configuration(name="dask", version="2022.6.1", extras_require_all=True)
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["outputs"]) == set()
expected = list(base_requirements)
for name, req_lst in extras.items():
if name != "complete":
expected.append(f"Extra: {name}")
expected.extend(req_lst)
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set_of_strings(recipe["requirements"]["run"]) == set(expected)
assert set_of_strings(recipe["test"]["requires"]) == {"pip"}
# all extras are included in the requirements except for the
# test requirements which are in the test section
config = Configuration(
name="dask",
version="2022.6.1",
extras_require_all=True,
extras_require_test="test",
)
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["outputs"]) == set()
expected = list(base_requirements)
for name, req_lst in extras.items():
if name not in ("test", "complete"):
expected.append(f"Extra: {name}")
expected.extend(req_lst)
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set_of_strings(recipe["requirements"]["run"]) == set(expected)
assert set_of_strings(recipe["test"]["requires"]) == {"pip", *extras["test"]}
# only "array" is included in the requirements
config = Configuration(
name="dask", version="2022.6.1", extras_require_include=("array",)
)
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["outputs"]) == set()
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set_of_strings(recipe["requirements"]["run"]) == {
*base_requirements,
"Extra: array",
*extras["array"],
}
assert set_of_strings(recipe["test"]["requires"]) == {"pip"}
# only "test" is included but in the test section
config = Configuration(
name="dask",
version="2022.6.1",
extras_require_all=True,
extras_require_exclude=set(extras) - {"test"},
extras_require_test="test",
)
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["outputs"]) == set()
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set_of_strings(recipe["requirements"]["run"]) == set(base_requirements)
assert set_of_strings(recipe["test"]["requires"]) == {"pip", *extras["test"]}
# only "test" is included in the test section
config = Configuration(
name="dask",
version="2022.6.1",
extras_require_all=True,
extras_require_exclude=set(extras) - {"test"},
extras_require_test="test",
extras_require_split=True,
)
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["outputs"]) == set()
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set_of_strings(recipe["requirements"]["run"]) == set(base_requirements)
assert set_of_strings(recipe["test"]["requires"]) == {"pip", *extras["test"]}
# all extras have their own output except for the
# test requirements which are in the test section
config = Configuration(
name="dask",
version="2022.6.1",
extras_require_all=True,
extras_require_test="test",
extras_require_split=True,
)
recipe = GrayskullFactory.create_recipe("pypi", config)
assert recipe["package"]["name"] == "<{ name|lower }}"
assert set(recipe["requirements"]["host"]) == set(host_requirements)
assert set(recipe["requirements"]["run"]) == set(base_requirements)
assert len(recipe["outputs"]) == 6
expected = {}
for name, req_lst in extras.items():
if name != "test":
expected[f"dask-{name}"] = {
"{{ pin_subpackage('dask', exact=True) }}",
"python >=3.8",
*req_lst,
}
found = {}
for output in recipe["outputs"]:
if output["name"] == "dask":
assert "requirements" not in output
else:
assert set(output["requirements"]["host"]) == set(host_requirements)
found[output["name"]] = set_of_strings(output["requirements"]["run"])
assert found == expected
expected = {"pip", *extras["test"]}
assert set_of_strings(recipe["test"]["requires"]) == expected
for output in recipe["outputs"]:
if output["name"] == "dask":
assert "test" not in output
else:
assert set_of_strings(output["test"]["requires"]) == expected
expected = {"noarch": "python"}
for output in recipe["outputs"]:
if output["name"] == "dask":
assert "build" not in output
else:
assert output["build"] == expected
def test_normalize_requirements_list():
config = Configuration(name="pytest")
requirements = ["pytest ~=5.3.2", "pyqt5"]
requirements = set(normalize_requirements_list(requirements, config))
expected = {"pytest >=5.3.2,<5.4.dev0", "pyqt"}
assert requirements == expected
def test_get_all_selectors_pypi(recipe_config):
_, config = recipe_config
config.version = "5.3.1"
assert get_all_selectors_pypi(
[
("(", "sys_platform", "==", "win32", "", "and"),
("", "python_version", "==", "2.7", ")", "and"),
("", "extra", "==", "socks", "", ""),
],
config,
) == ["(", "win", "and", "py==27", ")"]
def test_get_selector():
assert parse_extra_metadata_to_selector("extra", "==", "win32") == ""
assert parse_extra_metadata_to_selector("sys_platform", "==", "win32") == "win"
assert parse_extra_metadata_to_selector("python_version", "<", "3.6") == "py<36"
@pytest.mark.parametrize(
"requires_python, exp_selector, ex_cf",
[
(">=3.5", "2k", "<36"),
(">=3.6", "2k", None),
(">=3.7", "<37", "<37"),
("<=3.7", ">=38", ">=38"),
("<=3.7.1", ">=38", ">=38"),
("<3.7", ">=37", ">=37"),
(">2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", "<36", "<36"),
(">=2.7, !=3.6.*", "==36", "<37"),
(">3.7", "<38", "<38"),
(">2.7", "2k", "<36"),
("<3", "3k", "skip"),
("!=3.7", "==37", "==37"),
("~=3.7", "<37", "<37"),
],
)
def test_py_version_to_selector(requires_python, exp_selector, ex_cf, recipe_config):
config = recipe_config[1]
metadata = {"requires_python": requires_python}
assert py_version_to_selector(metadata, config) == f"# [py{exp_selector}]"
if ex_cf != "skip":
expected = f"# [py{ex_cf}]" if ex_cf else None
config.is_strict_cf = True
result = py_version_to_selector(metadata, config)
if isinstance(expected, str):
assert expected == result
else:
assert expected is result
@pytest.mark.parametrize(
"requires_python, exp_limit, ex_cf",
[
(">=3.5", ">=3.5", ">=3.6"),
(">=3.6", ">=3.6", ">=3.6"),
(">=3.7", ">=3.7", ">=3.7"),
("<=3.7", "<3.8", "<3.8"),
("<=3.7.1", "<3.8", "<3.8"),
("<3.7", "<3.7", "<3.7"),
(">2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", ">=3.6", ">=3.6"),
(">=2.7, !=3.6.*", "!=3.6", ">=3.7"),
(">3.7", ">=3.8", ">=3.8"),
(">2.7", ">=3.6", ">=3.6"),
("<3", "<3.0", "skip"),
("!=3.7", "!=3.7", "!=3.7"),
("~=3.7", ">=3.7", ">=3.7"),
],
)
def test_py_version_to_limit_python(requires_python, exp_limit, ex_cf, recipe_config):
metadata = {"requires_python": requires_python}
assert py_version_to_limit_python(metadata, recipe_config[1]) == f"{exp_limit}"
if ex_cf != "skip":
config = recipe_config[1]
config.is_strict_cf = True
result = py_version_to_limit_python(metadata, config)
if isinstance(ex_cf, str):
assert ex_cf == result
else:
assert ex_cf is result
def test_get_sha256_from_pypi_metadata():
metadata = {
"urls": [
{"packagetype": "egg", "digests": {"sha256": "23123"}},
{"packagetype": "sdist", "digests": {"sha256": "1234sha256"}},
]
}
assert get_sha256_from_pypi_metadata(metadata) == "1234sha256"
metadata = {
"urls": [
{"packagetype": "egg", "digests": {"sha256": "23123"}},
{"packagetype": "wheel", "digests": {"sha256": "1234sha256"}},
]
}
with pytest.raises(AttributeError) as err:
get_sha256_from_pypi_metadata(metadata)
assert err.match("Hash information for sdist was not found on PyPi metadata.")
@pytest.mark.github
@pytest.mark.parametrize(
"name", ["hypothesis", "https://github.com/HypothesisWorks/hypothesis"]
)
def test_injection_distutils(name):
config = Configuration(name="hypothesis")
data = get_sdist_metadata(
"https://pypi.org/packages/source/h/hypothesis/hypothesis-5.5.1.tar.gz",
config,
)
assert sorted(data["install_requires"]) == sorted(
["attrs>=19.2.0", "sortedcontainers>=2.1.0,<3.0.0"]
)
assert data["entry_points"] == {
"pytest11": ["hypothesispytest = hypothesis.extra.pytestplugin"]
}
assert data["version"] == "5.5.1"
assert data["name"] == "hypothesis"
assert not data.get("compilers")
def test_injection_distutils_pytest():
config = Configuration(name="pytest", version="5.3.2")
data = get_sdist_metadata(
"https://pypi.org/packages/source/p/pytest/pytest-5.3.2.tar.gz", config
)
assert sorted(data["install_requires"]) == sorted(
[
"py>=1.5.0",
"packaging",
"attrs>=17.4.0",
"more-itertools>=4.0.0",
'atomicwrites>=1.0;sys_platform=="win32"',
'pathlib2>=2.2.0;python_version<"3.6"',
'colorama;sys_platform=="win32"',
"pluggy>=0.12,<1.0",
'importlib-metadata>=0.12;python_version<"3.8"',
"wcwidth",
]
)
assert sorted(data["setup_requires"]) == sorted(
["setuptools-scm", "setuptools>=40.0", "wheel"]
)
assert not data.get("compilers")
def test_injection_distutils_compiler_gsw():
config = Configuration(name="gsw", version="3.6.19")
data = get_sdist_metadata(
"https://pypi.org/packages/source/g/gsw/gsw-3.6.19.tar.gz", config
)
assert data.get("compilers") == ["c"]
assert data["name"] == "gsw"
def test_injection_distutils_setup_reqs_ensure_list():
pkg_name, pkg_ver = "pyinstaller-hooks-contrib", "2020.7"
config = Configuration(name=pkg_name, version=pkg_ver)
data = get_sdist_metadata(
f"https://pypi.org/packages/source/p/{pkg_name}/{pkg_name}-{pkg_ver}.tar.gz",
config,
)
assert data.get("setup_requires") == ["setuptools >= 30.3.0"]
def test_merge_pypi_sdist_metadata():
config = Configuration(name="gsw", version="3.6.19")
pypi_metadata = get_pypi_metadata(config)
sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config)
merged_data = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config)
assert merged_data["compilers"] == ["c"]
assert sorted(merged_data["setup_requires"]) == sorted(
[
"build",
'numpy<3,>=2.0.0rc1; python_version >= "3.9"',
'oldest-supported-numpy; python_version < "3.9"',
"pip>9.0.1",
"setuptools>=42",
"setuptools_scm[toml]>=3.4",
"wheel",
"python >=3.8",
]
)
def test_pypi_metadata_constraints_for_python_versions():
config = Configuration(name="apache-airflow-providers-trino", version="6.0.0")
pypi_metadata = get_pypi_metadata(config)
assert sorted(pypi_metadata["requires_dist"]) == sorted(
[
"apache-airflow-providers-common-sql>=1.20.0",
"apache-airflow>=2.9.0",
'pandas<2.2,>=1.5.3; python_version < "3.9"',
'pandas<2.2,>=2.1.2; python_version >= "3.9"',
"trino>=0.318.0",
'apache-airflow-providers-google; extra == "google"',
'apache-airflow-providers-openlineage; extra == "openlineage"',
]
)
config = Configuration(name="databricks-sql-connector", version="3.7.0")
pypi_metadata = get_pypi_metadata(config)
assert sorted(pypi_metadata["requires_dist"]) == sorted(
[
'alembic<2.0.0,>=1.0.11; extra == "alembic"',
"lz4<5.0.0,>=4.0.2",
'numpy>=1.16.6; python_version >= "3.8" and python_version < "3.11"',
'numpy>=1.23.4; python_version >= "3.11"',
"oauthlib<4.0.0,>=3.1.0",
"openpyxl<4.0.0,>=3.0.10",
'pandas<2.3.0,>=1.2.5; python_version >= "3.8"',
"pyarrow>=14.0.1",
"requests<3.0.0,>=2.18.1",
'sqlalchemy>=2.0.21; extra == "sqlalchemy" or extra == "alembic"',
"thrift<0.21.0,>=0.16.0",
"urllib3>=1.26",
]
)
def test_sdist_metadata_from_toml_project_dependencies():
config = Configuration(name="apache-airflow-providers-trino", version="6.0.0")
pypi_metadata = get_pypi_metadata(config)
sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config)
assert sorted(sdist_metadata["install_requires"]) == sorted(
[
"apache-airflow-providers-common-sql>=1.20.0",
"apache-airflow>=2.9.0",
'pandas>=1.5.3,<2.2;python_version<"3.9"',
'pandas>=2.1.2,<2.2;python_version>="3.9"',
"trino>=0.318.0",
"python ~=3.9",
]
)
def test_sdist_metadata_from_toml_poetry_dependencies():
config = Configuration(name="databricks-sql-connector", version="3.7.0")
pypi_metadata = get_pypi_metadata(config)
sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config)
assert sorted(sdist_metadata["install_requires"]) == sorted(
[
"python >=3.8.0,<4.0.0",
"thrift >=0.16.0,<0.21.0",
"pandas >=1.2.5,<2.3.0 # [py>=38]",
"pyarrow >=14.0.1",
"lz4 >=4.0.2,<5.0.0",
"requests >=2.18.1,<3.0.0",
"oauthlib >=3.1.0,<4.0.0",
"numpy >=1.16.6 # [py>=38 and py<311]",
"numpy >=1.23.4 # [py>=311]",
"openpyxl >=3.0.10,<4.0.0",
"urllib3 >=1.26",
]
)
def test_merge_pypi_sdist_metadata_from_toml():
# tests merging pyproject.toml dependencies from poetry with pypi data,
# including multiple numpy constraints with python version selectors
config = Configuration(name="databricks-sql-connector", version="3.7.0")
pypi_metadata = get_pypi_metadata(config)
sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config)
merged_data = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config)
assert sorted(merged_data["requires_dist"]) == sorted(
[
"python >=3.8.0,<4.0.0",
"thrift >=0.16.0,<0.21.0",
"pandas >=1.2.5,<2.3.0 # [py>=38]",
"pyarrow >=14.0.1",
"lz4 >=4.0.2,<5.0.0",
"requests >=2.18.1,<3.0.0",
"oauthlib >=3.1.0,<4.0.0",
"numpy >=1.16.6 # [py>=38 and py<311]",
"numpy >=1.23.4 # [py>=311]",
"openpyxl >=3.0.10,<4.0.0",
"urllib3 >=1.26",
]
)
# tests merging pyproject.toml project dependencies with pypi data,
# including multiple pandas constraints with python version selectors
config = Configuration(name="apache-airflow-providers-trino", version="6.0.0")
pypi_metadata = get_pypi_metadata(config)
sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config)
merged_data = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config)
assert sorted(merged_data["requires_dist"]) == sorted(
[
"apache-airflow-providers-common-sql>=1.20.0",
"apache-airflow>=2.9.0",
'pandas>=1.5.3,<2.2;python_version<"3.9"',
'pandas>=2.1.2,<2.2;python_version>="3.9"',
"trino>=0.318.0",
"python ~=3.9",
]
)
def test_update_requirements_with_pin():
req = {
"build": ["<{ compiler('c') }}"],
"host": ["python", "numpy"],
"run": ["python", "numpy"],
}
update_requirements_with_pin(req)
assert req == {
"build": ["<{ compiler('c') }}"],
"host": ["python", "numpy"],
"run": ["python", "<{ pin_compatible('numpy') }}"],
}
def test_get_compilers():
config = Configuration(name="any_package")
assert get_compilers(["pybind11"], {}, config) == ["cxx"]
assert get_compilers(["cython"], {}, config) == ["c"]
assert sorted(get_compilers(["pybind11", "cython"], {}, config)) == sorted(
["cxx", "c"]
)
assert sorted(get_compilers(["pybind11"], {"compilers": ["c"]}, config)) == sorted(
["cxx", "c"]
)
def test_get_entry_points_from_sdist():
assert get_entry_points_from_sdist({}) == []
assert get_entry_points_from_sdist(
{"entry_points": {"console_scripts": ["console_scripts=entrypoints"]}}
) == ["console_scripts=entrypoints"]
assert get_entry_points_from_sdist(
{"entry_points": {"gui_scripts": ["gui_scripts=entrypoints"]}}
) == ["gui_scripts=entrypoints"]
assert sorted(
get_entry_points_from_sdist(
{
"entry_points": {
"gui_scripts": ["gui_scripts=entrypoints"],
"console_scripts": ["console_scripts=entrypoints"],
}
}
)
) == sorted(["gui_scripts=entrypoints", "console_scripts=entrypoints"])
assert sorted(
get_entry_points_from_sdist(
{
"entry_points": {
"gui_scripts": None,
"console_scripts": "console_scripts=entrypoints",
}
}
)
) == sorted(["console_scripts=entrypoints"])
assert sorted(
get_entry_points_from_sdist(
{
"entry_points": {
"gui_scripts": None,
"console_scripts": "console_scripts=entrypoints\nfoo=bar.main",
}
}
)
) == sorted(["console_scripts=entrypoints", "foo=bar.main"])
assert sorted(
get_entry_points_from_sdist(
{
"entry_points": {
"gui_scripts": "gui_scripts=entrypoints",
"console_scripts": None,
}
}
)
) == sorted(["gui_scripts=entrypoints"])
def test_build_noarch_skip():
recipe = create_python_recipe("hypothesis=5.5.2")[0]
assert recipe["build"]["noarch"] == "python"
assert "skip" not in recipe["build"]
@pytest.mark.github
def test_build_noarch_skip_github():
recipe = create_python_recipe(
"https://github.com/HypothesisWorks/hypothesis", version="5.5.2"
)[0]
assert recipe["build"]["noarch"] == "python"
assert "skip" not in recipe["build"]
def test_run_requirements_sdist():
config = Configuration(name="botocore", version="1.14.17")
recipe = GrayskullFactory.create_recipe("pypi", config)
assert sorted(recipe["requirements"]["run"]) == sorted(
[
"docutils >=0.10,<0.16",
"jmespath >=0.7.1,<1.0.0",
"python",
"python-dateutil >=2.1,<3.0.0",
"urllib3 >=1.20,<1.26",
]
)
# a more complex example with selectors
config = Configuration(name="apache-airflow-providers-trino", version="6.0.0")
recipe = GrayskullFactory.create_recipe("pypi", config)
assert "noarch" not in recipe["build"]
selectors = {
"python >=3.9,<4.dev0": None,
"apache-airflow-providers-common-sql >=1.20.0": None,
"apache-airflow >=2.9.0": None,
"pandas >=1.5.3,<2.2": "[py<39]",
"pandas >=2.1.2,<2.2": "[py>=39]",
"trino-python-client >=0.318.0": None,
}
for dep in recipe["requirements"]["run"]:
dep_str = str(dep)
assert dep_str in selectors
selector = selectors[dep_str]
if dep.inline_comment is None:
assert selector is None
else:
assert str(dep.inline_comment) == selector
# another example with selectors
config = Configuration(name="databricks-sql-connector", version="3.7.0")
recipe = GrayskullFactory.create_recipe("pypi", config)
assert "noarch" not in recipe["build"]
selectors = {
"python >=3.8.0,<4.0.0": None,
"thrift >=0.16.0,<0.21.0": None,
"pandas >=1.2.5,<2.3.0": "[py>=38]",
"pyarrow >=14.0.1": None,
"lz4 >=4.0.2,<5.0.0": None,
"requests >=2.18.1,<3.0.0": None,
"oauthlib >=3.1.0,<4.0.0": None,
"numpy >=1.16.6": "[py>=38 and py<311]",
"numpy >=1.23.4": "[py>=311]",
"openpyxl >=3.0.10,<4.0.0": None,
"urllib3 >=1.26": None,
}
for dep in recipe["requirements"]["run"]:
dep_str = str(dep)
assert dep_str in selectors
selector = selectors[dep_str]
if dep.inline_comment is None:
assert selector is None
else:
assert str(dep.inline_comment) == selector
def test_format_host_requirements():
assert sorted(format_dependencies(["setuptools>=40.0", "pkg2"], "pkg1")) == sorted(
["setuptools >=40.0", "pkg2"]
)
assert sorted(format_dependencies(["setuptools>=40.0", "pkg2"], "pkg2")) == sorted(
["setuptools >=40.0"]
)
assert sorted(format_dependencies(["setuptools >= 40.0"], "pkg")) == sorted(
["setuptools >=40.0"]
)
assert sorted(
format_dependencies(["setuptools_scm [toml] >=3.4.1"], "pkg")
) == sorted(["setuptools_scm >=3.4.1"])
def test_download_pkg_sdist(pkg_pytest):
with open(pkg_pytest, "rb") as pkg_file:
content = pkg_file.read()
pkg_sha256 = hashlib.sha256(content).hexdigest()
assert (
pkg_sha256 == "0d5fe9189a148acc3c3eb2ac8e1ac0742cb7618c084f3d228baaec0c254b318d"
)
setup_cfg = get_setup_cfg(os.path.dirname(pkg_pytest))
assert setup_cfg["name"] == "pytest"
assert setup_cfg["python_requires"] == ">=3.5"
assert setup_cfg["entry_points"] == {
"console_scripts": ["pytest=pytest:main", "py.test=pytest:main"]
}
def test_ciso_recipe():
recipe = GrayskullFactory.create_recipe(
"pypi", Configuration(name="ciso", version="0.2.2")
)
assert sorted(recipe["requirements"]["host"]) == sorted(
[
"cython >=3",
"numpy >=2.0.0rc1",
"oldest-supported-numpy",
"pip",
"python >=3.9",
"setuptools >=41.2",
"setuptools-scm",
"wheel",
]
)
assert sorted(recipe["requirements"]["run"]) == sorted(
["<{ pin_compatible('numpy') }}", "oldest-supported-numpy", "python >=3.9"]