forked from chriskuehl/dumb-pypi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.py
37 lines (30 loc) · 1.16 KB
/
testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import os.path
import shutil
import subprocess
import sys
import tempfile
from dumb_pypi import main
def make_package(path):
"""Make a fake package at path.
Even with --download, pip insists on extracting the downloaded packages (in
order to find dependencies), so we can't just make empty files.
"""
name, version = main.guess_name_version_from_filename(os.path.basename(path))
with tempfile.TemporaryDirectory() as td:
setup_py = os.path.join(td, 'setup.py')
with open(setup_py, 'w') as f:
f.write(
'from setuptools import setup\n'
'setup(name="{}", version="{}")\n'.format(name, version),
)
args = ('sdist', '--formats=zip')
if path.endswith(('.tgz', '.tar.gz')):
args = ('sdist', '--formats=gztar')
elif path.endswith('.tar'):
args = ('sdist', '--formats=tar')
elif path.endswith('.whl'):
args = ('bdist_wheel',)
subprocess.check_call((sys.executable, setup_py) + args, cwd=td)
created, = os.listdir(os.path.join(td, 'dist'))
shutil.move(os.path.join(td, 'dist', created), path)