def setup_args(config_path=Path("pyproject.toml")): cfg = config.read_flit_config(config_path) module = common.Module(cfg.module, config_path.parent) metadata = common.make_metadata(module, cfg) kwargs = {} for st_field, metadata_field in field_map.items(): val = getattr(metadata, metadata_field, None) if val is not None: kwargs[st_field] = val else: msg = f"{metadata_field} not found in {dir(metadata)}" assert metadata_field in {"license"}, msg kwargs["packages"] = setuptools.find_packages( include=[metadata.name + "*"]) if metadata.requires_dist: kwargs["install_requires"] = [ req for req in metadata.requires_dist if "extra ==" not in req ] if cfg.reqs_by_extra: kwargs["extras_require"] = cfg.reqs_by_extra scripts = cfg.entrypoints.get("console_scripts") if scripts is not None: kwargs["entry_points"] = dict( console_scipts=[" = ".join(ep) for ep in scripts.items()]) kwargs["include_package_data"] = True kwargs["package_data"] = { module.name: [re.escape(f[len(module.name) + 1:]) for f in find_files(module.path)] } return kwargs
def install_with_pip(self): self.install_reqs_my_python_if_needed() with tempfile.TemporaryDirectory() as td: temp_whl = osp.join(td, 'temp.whl') with open(temp_whl, 'w+b') as fp: wb = WheelBuilder( str(self.directory), self.module, metadata=common.make_metadata(self.module, self.ini_info), entrypoints=self.ini_info.entrypoints, target_fp=fp, ) wb.build() renamed_whl = osp.join(td, wb.wheel_filename) os.rename(temp_whl, renamed_whl) extras = self._extras_to_install() extras.discard('.none') whl_with_extras = '{}[{}]'.format(renamed_whl, ','.join(extras)) \ if extras else renamed_whl cmd = [self.python, '-m', 'pip', 'install', whl_with_extras] if self.user: cmd.append('--user') if self.deps == 'none': cmd.append('--no-deps') shell = (os.name == 'nt') check_call(cmd, shell=shell)
def test_make_metadata(): project_dir = samples_dir / 'pep621_nodynamic' ini_info = config.read_flit_config(project_dir / 'pyproject.toml') module = Module(ini_info.module, project_dir) print(module.file) md = make_metadata(module, ini_info) assert md.version == '0.3' assert md.summary == "Statically specified description"
def write_dist_info(self, site_pkgs): """Write dist-info folder, according to PEP 376""" metadata = common.make_metadata(self.module, self.ini_info) dist_info = pathlib.Path(site_pkgs) / common.dist_info_name( metadata.name, metadata.version) try: dist_info.mkdir() except FileExistsError: shutil.rmtree(str(dist_info)) dist_info.mkdir() with (dist_info / 'METADATA').open('w', encoding='utf-8') as f: metadata.write_metadata_file(f) self.installed_files.append(dist_info / 'METADATA') with (dist_info / 'INSTALLER').open('w', encoding='utf-8') as f: f.write('flit') self.installed_files.append(dist_info / 'INSTALLER') # We only handle explicitly requested installations with (dist_info / 'REQUESTED').open('wb'): pass self.installed_files.append(dist_info / 'REQUESTED') if self.ini_info.entrypoints: with (dist_info / 'entry_points.txt').open('w') as f: common.write_entry_points(self.ini_info.entrypoints, f) self.installed_files.append(dist_info / 'entry_points.txt') with (dist_info / 'direct_url.json').open('w', encoding='utf-8') as f: json.dump( { "url": self.directory.resolve().as_uri(), "dir_info": { "editable": bool(self.symlink or self.pth) } }, f) self.installed_files.append(dist_info / 'direct_url.json') # newline='' because the csv module does its own newline translation with (dist_info / 'RECORD').open('w', encoding='utf-8', newline='') as f: cf = csv.writer(f) for path in sorted(self.installed_files, key=str): path = pathlib.Path(path) if path.is_symlink() or path.suffix in {'.pyc', '.pyo'}: hash, size = '', '' else: hash = 'sha256=' + common.hash_file(str(path)) size = path.stat().st_size try: path = path.relative_to(site_pkgs) except ValueError: pass cf.writerow((str(path), hash, size)) cf.writerow( ((dist_info / 'RECORD').relative_to(site_pkgs), '', ''))
def write_dist_info(self, site_pkgs): """Write dist-info folder, according to PEP 376""" metadata = common.make_metadata(self.module, self.ini_info) dist_info = pathlib.Path(site_pkgs) / common.dist_info_name( metadata.name, metadata.version) try: dist_info.mkdir() except FileExistsError: shutil.rmtree(str(dist_info)) dist_info.mkdir() with (dist_info / 'METADATA').open('w', encoding='utf-8') as f: metadata.write_metadata_file(f) self.installed_files.append(dist_info / 'METADATA') with (dist_info / 'INSTALLER').open('w', encoding='utf-8') as f: f.write('flit') self.installed_files.append(dist_info / 'INSTALLER') # We only handle explicitly requested installations with (dist_info / 'REQUESTED').open('wb'): pass self.installed_files.append(dist_info / 'REQUESTED') if self.ini_info.entrypoints: with (dist_info / 'entry_points.txt').open('w') as f: common.write_entry_points(self.ini_info.entrypoints, f) self.installed_files.append(dist_info / 'entry_points.txt') with (dist_info / 'RECORD').open('w', encoding='utf-8') as f: cf = csv.writer(f) for path in self.installed_files: path = pathlib.Path(path) if path.is_symlink() or path.suffix in {'.pyc', '.pyo'}: hash, size = '', '' else: hash = 'sha256=' + common.hash_file(str(path)) size = path.stat().st_size try: path = path.relative_to(site_pkgs) except ValueError: pass cf.writerow((str(path), hash, size)) cf.writerow( ((dist_info / 'RECORD').relative_to(site_pkgs), '', ''))