Skip to content

Commit

Permalink
Cairo v0.4.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Sep 22, 2021
1 parent 7526bff commit cf8266f
Show file tree
Hide file tree
Showing 271 changed files with 11,153 additions and 6,784 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We recommend starting from [Setting up the environment](https://cairo-lang.org/d
# Installation instructions

You should be able to download the python package zip file directly from
[github](https://github.com/starkware-libs/cairo-lang/releases/tag/v0.4.0)
[github](https://github.com/starkware-libs/cairo-lang/releases/tag/v0.4.1)
and install it using ``pip``.
See [Setting up the environment](https://cairo-lang.org/docs/quickstart.html).

Expand Down Expand Up @@ -54,7 +54,7 @@ Once the docker image is built, you can fetch the python package zip file using:

```bash
> container_id=$(docker create cairo)
> docker cp ${container_id}:/app/cairo-lang-0.4.0.zip .
> docker cp ${container_id}:/app/cairo-lang-0.4.1.zip .
> docker rm -v ${container_id}
```

41 changes: 24 additions & 17 deletions src/cmake_utils/gen_pip_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,41 @@


def main():
parser = ArgumentParser(
description='Generates a CMake file declaring all pip targets.')
parser = ArgumentParser(description="Generates a CMake file declaring all pip targets.")
parser.add_argument(
'--interpreter_deps', type=str, nargs='*', required=True,
help='Interpreters and dependency output JSON files. '
'Example: python3.7:python_deps.json ...')
parser.add_argument('--output', type=str, help='Output cmake file', required=True)
"--interpreter_deps",
type=str,
nargs="*",
required=True,
help="Interpreters and dependency output JSON files. "
"Example: python3.7:python_deps.json ...",
)
parser.add_argument("--output", type=str, help="Output cmake file", required=True)
args = parser.parse_args()

res = ''
res = ""
package_libs = defaultdict(list)
package_versions = defaultdict(list)

# Load dependency files for each interpreter.
for interpreter_dep in args.interpreter_deps:
interpreter, dep_file = interpreter_dep.split(':')
with open(dep_file, 'r') as fp:
interpreter, dep_file = interpreter_dep.split(":")
with open(dep_file, "r") as fp:
for package in json.load(fp):
# Extract name of package.
name = package['package']['key'].replace('-', '_').lower()
name = package["package"]["key"].replace("-", "_").lower()
# Build a requirement line for current interpreter.
req = package['package']['package_name'] + \
'==' + package['package']['installed_version']
req = (
package["package"]["package_name"]
+ "=="
+ package["package"]["installed_version"]
)
package_versions[name].append(f'"{interpreter} {req}"')
# Append dependency libraries.
dep_names = [
dep['key'].replace('-', '_').lower() for dep in package['dependencies']]
package_libs[name] += [f'{interpreter}:pip_{name}' for name in dep_names]
dep["key"].replace("-", "_").lower() for dep in package["dependencies"]
]
package_libs[name] += [f"{interpreter}:pip_{name}" for name in dep_names]

# Create a united rule for each pip package.
for package_name in sorted(package_versions.keys()):
Expand All @@ -56,9 +63,9 @@ def main():

# Write the output file, only if it is changed, so that the timestamp will not be updated
# otherwise.
if not os.path.exists(args.output) or open(args.output, 'r').read() != res:
open(args.output, 'w').write(res)
if not os.path.exists(args.output) or open(args.output, "r").read() != res:
open(args.output, "w").write(res)


if __name__ == '__main__':
if __name__ == "__main__":
main()
49 changes: 27 additions & 22 deletions src/cmake_utils/gen_py_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,56 @@


def extract_licenses(filename: str) -> List[str]:
prefix = 'License: '
prefix = "License: "
if os.path.isfile(filename):
with open(filename, encoding='utf8') as fp:
with open(filename, encoding="utf8") as fp:
for line in fp.readlines():
if line.startswith(prefix):
return line.strip()[len(prefix):].split(',')
return line.strip()[len(prefix) :].split(",")
return []


def main():
parser = ArgumentParser(
description='Generates a json file that holds all the information for a python library '
'target.')
parser.add_argument('--name', type=str, help='Python library target name', required=True)
description="Generates a json file that holds all the information for a python library "
"target."
)
parser.add_argument("--name", type=str, help="Python library target name", required=True)
parser.add_argument(
'--interpreters', type=str, nargs='*', help='Supported interpreters',
default=['python3.7'])
parser.add_argument('--lib_dir', type=str, nargs='*', help='Library directory', required=True)
"--interpreters", type=str, nargs="*", help="Supported interpreters", default=["python3.7"]
)
parser.add_argument("--lib_dir", type=str, nargs="*", help="Library directory", required=True)
parser.add_argument(
'--import_paths', type=str, nargs='*', default=[], help='Path to add to sys.path')
"--import_paths", type=str, nargs="*", default=[], help="Path to add to sys.path"
)
parser.add_argument("--files", type=str, nargs="*", help="Library file list")
parser.add_argument(
'--files', type=str, nargs='*', help='Library file list')
"--lib_deps", type=str, nargs="*", help="Dependency libraries list", required=True
)
parser.add_argument("--output", type=str, help="Output info file", required=True)
parser.add_argument(
'--lib_deps', type=str, nargs='*', help='Dependency libraries list', required=True)
parser.add_argument('--output', type=str, help='Output info file', required=True)
"--py_exe_deps", type=str, nargs="*", required=True, help="List of executable dependencies"
)
parser.add_argument(
'--py_exe_deps', type=str, nargs='*', required=True, help='List of executable dependencies')
"--cmake_dir", type=str, nargs="?", help="Directory of this CMake target", required=False
)
parser.add_argument(
'--cmake_dir', type=str, nargs='?', help='Directory of this CMake target', required=False)
parser.add_argument(
'--prefix', type=str, nargs='?', help='Prefix of this CMake target', required=False)
"--prefix", type=str, nargs="?", help="Prefix of this CMake target", required=False
)
args = parser.parse_args()

