-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a little bit more setup. Make distinction between ast builder API, pr…
…ocedural API, and add a verify function
- Loading branch information
1 parent
6c999ef
commit fd148ba
Showing
9 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from uclid.builder import UclidModule | ||
|
||
|
||
class Module: | ||
def __init__(self, name): | ||
self.module = UclidModule(name) | ||
|
||
def __str__(self): | ||
return self.module.__inject__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import logging | ||
import os | ||
import pathlib | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
import zipfile | ||
|
||
import wget | ||
|
||
__author__ = "Federico Mora" | ||
__copyright__ = "Federico Mora" | ||
__license__ = "MIT" | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
LATEST_RELEASE_URL = "https://github.com/uclid-org/uclid/releases/download/v0.9.5d-prerelease/uclid-0.9.5.zip" # noqa: E501 | ||
|
||
|
||
def verify(query: str): | ||
uclid = download_uclid() | ||
with tempfile.NamedTemporaryFile() as tmp: | ||
tmp.write(query.encode()) | ||
tmp.flush() | ||
output = subprocess.run([uclid, tmp.name], capture_output=True) | ||
return output.stdout.decode("utf-8") | ||
|
||
|
||
def download_uclid(): | ||
# Get the directory of this file | ||
base = pathlib.Path(__file__).parent.resolve() | ||
_logger.info(f"Base directory: {base}") | ||
|
||
# Get the other directories we'll use | ||
build = os.path.join(base, "build") | ||
uclid = os.path.join(build, "uclid-0.9.5", "bin", "uclid") | ||
|
||
# if uclid exists, return it | ||
if os.path.exists(uclid): | ||
_logger.info("Uclid exists") | ||
return uclid | ||
|
||
# delete build directory if it exists | ||
_logger.info("Deleting build directory if it exists") | ||
if os.path.exists(build): | ||
shutil.rmtree(build) | ||
_logger.info("Build directory deleted") | ||
|
||
# make a build directory if it doesn't exist | ||
_logger.info("Making build directory") | ||
os.makedirs(build) | ||
|
||
# download uclid | ||
_logger.info("Downloading Uclid") | ||
wget.download(LATEST_RELEASE_URL, os.path.join(build, "uclid.zip")) | ||
_logger.info("Uclid downloaded") | ||
|
||
# unzip uclid.zip | ||
_logger.info("Unzipping Uclid") | ||
with zipfile.ZipFile(os.path.join(build, "uclid.zip"), "r") as zip_ref: | ||
zip_ref.extractall(build) | ||
_logger.info("Uclid unzipped") | ||
|
||
# if on windows, add .bat to uclid | ||
if os.name == "nt": | ||
uclid += ".bat" | ||
|
||
_logger.info(f"Uclid executable: {uclid}") | ||
|
||
# make uclid executable | ||
_logger.info("Making Uclid executable") | ||
os.chmod(uclid, 0o755) | ||
_logger.info("Uclid is now executable") | ||
|
||
return uclid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
__author__ = "Federico Mora" | ||
__copyright__ = "Federico Mora" | ||
__license__ = "MIT" | ||
|
||
|
||
def test_empty_module(): | ||
from uclid import Module | ||
|
||
m = Module("empty") | ||
# assert str(m).split() == "module empty { }".split() | ||
assert "module empty {" in str(m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import subprocess | ||
|
||
from uclid import verify | ||
from uclid.run import download_uclid | ||
|
||
__author__ = "Federico Mora" | ||
__copyright__ = "Federico Mora" | ||
__license__ = "MIT" | ||
|
||
|
||
def test_download(): | ||
uclid = download_uclid() | ||
output = subprocess.run([uclid, "--help"], capture_output=True) | ||
assert output.returncode == 0 | ||
output = output.stdout.decode("utf-8") | ||
assert "uclid 0.9.5" in output, f"uclid version not found in {output}" | ||
|
||
|
||
def test_run(): | ||
query = "module main { }" | ||
output = verify(query).split() | ||
expected = "Successfully parsed 1 and instantiated 1 module(s).".split() | ||
assert output == expected, f"Expected `{expected}` but got `{output}`" |