|
6 | 6 | from distutils.sysconfig import get_config_var
|
7 | 7 | from distutils.util import get_platform
|
8 | 8 | import contextlib
|
| 9 | +import pathlib |
| 10 | +import stat |
9 | 11 | import glob
|
10 | 12 | import inspect
|
11 | 13 | import os
|
@@ -614,3 +616,85 @@ def sys_tags():
|
614 | 616 | monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags)
|
615 | 617 | assert Wheel(
|
616 | 618 | 'onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl').is_compatible()
|
| 619 | + |
| 620 | + |
| 621 | +def test_wheel_mode(): |
| 622 | + @contextlib.contextmanager |
| 623 | + def build_wheel(extra_file_defs=None, **kwargs): |
| 624 | + file_defs = { |
| 625 | + 'setup.py': (DALS( |
| 626 | + ''' |
| 627 | + # -*- coding: utf-8 -*- |
| 628 | + from setuptools import setup |
| 629 | + import setuptools |
| 630 | + setup(**%r) |
| 631 | + ''' |
| 632 | + ) % kwargs).encode('utf-8'), |
| 633 | + } |
| 634 | + if extra_file_defs: |
| 635 | + file_defs.update(extra_file_defs) |
| 636 | + with tempdir() as source_dir: |
| 637 | + path.build(file_defs, source_dir) |
| 638 | + runsh = pathlib.Path(source_dir) / "script.sh" |
| 639 | + os.chmod(runsh, 0o777) |
| 640 | + subprocess.check_call((sys.executable, 'setup.py', |
| 641 | + '-q', 'bdist_wheel'), cwd=source_dir) |
| 642 | + yield glob.glob(os.path.join(source_dir, 'dist', '*.whl'))[0] |
| 643 | + |
| 644 | + params = dict( |
| 645 | + id='script', |
| 646 | + file_defs={ |
| 647 | + 'script.py': DALS( |
| 648 | + ''' |
| 649 | + #/usr/bin/python |
| 650 | + print('hello world!') |
| 651 | + ''' |
| 652 | + ), |
| 653 | + 'script.sh': DALS( |
| 654 | + ''' |
| 655 | + #/bin/sh |
| 656 | + echo 'hello world!' |
| 657 | + ''' |
| 658 | + ), |
| 659 | + }, |
| 660 | + setup_kwargs=dict( |
| 661 | + scripts=['script.py', 'script.sh'], |
| 662 | + ), |
| 663 | + install_tree=flatten_tree({ |
| 664 | + 'foo-1.0-py{py_version}.egg': { |
| 665 | + 'EGG-INFO': [ |
| 666 | + 'PKG-INFO', |
| 667 | + 'RECORD', |
| 668 | + 'WHEEL', |
| 669 | + 'top_level.txt', |
| 670 | + {'scripts': [ |
| 671 | + 'script.py', |
| 672 | + 'script.sh' |
| 673 | + ]} |
| 674 | + |
| 675 | + ] |
| 676 | + } |
| 677 | + }) |
| 678 | + ) |
| 679 | + |
| 680 | + project_name = params.get('name', 'foo') |
| 681 | + version = params.get('version', '1.0') |
| 682 | + install_tree = params.get('install_tree') |
| 683 | + file_defs = params.get('file_defs', {}) |
| 684 | + setup_kwargs = params.get('setup_kwargs', {}) |
| 685 | + |
| 686 | + with build_wheel( |
| 687 | + name=project_name, |
| 688 | + version=version, |
| 689 | + install_requires=[], |
| 690 | + extras_require={}, |
| 691 | + extra_file_defs=file_defs, |
| 692 | + **setup_kwargs |
| 693 | + ) as filename, tempdir() as install_dir: |
| 694 | + _check_wheel_install(filename, install_dir, |
| 695 | + install_tree, project_name, |
| 696 | + version, None) |
| 697 | + w = Wheel(filename) |
| 698 | + script_sh = pathlib.Path(install_dir) / w.egg_name() / "EGG-INFO" / "scripts" / "script.sh" |
| 699 | + assert script_sh.exists() |
| 700 | + assert oct(stat.S_IMODE(script_sh.stat().st_mode)) == "0o777" |
0 commit comments