Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide package_dir for setting subdirectory of project #295

Merged
merged 4 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def main():
parser.add_argument('--output-dir',
default=os.environ.get('CIBW_OUTPUT_DIR', 'wheelhouse'),
help='Destination folder for the wheels.')
parser.add_argument('project_dir',
parser.add_argument('package_dir',
default='.',
nargs='?',
help=('Path to the project that you want wheels for. Default: the current '
help=('Path to the package that you want wheels for. Default: the current '
'directory.'))

parser.add_argument('--print-build-identifiers',
Expand Down Expand Up @@ -104,7 +104,7 @@ def main():
test_command = get_option_from_environment('CIBW_TEST_COMMAND', platform=platform)
test_requires = get_option_from_environment('CIBW_TEST_REQUIRES', platform=platform, default='').split()
test_extras = get_option_from_environment('CIBW_TEST_EXTRAS', platform=platform, default='')
project_dir = args.project_dir
package_dir = args.package_dir
before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform)
build_verbosity = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='')
build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '')
Expand Down Expand Up @@ -147,8 +147,8 @@ def main():
# This needs to be passed on to the docker container in linux.py
os.environ['CIBUILDWHEEL'] = '1'

if not os.path.exists(os.path.join(project_dir, 'setup.py')):
print('cibuildwheel: Could not find setup.py at root of project', file=sys.stderr)
if not os.path.exists(os.path.join(package_dir, 'setup.py')):
print('cibuildwheel: Could not find setup.py at root of package', file=sys.stderr)
exit(2)

if args.print_build_identifiers:
Expand Down Expand Up @@ -189,7 +189,8 @@ def main():
manylinux_images = None

build_options = BuildOptions(
project_dir=project_dir,
project_dir='.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about calling os.getcwd() here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even better: killing the project_dir parameter, and just calling os.getcwd() in linux.py/macos.py/windows.py ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left project_dir because it still allows a bit advanced configuration if needed. But I can update it to os.getcwd().

package_dir=package_dir,
output_dir=output_dir,
test_command=test_command,
test_requires=test_requires,
Expand All @@ -201,8 +202,7 @@ def main():
environment=environment,
before_test=before_test,
dependency_constraints=dependency_constraints,
manylinux_images=manylinux_images

manylinux_images=manylinux_images,
)

# Python is buffering by default when running on the CI platforms, giving problems interleaving subprocess call output with unflushed calls to 'print'
Expand Down
9 changes: 8 additions & 1 deletion cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def build(options: BuildOptions):
('pp', 'manylinux_x86_64', options.manylinux_images['pypy_x86_64']),
]

abs_project_dir = os.path.abspath(options.project_dir)
abs_package_dir = os.path.abspath(options.package_dir)

