Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
td = copy_sample('module1_ini')
(td / 'module1.py').chmod(0o620)
make_wheel_in(td / 'flit.ini', td)
whl = td / 'module1-0.1-py2.py3-none-any.whl'
assert_isfile(whl)
with zipfile.ZipFile(str(whl)) as zf:
info = zf.getinfo('module1.py')
perms = (info.external_attr >> 16) & 0o777
assert perms == 0o644, oct(perms)
whl.unlink()
# This time with executable bit set
(td / 'module1.py').chmod(0o720)
make_wheel_in(td / 'flit.ini', td)
assert_isfile(whl)
with zipfile.ZipFile(str(whl)) as zf:
info = zf.getinfo('module1.py')
perms = (info.external_attr >> 16) & 0o777
assert perms == 0o755, oct(perms)
def test_dist_name(copy_sample):
td = copy_sample('altdistname')
make_wheel_in(td / 'flit.ini', td)
res = td / 'package_dist1-0.1-py2.py3-none-any.whl'
assert_isfile(res)
with unpack(res) as td_unpack:
assert_isdir(Path(td_unpack, 'package_dist1-0.1.dist-info'))
def test_wheel_src_package(copy_sample):
td = copy_sample('package2')
make_wheel_in(td / 'package2-pkg.ini', td)
whl_file = td / 'package2-0.1-py2.py3-none-any.whl'
assert_isfile(whl_file)
with unpack(whl_file) as unpacked:
print(os.listdir(unpacked))
assert_isfile(Path(unpacked, 'package2', '__init__.py'))
def test_wheel_module(copy_sample):
td = copy_sample('module1_ini')
make_wheel_in(td / 'flit.ini', td)
assert_isfile(td / 'module1-0.1-py2.py3-none-any.whl')
def test_entry_points_conflict(copy_sample):
td = copy_sample('entrypoints_conflict')
with pytest.raises(EntryPointsConflict):
make_wheel_in(td / 'flit.ini', td)
def test_wheel_src_module(copy_sample):
td = copy_sample('module3')
make_wheel_in(td / 'flit.ini', td)
whl_file = td / 'module3-0.1-py2.py3-none-any.whl'
assert_isfile(whl_file)
with unpack(whl_file) as unpacked:
assert_isfile(Path(unpacked, 'module3.py'))
assert_isdir(Path(unpacked, 'module3-0.1.dist-info'))
assert_isfile(Path(unpacked, 'module3-0.1.dist-info', 'LICENSE'))
def test_entry_points(copy_sample):
td = copy_sample('entrypoints_valid')
make_wheel_in(td / 'flit.ini', td)
assert_isfile(td / 'package1-0.1-py2.py3-none-any.whl')
with unpack(td / 'package1-0.1-py2.py3-none-any.whl') as td_unpack:
entry_points = Path(td_unpack, 'package1-0.1.dist-info', 'entry_points.txt')
assert_isfile(entry_points)
cp = configparser.ConfigParser()
cp.read(str(entry_points))
assert 'console_scripts' in cp.sections()
assert 'myplugins' in cp.sections()
def test_compression(tmp_path):
info = make_wheel_in(samples_dir / 'module1_ini' / 'flit.ini', tmp_path)
assert_isfile(info.file)
with zipfile.ZipFile(str(info.file)) as zf:
for name in [
'module1.py',
'module1-0.1.dist-info/METADATA',
]:
assert zf.getinfo(name).compress_type == zipfile.ZIP_DEFLATED
# Load the config file to make sure it gets validated
read_flit_config(ini_file)
if 'sdist' in formats:
sb = SdistBuilder.from_ini_path(ini_file)
sdist_file = sb.build(dist_dir, gen_setup_py=gen_setup_py)
sdist_info = SimpleNamespace(builder=sb, file=sdist_file)
# When we're building both, build the wheel from the unpacked sdist.
# This helps ensure that the sdist contains all the necessary files.
if 'wheel' in formats:
with unpacked_tarball(sdist_file) as tmpdir:
log.debug('Building wheel from unpacked sdist %s', tmpdir)
tmp_ini_file = Path(tmpdir, ini_file.name)
wheel_info = make_wheel_in(tmp_ini_file, dist_dir)
elif 'wheel' in formats:
wheel_info = make_wheel_in(ini_file, dist_dir)
except ConfigError as e:
sys.exit('Config error: {}'.format(e))
return SimpleNamespace(wheel=wheel_info, sdist=sdist_info)
try:
# Load the config file to make sure it gets validated
read_flit_config(ini_file)
if 'sdist' in formats:
sb = SdistBuilder.from_ini_path(ini_file)
sdist_file = sb.build(dist_dir, gen_setup_py=gen_setup_py)
sdist_info = SimpleNamespace(builder=sb, file=sdist_file)
# When we're building both, build the wheel from the unpacked sdist.
# This helps ensure that the sdist contains all the necessary files.
if 'wheel' in formats:
with unpacked_tarball(sdist_file) as tmpdir:
log.debug('Building wheel from unpacked sdist %s', tmpdir)
tmp_ini_file = Path(tmpdir, ini_file.name)
wheel_info = make_wheel_in(tmp_ini_file, dist_dir)
elif 'wheel' in formats:
wheel_info = make_wheel_in(ini_file, dist_dir)
except ConfigError as e:
sys.exit('Config error: {}'.format(e))
return SimpleNamespace(wheel=wheel_info, sdist=sdist_info)