Skip to content

Commit

Permalink
fixed update feedstock action and misc cleanup/clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gdementen committed Apr 29, 2020
1 parent 722bf75 commit c53c486
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
17 changes: 9 additions & 8 deletions releaser/make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def update_version(build_dir, release_name, package_name, module_name, public_re
replace_lines(meta_file, changes)
changed_files.append(meta_file)

# check, commit and push
# check and commit changes
print(echocall(['git', 'status', '-s']))
print(echocall(['git', 'diff', *changed_files]))
if no('Do the version update changes look right?'):
Expand Down Expand Up @@ -264,7 +264,7 @@ def push(build_dir, public_release, branch, **extra_kwargs):
return

chdir(build_dir)
doechocall('Pushing main repository changes to upstream',
doechocall('Pushing main repository changes upstream',
['git', 'push', 'upstream', branch, '--follow-tags'])


Expand All @@ -279,6 +279,7 @@ def build_conda_packages(conda_recipe_path, build_dir, conda_build_args, **extra
# XXX: split build & upload? (--no-anaconda-upload)
cmd = ['conda', 'build']
if conda_build_args:
# transform dict to flat list
for arg_name, arg_value in conda_build_args.items():
cmd += [arg_name, arg_value]
cmd += [conda_recipe_path]
Expand Down Expand Up @@ -361,16 +362,16 @@ def set_config(local_repository, package_name, module_name, release_name, branch
return config


def run_steps(config, steps, steps_funcs):
def run_steps(config, steps_funcs, steps_filter):
func_names = [f.__name__ for f, desc in steps_funcs]
if ':' in steps:
start, stop = steps.split(':')
if ':' in steps_filter:
start, stop = steps_filter.split(':')
start = func_names.index(start) if start else 0
# + 1 so that stop bound is inclusive
stop = func_names.index(stop) + 1 if stop else len(func_names)
else:
# assuming a single step
start = func_names.index(steps)
start = func_names.index(steps_filter)
stop = start + 1

for step_func, step_desc in steps_funcs[start:stop]:
Expand All @@ -386,8 +387,8 @@ def run_steps(config, steps, steps_funcs):
print("done.")


def make_release(local_repository, package_name, module_name, release_name='dev', steps=':', branch='master',
def make_release(local_repository, package_name, module_name, release_name='dev', steps_filter=':', branch='master',
src_documentation=None, tmp_dir=None, conda_build_args=None):
config = set_config(local_repository, package_name, module_name, release_name, branch, src_documentation,
tmp_dir, conda_build_args)
run_steps(config, steps, steps_funcs)
run_steps(config, steps_funcs, steps_filter)
25 changes: 11 additions & 14 deletions releaser/update_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import urllib.request as request
from os.path import join

from releaser.utils import call, echocall, doechocall, no, replace_lines, chdir
from releaser.utils import echocall, doechocall, no, replace_lines, chdir
from releaser.make_release import create_tmp_directory, clone_repository, cleanup, run_steps


Expand All @@ -24,8 +24,8 @@ def update_version_conda_forge_package(build_dir, version, main_repository, **ex
print(f'Computing SHA256 from archive {url}', end=' ')
with request.urlopen(url) as response:
sha256 = hashlib.sha256(response.read()).hexdigest()
print('done.')
print('SHA256: ', sha256)
print('done.')
print('SHA256: ', sha256)

# set version and sha256 in meta.yml file
meta_file = r'recipe\meta.yaml'
Expand All @@ -52,9 +52,6 @@ def push_conda_forge(build_dir, branch, **extra_kwargs):
# ------------ #

steps_funcs = [
########################################
# UPDATE LARRAY PACKAGE ON CONDA-FORGE #
########################################
(create_tmp_directory, ''),
(clone_repository, ''),
(update_version_conda_forge_package, ''),
Expand All @@ -63,23 +60,23 @@ def push_conda_forge(build_dir, branch, **extra_kwargs):
]


def set_config_conda(main_repository, feedstock_repository, module_name, version, branch, tmp_dir):
def set_config_conda(upstream_repository, feedstock_repository, module_name, version, branch, tmp_dir):
if tmp_dir is None:
tmp_dir = join(r"c:\tmp" if sys.platform == "win32" else "/tmp", "{}_feedstock".format(module_name))
tmp_dir = join(r"c:\tmp" if sys.platform == "win32" else "/tmp", f"{module_name}_feedstock")

config = {
'module_name': module_name,
'branch': branch,
'version': version,
'main_repository': main_repository,
'repository': feedstock_repository,
'main_repository': upstream_repository,
'upstream_repository': feedstock_repository,
'tmp_dir': tmp_dir,
'build_dir': join(tmp_dir, 'build'),
}
return config


def update_feedstock(main_repository, feedstock_repository, module_name, release_name, steps=':', branch='master',
tmp_dir=None):
config = set_config_conda(main_repository, feedstock_repository, module_name, release_name, branch, tmp_dir)
run_steps(config, steps, steps_funcs)
def update_feedstock(upstream_repository, feedstock_repository, module_name, release_name, steps_filter=':',
branch='master', tmp_dir=None):
config = set_config_conda(upstream_repository, feedstock_repository, module_name, release_name, branch, tmp_dir)
run_steps(config, steps_funcs, steps_filter)
24 changes: 19 additions & 5 deletions releaser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ def chdir(path):
os.chdir(path)


def force_decode(s):
def force_decode(s, encodings=('utf8', 'cp1252')):
if isinstance(s, str):
return s
assert isinstance(s, bytes)
encodings = ['utf8', 'cp1252']
for encoding in encodings:
try:
return s.decode(encoding)
Expand Down Expand Up @@ -254,6 +253,8 @@ def replace_lines(fpath, changes, end="\n"):
"""
Parameters
----------
fpath : str
Path to the file to modify.
changes : list of pairs
List of pairs (substring_to_find, new_line).
"""
Expand All @@ -272,9 +273,9 @@ def git_remote_last_rev(repository, branch='master'):
Parameters
----------
repository : str
name or url of the remote repository
Name or url of the remote repository
branch : str, optional
branch. Defaults to 'refs/heads/master'.
Branch. Defaults to 'master'.
Returns
-------
Expand All @@ -289,7 +290,20 @@ def git_remote_last_rev(repository, branch='master'):
raise Exception("Could not determine revision number")


def git_remote_url(remote_name):
def git_remote_url(remote_name='origin'):
"""
Return URL of a git remote
Parameters
----------
remote_name : str, optional
Name of remote. Defaults to 'origin'.
Returns
-------
str
URL of remote
"""
output_lines = call(['git', 'remote', 'get-url', remote_name]).splitlines()
assert len(output_lines) == 1
return output_lines[0]

0 comments on commit c53c486

Please sign in to comment.