-
Notifications
You must be signed in to change notification settings - Fork 169
/
Tiltfile
70 lines (61 loc) · 2.99 KB
/
Tiltfile
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
EXT_PATH = os.getcwd()
PYPI_PORT_VAR_NAME = 'PYPISERVER_PORT' # docker compose purposes
DEFAULT_PYPI_PORT_VALUE = '8222'
DEFAULT_PYPI_CONTAINER_NAME = 'tilt-pypiserver'
PYPI_CONTAINER_VAR_NAME = 'PYPI_CONTAINER_NAME' # docker compose purpose
PYPISERVER_DATA_CACHE_DIR_VAR_NAME = 'PYPISERVER_PACKAGES_DATA_CACHE' # docker compose purposes
PYPISERVER_DATA_CACHE_DIR = 'pypiserver'
PYTHON_CMD = 'python3'
# Find the directory where Tilt loaded modules.
# This is usually the XDG data directory for tilt data.
def _find_tilt_modules_load_dir():
current = os.path.abspath('./')
while True:
if os.path.exists(os.path.join(current, 'tilt_modules')):
return current
next_dir = os.path.dirname(current)
if next_dir == current:
fail('Could not find root Tiltfile')
current = next_dir
def _find_cache_dir():
from_env = os.getenv('TILT_PYPISERVER_CACHE_DIR', '')
if from_env != '':
return from_env
return os.path.join(_find_tilt_modules_load_dir(), PYPISERVER_DATA_CACHE_DIR)
# this is the root directory into which remote state will be downloaded
# use `os.putenv('TILT_PYPISERVER_CACHE_DIR', new_dir)` to change
_pypiserver_cache_dir = _find_cache_dir()
def run_pypiserver_container():
if str(local([PYTHON_CMD, '%s/src/is_port_used.py' % EXT_PATH, DEFAULT_PYPI_PORT_VALUE], quiet=True, echo_off=True)).rstrip('\n') == 'false':
port = DEFAULT_PYPI_PORT_VALUE
else:
port = str(local([PYTHON_CMD, '%s/src/find_free_port.py' % EXT_PATH], quiet=True, echo_off=True)).rstrip('\n')
os.putenv(PYPI_PORT_VAR_NAME, port)
packages_dir = os.path.join(_pypiserver_cache_dir, 'packages')
if not os.path.exists(packages_dir):
local('mkdir -p %s' % shlex.quote(packages_dir), echo_off=True)
os.putenv(PYPI_CONTAINER_VAR_NAME, DEFAULT_PYPI_CONTAINER_NAME)
os.putenv(PYPISERVER_DATA_CACHE_DIR_VAR_NAME, packages_dir)
docker_compose(os.path.join(EXT_PATH, './compose.yaml'))
return 'http://localhost:%s' % port
def build_package(path, name=None, upload=True, labels=None):
packages_dir = os.path.join(_pypiserver_cache_dir, 'python_packages')
package_name = str(local([PYTHON_CMD, 'setup.py', '--name'], dir=path, quiet=True, echo_off=True)).rstrip('\n')
package_fullname = str(local([PYTHON_CMD, 'setup.py', '--fullname'], dir=path, quiet=True, echo_off=True)).rstrip('\n')
#cmd = [PYTHON_CMD, 'setup.py', 'sdist', '--dist-dir=%s' % packages_dir]
cmd = ['bash', '%s/src/build.sh' % EXT_PATH, packages_dir]
if upload:
#cmd.extend(['upload', '-r', 'http://localhost:%s' % os.getenv(PYPI_PORT_VAR_NAME)])
cmd.append('http://localhost:%s' % os.getenv(PYPI_PORT_VAR_NAME))
local_resource(
labels=labels or [],
name='%s-package' % package_name,
cmd=cmd,
deps=[path],
ignore=[
os.path.join(path, package_fullname),
os.path.join(path, '*egg-info')
],
dir=path,
resource_deps=['pypiserver'] if upload else []
)