container_project_dir = '/project'
container_package_dir = os.path.join(container_project_dir, os.path.relpath(abs_package_dir, os.path.commonprefix([abs_project_dir, abs_package_dir]))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would container_package_dir = os.path.join('/project', package_dir) do the same here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it should be possible to pass package_dir to the docker container directly, without any path operations in Python, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if package_dir was passed as absolute path, I guess? Or, in that case we'd need to specify it needs to be a relative path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, good point. Then the relpath step would still be needed, but it could be left relative to the working dir and used like that inside the container.


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)]
if not platform_configs:
Expand Down Expand Up @@ -165,7 +171,7 @@ def build(options: BuildOptions):
# Build the wheel
rm -rf /tmp/built_wheel
mkdir /tmp/built_wheel
pip wheel . -w /tmp/built_wheel --no-deps {build_verbosity_flag}
pip wheel {package_dir} -w /tmp/built_wheel --no-deps {build_verbosity_flag}
built_wheel=(/tmp/built_wheel/*.whl)

# repair the wheel
Expand Down Expand Up @@ -234,6 +240,7 @@ def build(options: BuildOptions):
done
'''.format(
config_python_bin=config.path + '/bin',
package_dir=container_package_dir,
test_requires=' '.join(options.test_requires),
test_extras=options.test_extras,
test_command=shlex.quote(
Expand Down
11 changes: 6 additions & 5 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def setup_python(python_configuration, dependency_constraint_flags, environment)

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')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
Expand All @@ -181,19 +182,19 @@ def build(options: BuildOptions):
dependency_constraint_flags = [
'-c', options.dependency_constraints.get_for_python_version(config.version)
]

env = setup_python(config, dependency_constraint_flags, options.environment)

# run the before_build command
if options.before_build:
before_build_prepared = prepare_command(options.before_build, project=abs_project_dir)
before_build_prepared = prepare_command(options.before_build, project=abs_project_dir, package=abs_package_dir)
call(before_build_prepared, env=env, shell=True)

# build the wheel
if os.path.exists(built_wheel_dir):
shutil.rmtree(built_wheel_dir)
os.makedirs(built_wheel_dir)
call(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
call(['pip', 'wheel', abs_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]

# repair the wheel
Expand Down Expand Up @@ -229,7 +230,7 @@ def build(options: BuildOptions):
call(['which', 'python'], env=virtualenv_env)

if options.before_test:
before_test_prepared = prepare_command(options.before_test, project=abs_project_dir)
before_test_prepared = prepare_command(options.before_test, project=abs_project_dir, package=abs_package_dir)
call(before_test_prepared, env=virtualenv_env, shell=True)

# install the wheel
Expand All @@ -242,7 +243,7 @@ def build(options: BuildOptions):
# run the tests from $HOME, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel
# and not the repo code)
test_command_prepared = prepare_command(options.test_command, project=abs_project_dir)
test_command_prepared = prepare_command(options.test_command, project=abs_project_dir, package=abs_package_dir)
call(test_command_prepared, cwd=os.environ['HOME'], env=virtualenv_env, shell=True)

# clean up
Expand Down
2 changes: 1 addition & 1 deletion cibuildwheel/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import urllib.request
from fnmatch import fnmatch
from time import sleep
Expand Down Expand Up @@ -109,6 +108,7 @@ def get_for_python_version(self, version):

BuildOptions = NamedTuple("BuildOptions", [
("project_dir", str),
("package_dir", str),
("output_dir", str),
("test_command", Optional[str]),
("test_requires", List[str]),
Expand Down
9 changes: 5 additions & 4 deletions cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def setup_python(python_configuration, dependency_constraint_flags, environment)

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')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
Expand All @@ -165,14 +166,14 @@ def build(options: BuildOptions):

# run the before_build command
if options.before_build:
before_build_prepared = prepare_command(options.before_build, project=abs_project_dir)
before_build_prepared = prepare_command(options.before_build, project=abs_project_dir, package=abs_package_dir)
shell([before_build_prepared], env=env)

# build the wheel
if os.path.exists(built_wheel_dir):
shutil.rmtree(built_wheel_dir)
os.makedirs(built_wheel_dir)
shell(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
shell(['pip', 'wheel', abs_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]

# repair the wheel
Expand Down Expand Up @@ -213,7 +214,7 @@ def build(options: BuildOptions):
shell(['which', 'python'], env=virtualenv_env)

if options.before_test:
before_test_prepared = prepare_command(options.before_test, project=abs_project_dir)
before_test_prepared = prepare_command(options.before_test, project=abs_project_dir, package=abs_package_dir)
shell([before_test_prepared], env=virtualenv_env)

# install the wheel
Expand All @@ -226,7 +227,7 @@ def build(options: BuildOptions):
# run the tests from c:\, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel
# and not the repo code)
test_command_prepared = prepare_command(options.test_command, project=abs_project_dir)
test_command_prepared = prepare_command(options.test_command, project=abs_project_dir, package=abs_package_dir)
shell([test_command_prepared], cwd='c:\\', env=virtualenv_env)

# clean up
Expand Down
4 changes: 2 additions & 2 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ usage: cibuildwheel [-h] [--platform {auto,linux,macos,windows}]
Build wheels for all the platforms.

positional arguments:
project_dir Path to the project that you want wheels for.
Default: the current directory.
package_dir Path to the package that you want wheels for. Default:
the current directory.

optional arguments:
-h, --help show this help message and exit
Expand Down
8 changes: 4 additions & 4 deletions unit_test/main_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __call__(self, *args, **kwargs):
self.kwargs = kwargs


MOCK_PROJECT_DIR = 'some_project_dir'
MOCK_PACKAGE_DIR = 'some_package_dir'


@pytest.fixture(autouse=True)
Expand All @@ -39,20 +39,20 @@ def fail_on_call(*args, **kwargs):


@pytest.fixture(autouse=True)
def fake_project_dir(monkeypatch):
def fake_package_dir(monkeypatch):
'''
Monkey-patch enough for the main() function to run
'''
real_os_path_exists = os.path.exists

def mock_os_path_exists(path):
if path == os.path.join(MOCK_PROJECT_DIR, 'setup.py'):
if path == os.path.join(MOCK_PACKAGE_DIR, 'setup.py'):
return True
else:
return real_os_path_exists(path)

monkeypatch.setattr(os.path, 'exists', mock_os_path_exists)
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', MOCK_PROJECT_DIR])
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', MOCK_PACKAGE_DIR])


@pytest.fixture(params=['linux', 'macos', 'windows'])
Expand Down
6 changes: 3 additions & 3 deletions unit_test/main_tests/main_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cibuildwheel.__main__ import main

from conftest import MOCK_PROJECT_DIR # noqa: I100
from conftest import MOCK_PACKAGE_DIR # noqa: I100


def test_unknown_platform_non_ci(monkeypatch, capsys):
Expand Down Expand Up @@ -51,10 +51,10 @@ def test_platform_argument(platform, intercepted_build_args, monkeypatch):

main()

assert intercepted_build_args.args[0].project_dir == MOCK_PROJECT_DIR
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR


def test_platform_environment(platform, intercepted_build_args, monkeypatch):
main()

assert intercepted_build_args.args[0].project_dir == MOCK_PROJECT_DIR
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR