Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_build_sdist_only(copy_sample):
td = copy_sample('module1_toml')
(td / '.git').mkdir() # Fake a git repo
with MockCommand('git', LIST_FILES_TEMPLATE.format(
python=sys.executable, module='module1.py')):
res = build.main(td / 'pyproject.toml', formats={'sdist'})
assert res.wheel is None
# Compare str path to work around pathlib/pathlib2 mismatch on Py 3.5
assert [str(p) for p in (td / 'dist').iterdir()] == [str(res.sdist.file)]
def test_build_main(copy_sample):
td = copy_sample('module1_toml')
(td / '.git').mkdir() # Fake a git repo
with MockCommand('git', LIST_FILES_TEMPLATE.format(
python=sys.executable, module='module1.py')):
res = build.main(td / 'pyproject.toml')
assert res.wheel.file.suffix == '.whl'
assert res.sdist.file.name.endswith('.tar.gz')
assert_isdir(td / 'dist')
def test_build_wheel_only(copy_sample):
td = copy_sample('module1_toml')
(td / '.git').mkdir() # Fake a git repo
with MockCommand('git', LIST_FILES_TEMPLATE.format(
python=sys.executable, module='module1.py')):
res = build.main(td / 'pyproject.toml', formats={'wheel'})
assert res.sdist is None
# Compare str path to work around pathlib/pathlib2 mismatch on Py 3.5
assert [str(p) for p in (td / 'dist').iterdir()] == [str(res.wheel.file)]
def test_build_module_no_docstring():
with TemporaryDirectory() as td:
pyproject = Path(td, 'pyproject.toml')
shutil.copy(str(samples_dir / 'no_docstring-pkg.toml'), str(pyproject))
shutil.copy(str(samples_dir / 'no_docstring.py'), td)
shutil.copy(str(samples_dir / 'EG_README.rst'), td)
Path(td, '.git').mkdir() # Fake a git repo
with MockCommand('git', LIST_FILES_TEMPLATE.format(
python=sys.executable, module='no_docstring.py')):
with pytest.raises(common.NoDocstringError) as exc_info:
build.main(pyproject)
assert 'no_docstring.py' in str(exc_info.value)
sys.exit('Neither pyproject.toml nor flit.ini found, '
'and no other config file path specified')
enable_colourful_output(logging.DEBUG if args.debug else logging.INFO)
log.debug("Parsed arguments %r", args)
if args.logo:
from .logo import clogo
print(clogo.format(version=__version__))
sys.exit(0)
if args.subcmd == 'build':
from .build import main
try:
main(args.ini_file, formats=set(args.format or []),
gen_setup_py=args.setup_py)
except(common.NoDocstringError, common.VCSError, common.NoVersionError) as e:
sys.exit(e.args[0])
elif args.subcmd == 'publish':
if args.deprecated_repository:
log.warning("Passing --repository before the 'upload' subcommand is deprecated: pass it after")
repository = args.repository or args.deprecated_repository
from .upload import main
main(args.ini_file, repository, formats=set(args.format or []),
gen_setup_py=args.setup_py)
elif args.subcmd == 'install':
from .install import Installer
try:
python = find_python_executable(args.python)
Installer.from_ini_path(args.ini_file, user=args.user, python=python,
print(clogo.format(version=__version__))
sys.exit(0)
if args.subcmd == 'build':
from .build import main
try:
main(args.ini_file, formats=set(args.format or []),
gen_setup_py=args.setup_py)
except(common.NoDocstringError, common.VCSError, common.NoVersionError) as e:
sys.exit(e.args[0])
elif args.subcmd == 'publish':
if args.deprecated_repository:
log.warning("Passing --repository before the 'upload' subcommand is deprecated: pass it after")
repository = args.repository or args.deprecated_repository
from .upload import main
main(args.ini_file, repository, formats=set(args.format or []),
gen_setup_py=args.setup_py)
elif args.subcmd == 'install':
from .install import Installer
try:
python = find_python_executable(args.python)
Installer.from_ini_path(args.ini_file, user=args.user, python=python,
symlink=args.symlink, deps=args.deps, extras=args.extras,
pth=args.pth_file).install()
except (ConfigError, PythonNotFoundError, common.NoDocstringError, common.NoVersionError) as e:
sys.exit(e.args[0])
elif args.subcmd == 'init':
from .init import TerminalIniter
TerminalIniter().initialise()
else:
def main(ini_path, repo_name, formats=None, gen_setup_py=True):
"""Build and upload wheel and sdist."""
from . import build
built = build.main(ini_path, formats=formats, gen_setup_py=gen_setup_py)
if built.wheel is not None:
do_upload(built.wheel.file, built.wheel.builder.metadata, repo_name)
if built.sdist is not None:
do_upload(built.sdist.file, built.sdist.builder.metadata, repo_name)