A PEP-517 `build_sdist()` function. Also called by `handle_argv()` to handle the `sdist` command. Returns leafname of generated archive within `sdist_directory`.
(self,
sdist_directory,
formats,
config_settings=None,
)
| 808 | |
| 809 | |
| 810 | def build_sdist(self, |
| 811 | sdist_directory, |
| 812 | formats, |
| 813 | config_settings=None, |
| 814 | ): |
| 815 | ''' |
| 816 | A PEP-517 `build_sdist()` function. |
| 817 | |
| 818 | Also called by `handle_argv()` to handle the `sdist` command. |
| 819 | |
| 820 | Returns leafname of generated archive within `sdist_directory`. |
| 821 | ''' |
| 822 | assert self.fn_sdist, f'fn_sdist() not provided.' |
| 823 | log2( |
| 824 | f' sdist_directory={sdist_directory!r}' |
| 825 | f' formats={formats!r}' |
| 826 | f' config_settings={config_settings!r}' |
| 827 | ) |
| 828 | if formats and formats != 'gztar': |
| 829 | raise Exception( f'Unsupported: formats={formats}') |
| 830 | items = list() |
| 831 | if inspect.signature(self.fn_sdist).parameters: |
| 832 | items = self.fn_sdist(config_settings) |
| 833 | else: |
| 834 | items = self.fn_sdist() |
| 835 | |
| 836 | prefix = f'{_normalise2(self.name)}-{self.version}' |
| 837 | os.makedirs(sdist_directory, exist_ok=True) |
| 838 | tarpath = f'{sdist_directory}/{prefix}.tar.gz' |
| 839 | log2(f'Creating sdist: {tarpath}') |
| 840 | |
| 841 | with tarfile.open(tarpath, 'w:gz') as tar: |
| 842 | |
| 843 | names_in_tar = list() |
| 844 | def check_name(name): |
| 845 | if name in names_in_tar: |
| 846 | raise Exception(f'Name specified twice: {name}') |
| 847 | names_in_tar.append(name) |
| 848 | |
| 849 | def add(from_, name): |
| 850 | check_name(name) |
| 851 | if isinstance(from_, str): |
| 852 | log2( f'Adding file: {os.path.relpath(from_)} => {name}') |
| 853 | tar.add( from_, f'{prefix}/{name}', recursive=False) |
| 854 | elif isinstance(from_, bytes): |
| 855 | log2( f'Adding: {name}') |
| 856 | ti = tarfile.TarInfo(f'{prefix}/{name}') |
| 857 | ti.size = len(from_) |
| 858 | ti.mtime = time.time() |
| 859 | tar.addfile(ti, io.BytesIO(from_)) |
| 860 | else: |
| 861 | assert 0 |
| 862 | |
| 863 | def add_string(text, name): |
| 864 | textb = text.encode('utf8') |
| 865 | return add(textb, name) |
| 866 | |
| 867 | found_pyproject_toml = False |
no test coverage detected