Skip to content

Commit

Permalink
Merge pull request #27 from conjure-cp/restructuring
Browse files Browse the repository at this point in the history
Restructuring
  • Loading branch information
ozgurakgun authored Mar 2, 2023
2 parents 9daad21 + a8c2c3c commit ea3c450
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 39 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ You do not have to use Google Colab to use Conjure Notebook. Currently we do not
This section is main for the benefit of the project maintainers.

- 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
2 changes: 1 addition & 1 deletion conjure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 2 additions & 2 deletions conjure/conjure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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'))

Expand Down
2 changes: 1 addition & 1 deletion conjure/conjurehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions conjure/conjuremagics.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ 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):
# 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) + ' '
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
Expand All @@ -75,14 +75,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()
Expand Down Expand Up @@ -201,7 +202,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()
Expand Down
13 changes: 0 additions & 13 deletions conjure/conjuretypeconversion.py

This file was deleted.

6 changes: 0 additions & 6 deletions setup.cfg

This file was deleted.

14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
long_description = fh.read()

setuptools.setup(
name="conjure",
version="v2.3.0",
author="Ogabek Yusupov",
author_email="[email protected]",
description="Conjure extension for jupyter notebook",
name="Conjure Notebook",
version="v0.0.2",
author="Ogabek Yusupov, Özgür Akgün, Chris Jefferson",
author_email="[email protected], [email protected], [email protected]",
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",
]
)
)

0 comments on commit ea3c450

Please sign in to comment.