From 37a15b6cae35d17c06542cda63d2d0f6358fcf74 Mon Sep 17 00:00:00 2001 From: Rodrigo Luger Date: Wed, 19 May 2021 10:09:59 -0400 Subject: [PATCH 1/3] use scm version --- .gitignore | 3 +++ pyproject.toml | 24 +++++++++++++++++++ setup.cfg | 6 +++++ setup.py | 65 +++++++------------------------------------------- 4 files changed, 42 insertions(+), 56 deletions(-) create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index b6e4761..ab7eede 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# SCM version +multiplanet/multiplanet_version.py \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b7b8828 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "multiplanet/multiplanet_version.py" +write_to_template = '__version__ = "{version}"' + +[tool.black] +line-length = 79 +exclude = ''' +/( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ea4515e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,6 @@ +[options] +setup_requires = + setuptools_scm + +[metadata] +license_files = LICENSE diff --git a/setup.py b/setup.py index ed3fa80..4203c87 100644 --- a/setup.py +++ b/setup.py @@ -1,78 +1,31 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- - -from __future__ import absolute_import, division, print_function, unicode_literals -import warnings +from setuptools import setup import os -import io -import re - -try: - from setuptools import setup - from setuptools.command.install import install - - setup -except ImportError: - from distutils.core import setup - - setup - -# Get the long description from the README -def readme(): - with open("README.md") as f: - return f.read() - - -# Read, version funcs taken from: -# https://github.com/ellisonbg/altair/blob/master/setup.py -def read(path, encoding="utf-8"): - path = os.path.join(os.path.dirname(__file__), path) - with io.open(path, encoding=encoding) as fp: - return fp.read() - -def version(path): - """ - Obtain the packge version from a python file e.g. pkg/__init__.py - See . - """ - version_file = read(path) - version_match = re.search( - r"""^__version__ = ['"]([^'"]*)['"]""", version_file, re.M - ) - if version_match: - return version_match.group(1) - raise RuntimeError("Unable to find version string.") - - -VERSION = version("multiplanet/__init__.py") # Setup! setup( name="multiplanet", - version=VERSION, description="VPLANET parameter sweep helper", - long_description=readme(), + long_description=open("README.md", "r").read(), long_description_content_type="text/markdown", - classifiers=[ - "Development Status :: 3 - Alpha", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Topic :: Scientific/Engineering :: Astronomy", - ], url="https://github.com/VirtualPlanetaryLaboratory/multi-planet", author="Caitlyn Wilhelm", author_email="cwilhelm@uw.edu", license="MIT", packages=["multiplanet"], + include_package_data=True, + use_scm_version={ + "write_to": os.path.join("multiplanet", "multiplanet_version.py"), + "write_to_template": '__version__ = "{version}"\n', + }, + install_requires=["numpy", "h5py", "argparse", "pandas", "scipy"], entry_points={ "console_scripts": [ "multi-planet = multiplanet.multiplanet:Arguments", "mpstatus = multiplanet.mpstatus:main", ], }, - install_requires=["numpy", "h5py", "argparse", "pandas", "scipy"], - include_package_data=True, + setup_requires=["setuptools_scm"], zip_safe=False, ) From 01a2cae49b90338e0ff4e3159f41d59cfbfbfc0a Mon Sep 17 00:00:00 2001 From: Rodrigo Luger Date: Wed, 19 May 2021 10:15:55 -0400 Subject: [PATCH 2/3] bugfix --- multiplanet/multiplanet.py | 201 +++++++++++++++++++++++++------------ 1 file changed, 137 insertions(+), 64 deletions(-) diff --git a/multiplanet/multiplanet.py b/multiplanet/multiplanet.py index f5b8f57..1b87d3a 100644 --- a/multiplanet/multiplanet.py +++ b/multiplanet/multiplanet.py @@ -11,107 +11,140 @@ # -------------------------------------------------------------------- ## parallel implementation of running vplanet over a directory ## -def parallel_run_planet(input_file, cores, quiet, bigplanet,email): +def parallel_run_planet(input_file, cores, quiet, bigplanet, email): # gets the folder name with all the sims folder_name, infiles = GetDir(input_file) - #gets the list of sims + # gets the list of sims sims = GetSims(folder_name) - #initalizes the checkpoint file - checkpoint_file = os.getcwd() + '/' + '.' + folder_name + # initalizes the checkpoint file + checkpoint_file = os.getcwd() + "/" + "." + folder_name - #checks if the files doesn't exist and if so then it creates it + # checks if the files doesn't exist and if so then it creates it if os.path.isfile(checkpoint_file) == False: - CreateCP(checkpoint_file,input_file,quiet,sims) + CreateCP(checkpoint_file, input_file, quiet, sims) - #if it does exist, it checks for any 0's (sims that didn't complete) and - #changes them to -1 to be re-ran + # if it does exist, it checks for any 0's (sims that didn't complete) and + # changes them to -1 to be re-ran else: - ReCreateCP(checkpoint_file,input_file,quiet,sims) + ReCreateCP(checkpoint_file, input_file, quiet, sims) # Get the SNames (sName and sSystemName) for the simuations # Save the name of the log file system_name, body_list = GetSNames(infiles, sims) logfile = system_name + ".log" - lock = mp.Lock() workers = [] - master_hdf5_file = folder_name + '.bpl' - with h5py.File(master_hdf5_file, 'w') as Master: + master_hdf5_file = folder_name + ".bpl" + with h5py.File(master_hdf5_file, "w") as Master: for i in range(cores): - workers.append(mp.Process(target=par_worker, - args=(checkpoint_file, system_name, body_list, logfile, infiles, quiet, lock, bigplanet, master_hdf5_file))) + workers.append( + mp.Process( + target=par_worker, + args=( + checkpoint_file, + system_name, + body_list, + logfile, + infiles, + quiet, + lock, + bigplanet, + master_hdf5_file, + ), + ) + ) for w in workers: w.start() for w in workers: w.join() if bigplanet == False: - sub.run(['rm', master_hdf5_file]) + sub.run(["rm", master_hdf5_file]) if email is not None: SendMail(email, folder_name) -def SendMail(email,destfolder): + +def SendMail(email, destfolder): Title = "Multi-Planet has finished for " + destfolder Body = "Please log into your computer to verify the results. This is an auto-generated message." - message = "echo " + Body + " | " + 'mail -s ' + '"'+ Title + '" ' + email - sub.Popen(message , shell=True) + message = "echo " + Body + " | " + "mail -s " + '"' + Title + '" ' + email + sub.Popen(message, shell=True) + def GetDir(input_file): """ Give it input file and returns name of folder where simulations are located. """ infiles = [] # gets the folder name with all the sims - with open(input_file, 'r') as vpl: + with open(input_file, "r") as vpl: content = [line.strip().split() for line in vpl.readlines()] for line in content: if line: - if line[0] == 'destfolder': + if line[0] == "destfolder": folder_name = line[1] - if line[0] == 'file': + if line[0] == "file": infiles.append(line[1]) if folder_name is None: - print("Name of destination folder not provided in file '%s'." - "Use syntax 'destfolder '"%inputf) - + print( + "Name of destination folder not provided in file '%s'." + "Use syntax 'destfolder '" % inputf + ) if os.path.isdir(folder_name) == False: - print("ERROR: Folder", folder_name, "does not exist in the current directory.") + print( + "ERROR: Folder", + folder_name, + "does not exist in the current directory.", + ) exit() return folder_name, infiles -def CreateCP(checkpoint_file,input_file,quiet,sims): - with open(checkpoint_file,'w') as cp: - cp.write('Vspace File: ' + os.getcwd() + '/' + input_file + '\n') - cp.write('Total Number of Simulations: '+ str(len(sims)) + '\n') + +def CreateCP(checkpoint_file, input_file, quiet, sims): + with open(checkpoint_file, "w") as cp: + cp.write("Vspace File: " + os.getcwd() + "/" + input_file + "\n") + cp.write("Total Number of Simulations: " + str(len(sims)) + "\n") for f in range(len(sims)): cp.write(sims[f] + " " + "-1 \n") - cp.write('THE END \n') + cp.write("THE END \n") -def ReCreateCP(checkpoint_file,input_file,quiet,sims): + +def ReCreateCP(checkpoint_file, input_file, quiet, sims): if quiet == False: - print('WARNING: multi-planet checkpoint file already exists!') - print('Checking if checkpoint file is corrupt...') + print("WARNING: multi-planet checkpoint file already exists!") + print("Checking if checkpoint file is corrupt...") datalist = [] - with open(checkpoint_file, 'r') as f: + with open(checkpoint_file, "r") as f: for newline in f: datalist.append(newline.strip().split()) for l in datalist: - if l[1] == '0': - l[1] = '-1' + if l[1] == "0": + l[1] = "-1" - with open(checkpoint_file, 'w') as f: + with open(checkpoint_file, "w") as f: for newline in datalist: - f.writelines(' '.join(newline)+'\n') + f.writelines(" ".join(newline) + "\n") + ## parallel worker to run vplanet ## -def par_worker(checkpoint_file,system_name, body_list, log_file, in_files, quiet, lock,bigplanet, h5_file): +def par_worker( + checkpoint_file, + system_name, + body_list, + log_file, + in_files, + quiet, + lock, + bigplanet, + h5_file, +): while True: @@ -120,33 +153,39 @@ def par_worker(checkpoint_file,system_name, body_list, log_file, in_files, quiet if bigplanet == True: data = {} - with open(checkpoint_file, 'r') as f: + with open(checkpoint_file, "r") as f: for newline in f: datalist.append(newline.strip().split()) - folder = '' + folder = "" for l in datalist: - if l[1] == '-1': + if l[1] == "-1": folder = l[0] - l[1] = '0' + l[1] = "0" break if not folder: lock.release() return - with open(checkpoint_file, 'w') as f: + with open(checkpoint_file, "w") as f: for newline in datalist: - f.writelines(' '.join(newline)+'\n') + f.writelines(" ".join(newline) + "\n") lock.release() os.chdir(folder) - #runs vplanet on folder and writes the output to the log file - with open('vplanet_log','a+') as vplf: - vplanet = sub.Popen("vplanet vpl.in", shell=True, stdout=sub.PIPE, stderr=sub.PIPE, universal_newlines=True) + # runs vplanet on folder and writes the output to the log file + with open("vplanet_log", "a+") as vplf: + vplanet = sub.Popen( + "vplanet vpl.in", + shell=True, + stdout=sub.PIPE, + stderr=sub.PIPE, + universal_newlines=True, + ) return_code = vplanet.poll() for line in vplanet.stderr: vplf.write(line) @@ -157,46 +196,77 @@ def par_worker(checkpoint_file,system_name, body_list, log_file, in_files, quiet lock.acquire() datalist = [] - with open(checkpoint_file, 'r') as f: + with open(checkpoint_file, "r") as f: for newline in f: datalist.append(newline.strip().split()) if return_code is None: for l in datalist: if l[0] == folder: - l[1] = '1' + l[1] = "1" break if quiet == False: print(folder, "completed") if bigplanet == True: - with h5py.File(h5_file, 'w') as Master: - group_name = folder.split('/')[-1] - if group_name not in Master: - CreateHDF5Group(data, system_name, body_list, log_file, group_name,in_files, h5_file) + with h5py.File(h5_file, "w") as Master: + group_name = folder.split("/")[-1] + if group_name not in Master: + CreateHDF5Group( + data, + system_name, + body_list, + log_file, + group_name, + in_files, + h5_file, + ) else: for l in datalist: if l[0] == folder: - l[1] = '-1' + l[1] = "-1" break if quiet == False: print(folder, "failed") - with open(checkpoint_file, 'w') as f: + with open(checkpoint_file, "w") as f: for newline in datalist: - f.writelines(' '.join(newline)+'\n') - + f.writelines(" ".join(newline) + "\n") lock.release() os.chdir("../../") + def Arguments(): max_cores = mp.cpu_count() - parser = argparse.ArgumentParser(description="Using multi-processing to run a large number of simulations") - parser.add_argument("-c","--cores", type=int, default=max_cores, help="The total number of processors used") - parser.add_argument("-q","--quiet", action="store_true", help="No command line output for multi-planet") - parser.add_argument("-bp","--bigplanet", action="store_true" ,help="Runs bigplanet and creates the HDF5 files alongside running mutlt-planet") - parser.add_argument("-m","--email",type=str, help="Mails user when multi-planet is completed") + parser = argparse.ArgumentParser( + description="Using multi-processing to run a large number of simulations" + ) + parser.add_argument( + "-c", + "--cores", + type=int, + default=max_cores, + help="The total number of processors used", + ) + parser.add_argument( + "-q", + "--quiet", + action="store_true", + help="No command line output for multi-planet", + ) + parser.add_argument( + "-bp", + "--bigplanet", + action="store_true", + help="Runs bigplanet and creates the HDF5 files alongside running mutlt-planet", + ) + parser.add_argument( + "-m", + "--email", + type=str, + help="Mails user when multi-planet is completed", + ) parser.add_argument("InputFile", help="name of the vspace file") args = parser.parse_args() @@ -208,7 +278,10 @@ def Arguments(): except OSError: raise Exception("Unable to call VPLANET. Is it in your PATH?") - parallel_run_planet(args.InputFile,args.cores,args.quiet,args.bigplanet,args.email) + parallel_run_planet( + args.InputFile, args.cores, args.quiet, args.bigplanet, args.email + ) + if __name__ == "__main__": Arguments() From 41083b2ebfc4e8d357a840ee4b1685582ddf303d Mon Sep 17 00:00:00 2001 From: Rodrigo Luger Date: Wed, 19 May 2021 10:19:30 -0400 Subject: [PATCH 3/3] require bigplanet --- setup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4203c87..f77c5d4 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,14 @@ "write_to": os.path.join("multiplanet", "multiplanet_version.py"), "write_to_template": '__version__ = "{version}"\n', }, - install_requires=["numpy", "h5py", "argparse", "pandas", "scipy"], + install_requires=[ + "numpy", + "h5py", + "argparse", + "pandas", + "scipy", + "bigplanet", + ], entry_points={ "console_scripts": [ "multi-planet = multiplanet.multiplanet:Arguments",