From fd1ffd16630c5d6754b654e2d3859309eae8147f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Akgu=CC=88n?= Date: Thu, 2 Mar 2023 14:46:53 +0000 Subject: [PATCH 1/5] general code formatting improvements and clean ups --- conjure/__init__.py | 2 +- conjure/conjure.py | 4 ++-- conjure/conjurehelper.py | 2 +- conjure/conjuremagics.py | 27 +++++++++++++++------------ conjure/conjuretypeconversion.py | 13 ------------- setup.cfg | 6 ------ setup.py | 14 +++++++------- 7 files changed, 26 insertions(+), 42 deletions(-) delete mode 100644 conjure/conjuretypeconversion.py delete mode 100644 setup.cfg diff --git a/conjure/__init__.py b/conjure/__init__.py index cbc4cce..a35e77a 100644 --- a/conjure/__init__.py +++ b/conjure/__init__.py @@ -9,7 +9,7 @@ def load_ipython_extension(ipython): display(Javascript(initHighlighter)) - if(Conjure.check_conjure()): # check conjure is installed + if Conjure.check_conjure(): # check conjure is installed ipython.register_magics(ConjureMagics) print('Conjure extension is loaded.') print('For usage help run: %conjure_help') diff --git a/conjure/conjure.py b/conjure/conjure.py index 4fcbb02..97f9bf7 100644 --- a/conjure/conjure.py +++ b/conjure/conjure.py @@ -26,7 +26,7 @@ def solve(self, args: str, code: str, shell_params: dict) -> dict: " --output-format=json --solutions-in-one-file --solver=chuffed " + args, ], shell=True, stdout=PIPE, stderr=PIPE) _, error = shell_output.communicate() - if(error): + if error: raise Exception(error.decode('utf-8')) return conjurehelper.read_solution_json_file() @@ -37,7 +37,7 @@ def get_representations(self, code: str): shell_output = Popen(["conjure ide --dump-representations " + temp_essence_file], shell=True, stdout=PIPE, stderr=PIPE) output, error = shell_output.communicate() - if(error): + if error: raise Exception(error.decode('utf-8')) return json.loads(output.decode('utf-8')) diff --git a/conjure/conjurehelper.py b/conjure/conjurehelper.py index fee48e3..4c01dd6 100644 --- a/conjure/conjurehelper.py +++ b/conjure/conjurehelper.py @@ -11,7 +11,7 @@ def __init__(self): if not os.path.isdir(self.tempdir): os.mkdir(self.tempdir) - def create_temp_file(self, extension : str, contents: str) -> str: + def create_temp_file(self, extension: str, contents: str) -> str: # use the current timestamp as the filename for the Essence file timestamp = datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S") temp_filename = "%s.%s" % (timestamp, extension) diff --git a/conjure/conjuremagics.py b/conjure/conjuremagics.py index 86a75fc..6789403 100644 --- a/conjure/conjuremagics.py +++ b/conjure/conjuremagics.py @@ -39,23 +39,25 @@ def conjure(self, args, code): args += ' --number-of-solutions=all ' # adding representations - if(self.choose_representations_value == self.choose_representations_options[1] # only add representations if user selected so on settings - and len(self.conjure_representations.keys()) > 0): - reps = [] - for repName, repAns in self.conjure_representations.items(): - reps.append(repName + ":" + repAns) - args += ' --responses-representation=' + ",".join(reps) + ' ' + # only add representations if user selected so on settings + if self.choose_representations_value == self.choose_representations_options[1] + and len(self.conjure_representations.keys()) > 0: + reps = [] + for repName, repAns in self.conjure_representations.items(): + reps.append(repName + ":" + repAns) + args += ' --responses-representation=' + ",".join(reps) + ' ' # removing language Essence 1.3 from code in incremental building # we will only remove it in subsequent runs - if(len(self.conjure_models) > 0) and code.startswith('language Essence '): + if len(self.conjure_models) > 0 and code.startswith('language Essence '): code = "\n".join(code.split("\n")[1:]) # code execution try: if code not in self.conjure_models: # we won't add code to models if the code is already there self.conjure_models.append(code) - resultdict = conjure.solve(args, '\n'.join(self.conjure_models), dict(self.shell.user_ns)) + resultdict = conjure.solve(args, '\n'.join( + self.conjure_models), dict(self.shell.user_ns)) except Exception as err: self.conjure_models.pop() @@ -75,14 +77,15 @@ def conjure(self, args, code): else: return resultdict['conjure_solutions'] else: - print("Done. Found %d solution(s)." % len(resultdict["conjure_solutions"])) + print("Done. Found %d solution(s)." % + len(resultdict["conjure_solutions"])) if len(resultdict['conjure_solutions']) == 1: print("Variables have been assigned their value in the solution") - print("The solution is also stored in Python variable: conjure_solutions") + print( + "The solution is also stored in Python variable: conjure_solutions") elif len(resultdict['conjure_solutions'] > 1): print("Solutions are stored in Python variable: conjure_solutions") - @line_magic def conjure_settings(self, line): conjure = Conjure() @@ -201,7 +204,7 @@ def conjure_print(self, line): @line_magic def conjure_rollback(self, line): - if(len(self.conjure_models) == 0): + if len(self.conjure_models) == 0: print("Exception: conjure model is empty.", file=sys.stderr) return self.conjure_models.pop() diff --git a/conjure/conjuretypeconversion.py b/conjure/conjuretypeconversion.py deleted file mode 100644 index 042a99f..0000000 --- a/conjure/conjuretypeconversion.py +++ /dev/null @@ -1,13 +0,0 @@ -class ConjureTypeConversion(): - @staticmethod - def to_conjure_param_text(variable_name, value) -> str: - if type(value) is bool: # type conversion for conjure bool type - return "letting {0} be {1}\n".format(variable_name, 'true' if value else 'false') - if type(value) is dict: # type coversion for conjure function type, this will convert python dictionary to essence param type - return "letting {0} be function ({1})".format(variable_name, ", ".join( - list(map(lambda x: (str(x[0]) + ' --> ' + str(x[1])), value.items()))) - ) - if type(value) is set: - return "letting {0} be new type enum {{{1}}}".format(variable_name, ", ".join(list(value))) - else: - return "letting {0} be {1}\n".format(variable_name, value) diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 7f1c3f5..0000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[bdist_wheel] -# This flag says to generate wheels that support both Python 2 and Python -# 3. If your code will not run unchanged on both Python 2 and 3, you will -# need to generate separate wheels for each Python version that you -# support. -universal=1 \ No newline at end of file diff --git a/setup.py b/setup.py index d55e6c4..14678e8 100644 --- a/setup.py +++ b/setup.py @@ -4,21 +4,21 @@ long_description = fh.read() setuptools.setup( - name="conjure", - version="v2.3.0", - author="Ogabek Yusupov", - author_email="ogabekyusupov@gmail.com", - description="Conjure extension for jupyter notebook", + name="Conjure Notebook", + version="v0.0.2", + author="Ogabek Yusupov, Ozgur Akgun, Chris Jefferson", + author_email="ogabekyusupov@gmail.com, ozgur.akgun@st-andrews.ac.uk, caj21@st-andrews.ac.uk", + description="A Jupyter notebook extension for the automated constraint modelling tool Conjure", long_description=long_description, url="https://github.com/conjure-cp/conjure-notebook", packages=setuptools.find_packages(), include_package_data=True, install_requires=[ - 'ipywidgets>=7,<8', + 'ipywidgets>=7,<8', ], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ] -) \ No newline at end of file +) From 682d65de4ddaff87c75df7c70e2adcf9cbf4b5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Akgu=CC=88n?= Date: Thu, 2 Mar 2023 14:48:50 +0000 Subject: [PATCH 2/5] oops --- conjure/conjuremagics.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conjure/conjuremagics.py b/conjure/conjuremagics.py index 6789403..5430685 100644 --- a/conjure/conjuremagics.py +++ b/conjure/conjuremagics.py @@ -40,8 +40,7 @@ def conjure(self, args, code): # adding representations # only add representations if user selected so on settings - if self.choose_representations_value == self.choose_representations_options[1] - and len(self.conjure_representations.keys()) > 0: + if self.choose_representations_value == self.choose_representations_options[1] and len(self.conjure_representations.keys()) > 0: reps = [] for repName, repAns in self.conjure_representations.items(): reps.append(repName + ":" + repAns) From 056b76bf2f9d773eeb4bd1cf40e66b0df6f21fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Akgu=CC=88n?= Date: Thu, 2 Mar 2023 14:51:39 +0000 Subject: [PATCH 3/5] oops x2 --- conjure/conjuremagics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conjure/conjuremagics.py b/conjure/conjuremagics.py index 5430685..9bbab2b 100644 --- a/conjure/conjuremagics.py +++ b/conjure/conjuremagics.py @@ -41,9 +41,9 @@ def conjure(self, args, code): # adding representations # only add representations if user selected so on settings if self.choose_representations_value == self.choose_representations_options[1] and len(self.conjure_representations.keys()) > 0: - reps = [] - for repName, repAns in self.conjure_representations.items(): - reps.append(repName + ":" + repAns) + reps = [] + for repName, repAns in self.conjure_representations.items(): + reps.append(repName + ":" + repAns) args += ' --responses-representation=' + ",".join(reps) + ' ' # removing language Essence 1.3 from code in incremental building From aa12919a4b41ddaedfb67ef465f94ce00cd73880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Akgu=CC=88n?= Date: Thu, 2 Mar 2023 14:56:31 +0000 Subject: [PATCH 4/5] Also edit setup.py --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7caf90..c091b4a 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,9 @@ See demo videos made by @ogabek96 on Youtube: https://www.youtube.com/channel/UC ## Making a release - Edit the versions in scripts/install-colab.sh +- Edit the version in setup.py - Edit the version in the README.md example (this file!) - Create a tag, push to main, push the tag: - - git commit scripts/versions.sh README.md -m "Updating version information" + - git commit scripts/versions.sh README.md setup.py -m "Updating version information" - git tag -a v3.1.4 -m "version 3.1.4" - git push origin main --tags From a8c2c3c4f8702c24f782c4639ed4c21240e7f17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Akgu=CC=88n?= Date: Thu, 2 Mar 2023 14:57:46 +0000 Subject: [PATCH 5/5] my name --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 14678e8..6c5ed69 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="Conjure Notebook", version="v0.0.2", - author="Ogabek Yusupov, Ozgur Akgun, Chris Jefferson", + author="Ogabek Yusupov, Özgür Akgün, Chris Jefferson", author_email="ogabekyusupov@gmail.com, ozgur.akgun@st-andrews.ac.uk, caj21@st-andrews.ac.uk", description="A Jupyter notebook extension for the automated constraint modelling tool Conjure", long_description=long_description,