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

Refactor distribution upload code #20

Merged
merged 5 commits into from
Aug 6, 2018
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 recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: conda-forge-ci-setup
version: 1.3.5
version: 1.3.6

build:
number: 0
Expand Down
65 changes: 40 additions & 25 deletions recipe/upload_or_check_non_existence.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def built_distribution_already_exists(cli, meta, fname, owner):
return exists


def upload(cli, path, owner, channels):
with get_temp_token(cli.token) as fn:
subprocess.check_call(['anaconda', '--quiet', '-t', fn,
'upload', path,
'--user={}'.format(owner),
'--channel={}'.format(channels)],
env=os.environ)
def upload(token_fn, path, owner, channels):
subprocess.check_call(['anaconda', '--quiet', '-t', token_fn,
'upload', path,
'--user={}'.format(owner),
'--channel={}'.format(channels)],
env=os.environ)


def distribution_exists_on_channel(binstar_cli, meta, fname, owner, channel='main'):
Expand Down Expand Up @@ -108,24 +107,40 @@ def main():

cli = get_server_api(token=token)
metas = conda_build.api.render(recipe_dir, variant_config_files=args.variant_config_files)
for meta, _, _ in metas:
fnames = conda_build.api.get_output_file_paths(meta)
print("Processing {}".format(meta.name()))
if meta.skip():
print("No upload to take place - this configuration was skipped in build/skip.")
continue
for fname in fnames:
exists = built_distribution_already_exists(cli, meta, fname, owner)
if token:
if not exists:
upload(cli, fname, owner, channel)
print('Uploaded {}'.format(fname))
else:
print('Distribution {} already \nexists for {}.' .format(fname, owner))
else:
print("No BINSTAR_TOKEN present, so no upload is taking place. "
"The distribution just built {} already available for {}."
"".format('is' if exists else 'is not', owner))

# Print the skipped distributions
skipped_distributions = [ m for m, _, _ in metas if m.skip() ]
for m in skipped_distributions:
print("{} configuration was skipped in build/skip.".format(m.name()))


# The list of built/not skipped distributions
built_distributions = [(m, path)
for m, _, _ in metas
for path in conda_build.api.get_output_file_paths(m)
if not m.skip()]

# These are the ones that already exist on the owner channel's
existing_distributions = [path for m, path in built_distributions
if built_distribution_already_exists(cli, m, path, owner)]
for d in existing_distributions:
print('Distribution {} already exists for {}'.format(d, owner))


# These are the ones that are new to the owner channel's
new_distributions = [path for m, path in built_distributions
if not built_distribution_already_exists(cli, m, path, owner)]

# This is the actual fix where we create the token file once and reuse it for all uploads
if token:
with get_temp_token(cli.token) as token_fn:
for path in new_distributions:
upload(token_fn, path, owner, channel)
print('Uploaded {}'.format(path))
else:
for path in new_distributions:
print("Distribution {} is new for {}, but no upload is taking place "
"because the BINSTAR_TOKEN is missing.".format(path, owner))

if __name__ == '__main__':
main()