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

Capture upload_only_when_stable from kwargs #25

Merged
merged 4 commits into from
Aug 2, 2019
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
2 changes: 1 addition & 1 deletion bincrafters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '0.18.2'
__version__ = '0.18.3'
113 changes: 66 additions & 47 deletions bincrafters/build_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ def get_version(recipe=None):
return ci_ver if ci_ver else get_version_from_recipe(recipe=recipe)


def get_conan_vars(recipe=None):
username = os.getenv("CONAN_USERNAME", get_username_from_ci() or "bincrafters")
channel = os.getenv("CONAN_CHANNEL", get_channel_from_ci())
def get_conan_vars(recipe=None, kwargs={}):
username = kwargs.get("username", os.getenv("CONAN_USERNAME", get_username_from_ci() or "bincrafters"))
kwargs["channel"] = kwargs.get("channel", os.getenv("CONAN_CHANNEL", get_channel_from_ci()))
version = os.getenv("CONAN_VERSION", get_version(recipe=recipe))
login_username = os.getenv("CONAN_LOGIN_USERNAME", username)
return username, channel, version, login_username
kwargs["login_username"] = kwargs.get("login_username", os.getenv("CONAN_LOGIN_USERNAME", username))
kwargs["username"] = username

return username, version, kwargs


def get_user_repository(username, repository_name):
Expand All @@ -137,67 +139,84 @@ def get_conan_upload(username):
return get_user_repository(username, repository_name)


def get_conan_remotes(username):
remotes = os.getenv("CONAN_REMOTES")
if remotes:
remotes = remotes.split(',')
for remote in reversed(remotes):
if '@' in remote:
remote = RemotesManager._get_remote_from_str(remote, var_name=remote)
return remotes
def get_conan_upload_param(username, kwargs):
if "upload" not in kwargs:
kwargs["upload"] = get_conan_upload(username)
return kwargs


# While redundant, this moves upload remote to position 0.
remotes = [get_conan_upload(username)]
# Add bincrafters repository for other users, e.g. if the package would
# require other packages from the bincrafters repo.
bincrafters_user = "bincrafters"
if username != bincrafters_user:
remotes.append(get_conan_upload(bincrafters_user))
def get_conan_remotes(username, kwargs):
remotes = None
if "remotes" not in kwargs:
remotes = os.getenv("CONAN_REMOTES")
if remotes:
remotes = remotes.split(',')
for remote in reversed(remotes):
if '@' in remote:
remote = RemotesManager._get_remote_from_str(remote, var_name=remote)
else:
# While redundant, this moves upload remote to position 0.
remotes = [get_conan_upload(username)]
# Add bincrafters repository for other users, e.g. if the package would
# require other packages from the bincrafters repo.
bincrafters_user = "bincrafters"
if username != bincrafters_user:
remotes.append(get_conan_upload(bincrafters_user))

# Force Bincrafters repo on remotes
if BINCRAFTERS_REPO_URL not in remotes:
remotes.append(BINCRAFTERS_REPO_URL)
# Force Bincrafters repo on remotes
if BINCRAFTERS_REPO_URL not in remotes:
remotes.append(BINCRAFTERS_REPO_URL)

return remotes
kwargs["remotes"] = remotes
return kwargs


def get_upload_when_stable():
return get_bool_from_env("CONAN_UPLOAD_ONLY_WHEN_STABLE")
def get_upload_when_stable(kwargs):
upload_when_stable = kwargs.get('upload_only_when_stable')
if upload_when_stable is None:
kwargs['upload_only_when_stable'] = get_bool_from_env("CONAN_UPLOAD_ONLY_WHEN_STABLE")
uilianries marked this conversation as resolved.
Show resolved Hide resolved
return kwargs


def get_os():
return platform.system().replace("Darwin", "Macos")


