Change how paths are handled, using 'project is working dir' mentality

This commit is contained in:
Joe Rickerby
2020-04-09 16:19:36 +01:00
parent 95bef46832
commit 7e59d8c61c
5 changed files with 27 additions and 21 deletions
-1
View File
@@ -197,7 +197,6 @@ def main():
manylinux_images = None manylinux_images = None
build_options = BuildOptions( build_options = BuildOptions(
project_dir='.',
package_dir=package_dir, package_dir=package_dir,
output_dir=output_dir, output_dir=output_dir,
test_command=test_command, test_command=test_command,
+7 -7
View File
@@ -96,11 +96,10 @@ def build(options: BuildOptions):
('pp', 'manylinux_x86_64', options.manylinux_images['pypy_x86_64']), ('pp', 'manylinux_x86_64', options.manylinux_images['pypy_x86_64']),
] ]
abs_project_dir = os.path.abspath(options.project_dir) if not os.path.realpath(options.package_dir).startswith(os.path.realpath('.')):
abs_package_dir = os.path.abspath(options.package_dir) raise Exception('package_dir must be inside the working directory')
container_project_dir = '/project' container_package_dir = os.path.join('/project', os.path.relpath(options.package_dir, '.'))
container_package_dir = os.path.join(container_project_dir, os.path.relpath(abs_package_dir, os.path.commonprefix([abs_project_dir, abs_package_dir]))),
for implementation, platform_tag, docker_image in platforms: for implementation, platform_tag, docker_image in platforms:
platform_configs = [c for c in python_configurations if c.identifier.startswith(implementation) and c.identifier.endswith(platform_tag)] platform_configs = [c for c in python_configurations if c.identifier.startswith(implementation) and c.identifier.endswith(platform_tag)]
@@ -108,6 +107,7 @@ def build(options: BuildOptions):
continue continue
container_name = 'cibuildwheel-{}'.format(uuid.uuid4()) container_name = 'cibuildwheel-{}'.format(uuid.uuid4())
try: try:
call(['docker', 'create', call(['docker', 'create',
'--env', 'CIBUILDWHEEL', '--env', 'CIBUILDWHEEL',
@@ -244,10 +244,10 @@ def build(options: BuildOptions):
test_requires=' '.join(options.test_requires), test_requires=' '.join(options.test_requires),
test_extras=options.test_extras, test_extras=options.test_extras,
test_command=shlex.quote( test_command=shlex.quote(
prepare_command(options.test_command, project='/project') if options.test_command else '' prepare_command(options.test_command, project='/project', package=container_package_dir) if options.test_command else ''
), ),
before_build=shlex.quote( before_build=shlex.quote(
prepare_command(options.before_build, project='/project') if options.before_build else '' prepare_command(options.before_build, project='/project', package=container_package_dir) if options.before_build else ''
), ),
build_verbosity_flag=' '.join(get_build_verbosity_extra_flags(options.build_verbosity)), build_verbosity_flag=' '.join(get_build_verbosity_extra_flags(options.build_verbosity)),
repair_command=shlex.quote( repair_command=shlex.quote(
@@ -257,7 +257,7 @@ def build(options: BuildOptions):
uid=os.getuid(), uid=os.getuid(),
gid=os.getgid(), gid=os.getgid(),
before_test=shlex.quote( before_test=shlex.quote(
prepare_command(options.before_test, project='/project') if options.before_test else '' prepare_command(options.before_test, project='/project', package=container_package_dir) if options.before_test else ''
), ),
dependency_install_flags='-c /constraints.txt' if options.dependency_constraints else '', dependency_install_flags='-c /constraints.txt' if options.dependency_constraints else '',
) )
+8 -6
View File
@@ -168,8 +168,6 @@ def setup_python(python_configuration, dependency_constraint_flags, environment)
def build(options: BuildOptions): def build(options: BuildOptions):
abs_project_dir = os.path.abspath(options.project_dir)
abs_package_dir = os.path.abspath(options.package_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel') built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
@@ -187,14 +185,14 @@ def build(options: BuildOptions):
# run the before_build command # run the before_build command
if options.before_build: if options.before_build:
before_build_prepared = prepare_command(options.before_build, project=abs_project_dir, package=abs_package_dir) before_build_prepared = prepare_command(options.before_build, project='.', package=options.package_dir)
call(before_build_prepared, env=env, shell=True) call(before_build_prepared, env=env, shell=True)
# build the wheel # build the wheel
if os.path.exists(built_wheel_dir): if os.path.exists(built_wheel_dir):
shutil.rmtree(built_wheel_dir) shutil.rmtree(built_wheel_dir)
os.makedirs(built_wheel_dir) os.makedirs(built_wheel_dir)
call(['pip', 'wheel', abs_package_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env) call(['pip', 'wheel', options.package_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0] built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0]
# repair the wheel # repair the wheel
@@ -230,7 +228,7 @@ def build(options: BuildOptions):
call(['which', 'python'], env=virtualenv_env) call(['which', 'python'], env=virtualenv_env)
if options.before_test: if options.before_test:
before_test_prepared = prepare_command(options.before_test, project=abs_project_dir, package=abs_package_dir) before_test_prepared = prepare_command(options.before_test, project='.', package=options.package_dir)
call(before_test_prepared, env=virtualenv_env, shell=True) call(before_test_prepared, env=virtualenv_env, shell=True)
# install the wheel # install the wheel
@@ -243,7 +241,11 @@ def build(options: BuildOptions):
# run the tests from $HOME, with an absolute path in the command # run the tests from $HOME, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel # (this ensures that Python runs the tests against the installed wheel
# and not the repo code) # and not the repo code)
test_command_prepared = prepare_command(options.test_command, project=abs_project_dir, package=abs_package_dir) test_command_prepared = prepare_command(
options.test_command,
project=os.path.abspath('.'),
package=os.path.abspath(options.package_dir)
)
call(test_command_prepared, cwd=os.environ['HOME'], env=virtualenv_env, shell=True) call(test_command_prepared, cwd=os.environ['HOME'], env=virtualenv_env, shell=True)
# clean up # clean up
-1
View File
@@ -107,7 +107,6 @@ class DependencyConstraints:
BuildOptions = NamedTuple("BuildOptions", [ BuildOptions = NamedTuple("BuildOptions", [
("project_dir", str),
("package_dir", str), ("package_dir", str),
("output_dir", str), ("output_dir", str),
("test_command", Optional[str]), ("test_command", Optional[str]),
+12 -6
View File
@@ -143,8 +143,6 @@ def setup_python(python_configuration, dependency_constraint_flags, environment)
def build(options: BuildOptions): def build(options: BuildOptions):
abs_project_dir = os.path.abspath(options.project_dir)
abs_package_dir = os.path.abspath(options.package_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel') built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
@@ -166,14 +164,14 @@ def build(options: BuildOptions):
# run the before_build command # run the before_build command
if options.before_build: if options.before_build:
before_build_prepared = prepare_command(options.before_build, project=abs_project_dir, package=abs_package_dir) before_build_prepared = prepare_command(options.before_build, project='.', package=options.package_dir)
shell([before_build_prepared], env=env) shell([before_build_prepared], env=env)
# build the wheel # build the wheel
if os.path.exists(built_wheel_dir): if os.path.exists(built_wheel_dir):
shutil.rmtree(built_wheel_dir) shutil.rmtree(built_wheel_dir)
os.makedirs(built_wheel_dir) os.makedirs(built_wheel_dir)
shell(['pip', 'wheel', abs_package_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env) shell(['pip', 'wheel', options.package_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0] built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0]
# repair the wheel # repair the wheel
@@ -214,7 +212,11 @@ def build(options: BuildOptions):
shell(['which', 'python'], env=virtualenv_env) shell(['which', 'python'], env=virtualenv_env)
if options.before_test: if options.before_test:
before_test_prepared = prepare_command(options.before_test, project=abs_project_dir, package=abs_package_dir) before_test_prepared = prepare_command(
options.before_test,
project='.',
package=options.package_dir
)
shell([before_test_prepared], env=virtualenv_env) shell([before_test_prepared], env=virtualenv_env)
# install the wheel # install the wheel
@@ -227,7 +229,11 @@ def build(options: BuildOptions):
# run the tests from c:\, with an absolute path in the command # run the tests from c:\, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel # (this ensures that Python runs the tests against the installed wheel
# and not the repo code) # and not the repo code)
test_command_prepared = prepare_command(options.test_command, project=abs_project_dir, package=abs_package_dir) test_command_prepared = prepare_command(
options.test_command,
project=os.path.abspath('.'),
package=os.path.abspath(options.package_dir)
)
shell([test_command_prepared], cwd='c:\\', env=virtualenv_env) shell([test_command_prepared], cwd='c:\\', env=virtualenv_env)
# clean up # clean up