# Try to extract license if possible.
licenses = []
for d in args.lib_dir:
# Remove filters if exist (like 'pypy:<path>').
d = d.split(':')[-1]
metadata_files = glob.glob(os.path.join(d, '*/METADATA'))
d = d.split(":")[-1]
metadata_files = glob.glob(os.path.join(d, "*/METADATA"))
for filename in metadata_files:
licenses += extract_licenses(filename)
licenses = sorted(set(licenses))

os.makedirs(os.path.dirname(args.output), exist_ok=True)
with open(args.output, 'w') as fp:
with open(args.output, "w") as fp:
json.dump(
dict(
name=args.name,
Expand All @@ -94,8 +99,8 @@ def main():
sort_keys=True,
indent=4,
)
fp.write('\n')
fp.write("\n")


if __name__ == '__main__':
if __name__ == "__main__":
main()
86 changes: 47 additions & 39 deletions src/cmake_utils/gen_python_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,41 @@


def main():
parser = ArgumentParser(
description='Generates an executable file for python_exe().')
parser = ArgumentParser(description="Generates an executable file for python_exe().")
parser.add_argument("--name", help="The name of the target", required=True)
parser.add_argument("--exe_path", help="The path to the output script file", required=True)
parser.add_argument(
'--name', help='The name of the target', required=True)
"--venv", help="The python virtual environment that will run the module", required=True
)
parser.add_argument("--module", help="The name of the module to run", required=True)
parser.add_argument("--args", help="Additional arguments to pass to the module")
parser.add_argument("--info_dir", help="Directory for all libraries info files", required=True)
parser.add_argument(
'--exe_path', help='The path to the output script file', required=True)
"--cmake_binary_dir", help="The path to the CMake binary root dir", required=True
)
parser.add_argument("--working_dir", help="Working directory to run the executable from.")
parser.add_argument(
'--venv', help='The python virtual environment that will run the module', required=True)
parser.add_argument(
'--module', help='The name of the module to run', required=True)
parser.add_argument(
'--args', help='Additional arguments to pass to the module')
parser.add_argument(
'--info_dir', help='Directory for all libraries info files', required=True)
parser.add_argument(
'--cmake_binary_dir', help='The path to the CMake binary root dir', required=True)
parser.add_argument(
'--working_dir', help='Working directory to run the executable from.')
parser.add_argument(
'--environment_variables', help='Environments variables for the executable.')
"--environment_variables", help="Environments variables for the executable."
)
args = parser.parse_args()

venv_info = json.load(open(os.path.join(args.info_dir, f'{args.venv}.info')))
venv_info = json.load(open(os.path.join(args.info_dir, f"{args.venv}.info")))
# Fetch the location of the venv dir, relative to the executable script.
build_path_bash = os.path.relpath(
args.cmake_binary_dir, os.path.dirname(args.exe_path))
assert 'venv_dir' in venv_info, \
f'venv_dir not found, make sure "{args.venv}" is a valid virtual environment.'
venv_dir_rel = os.path.relpath(venv_info['venv_dir'], args.cmake_binary_dir)
cd_command = f'cd {args.working_dir}' if args.working_dir else ''
build_path_bash = os.path.relpath(args.cmake_binary_dir, os.path.dirname(args.exe_path))
assert (
"venv_dir" in venv_info
), f'venv_dir not found, make sure "{args.venv}" is a valid virtual environment.'
venv_dir_rel = os.path.relpath(venv_info["venv_dir"], args.cmake_binary_dir)
cd_command = f"cd {args.working_dir}" if args.working_dir else ""

exe_args = args.args.replace(
'{VENV_SITE_DIR}',
'${BUILD_ROOT}/' + os.path.relpath(venv_info['site_dir'], args.cmake_binary_dir))
"{VENV_SITE_DIR}",
"${BUILD_ROOT}/" + os.path.relpath(venv_info["site_dir"], args.cmake_binary_dir),
)

with open(args.exe_path, 'w') as fp:
fp.write(f"""\
with open(args.exe_path, "w") as fp:
fp.write(
f"""\
#!/bin/bash
# Find the directory of the executable using $(dirname $0), convert it to absolute path using
# realpath, and use it to find build directory (e.g., .../build/Debug or /app/).
Expand All @@ -60,22 +58,32 @@ def main():
CMAKE_TARGET_NAME={args.name} \
${{BUILD_ROOT}}/{venv_dir_rel}/bin/python -u -m {args.module} \
{exe_args} $@
""")
"""
)

os.chmod(
args.exe_path,
stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR |
stat.S_IXGRP | stat.S_IRGRP |
stat.S_IXOTH | stat.S_IROTH)
stat.S_IXUSR
| stat.S_IRUSR
| stat.S_IWUSR
| stat.S_IXGRP
| stat.S_IRGRP
| stat.S_IXOTH
| stat.S_IROTH,
)

# Generate info file.
with open(os.path.join(args.info_dir, f'{args.name}.info'), 'w') as fp:
json.dump({
'exe_path': args.exe_path,
'venv': args.venv,
}, fp, indent=4)
fp.write('\n')
with open(os.path.join(args.info_dir, f"{args.name}.info"), "w") as fp:
json.dump(
{
"exe_path": args.exe_path,
"venv": args.venv,
},
fp,
indent=4,
)
fp.write("\n")


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit cf8266f

Please sign in to comment.