def get_archs():
archs = os.getenv("CONAN_ARCHS", None)
if get_os() == "Macos" and archs is None:
return ["x86_64"]
return split_colon_env("CONAN_ARCHS") if archs else None
def get_archs(kwargs):
if "archs" not in kwargs:
archs = os.getenv("CONAN_ARCHS", None)
if get_os() == "Macos" and archs is None:
kwargs["archs"] = ["x86_64"]
else:
kwargs["archs"] = split_colon_env("CONAN_ARCHS") if archs else None
return kwargs


def get_stable_branch_pattern(kwargs):
if "stable_branch_pattern" not in kwargs:
kwargs["stable_branch_pattern"] = os.getenv("CONAN_STABLE_BRANCH_PATTERN", "stable/*")
return kwargs


def get_reference(name, version, kwargs):
if "reference" not in kwargs:
kwargs["reference"] = "{0}/{1}".format(name, version)
return kwargs


def get_builder(build_policy=None, cwd=None, **kwargs):
recipe = get_recipe_path(cwd)
name = get_name_from_recipe(recipe=recipe)
username, channel, version, login_username = get_conan_vars(recipe=recipe)
reference = "{0}/{1}".format(name, version)
upload = get_conan_upload(username)
remotes = get_conan_remotes(username)
upload_when_stable = get_upload_when_stable()
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", "stable/*")
archs = get_archs()
username, version, kwargs = get_conan_vars(recipe=recipe, kwargs=kwargs)
kwargs = get_reference(name, version, kwargs)
kwargs = get_conan_upload_param(username, kwargs)
kwargs = get_conan_remotes(username, kwargs)
kwargs = get_upload_when_stable(kwargs)
kwargs = get_stable_branch_pattern(kwargs)
kwargs = get_archs(kwargs)
build_policy = os.getenv('CONAN_BUILD_POLICY', build_policy)
builder = ConanMultiPackager(
username=username,
login_username=login_username,
channel=channel,
reference=reference,
upload=upload,
remotes=remotes,
archs=archs,
build_policy=build_policy,
upload_only_when_stable=upload_when_stable,
stable_branch_pattern=stable_branch_pattern,
cwd=cwd,
**kwargs)

Expand Down
3 changes: 2 additions & 1 deletion bincrafters/build_template_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def get_builder(shared_option_name=None,
dll_with_static_runtime=False,
build_policy=None,
cwd=None,
reference=None,
**kwargs):
recipe = build_shared.get_recipe_path(cwd)

Expand All @@ -19,6 +20,6 @@ def get_builder(shared_option_name=None,
shared_option_name=shared_option_name,
pure_c=pure_c,
dll_with_static_runtime=dll_with_static_runtime,
**kwargs)
reference=reference)

return builder
2 changes: 1 addition & 1 deletion bincrafters/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
conan_package_tools>=0.25.1
conan_package_tools>=0.29.1
9 changes: 7 additions & 2 deletions tests/test_package_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ def test_upload_only_when_stable_builder(set_upload_when_stable_false):
assert False == builder.upload_only_when_stable


def test_upload_only_when_stable_parameter(set_upload_when_stable_false):
builder = build_template_default.get_builder(upload_only_when_stable=True)
assert True == builder.upload_only_when_stable


def test_upload_only_when_stable_header_only(set_upload_when_stable_false):
builder = build_template_header_only.get_builder()
assert False == builder.upload_only_when_stable
Expand All @@ -211,7 +216,7 @@ def test_format_multi_remotes(set_multi_remote_address):
builder = build_template_default.get_builder()
assert 2 == len(builder.remotes_manager._remotes)
remote = builder.remotes_manager._remotes[0]
assert "remote0" == remote.name
assert "remotefoo" == remote.name
assert "https://api.bintray.com/conan/foo/bar" == remote.url
assert remote.use_ssl
remote = builder.remotes_manager._remotes[1]
Expand Down Expand Up @@ -240,5 +245,5 @@ def test_default_remote_address(set_upload_address):
assert "remotefoo" == remote.name
assert "https://api.bintray.com/conan/foo/bar" == remote.url
remote = builder.remotes_manager._remotes[1]
assert "remote1" == remote.name
assert "upload_repo" == remote.name
assert "https://api.bintray.com/conan/bincrafters/public-conan" == remote.url