From 4dbfe64195cd34e29037379c71bffd7645054b8e Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 27 Oct 2025 20:18:28 +0100 Subject: [PATCH] Script for downloading binaries added, readme updated --- README.md | 66 +++++++++++++++++++++++++++++++++++++++---- pyproject.toml | 4 ++- tools/get_binaries.py | 47 ++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 tools/get_binaries.py diff --git a/README.md b/README.md index de02c42..7d5eb65 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# State of the project +# Copapy Development is in a very early stage. Only very few components are in a working state. -# Introduction +## Introduction Copapy is a python based embedded domain specific language (eDSL) with a copy & patch compiler. It compiles to machine code. It uses the python interpreter for compilation. It generates a directed graph of variables and operations. The compiler generates machine code by composing pre-compiled stencils derived from C code with gcc -O3. @@ -20,13 +20,69 @@ The language aims to be: - No runtime errors - Immutable types -# How it works +### How it works -## Compilation +### Compilation The Compilation step starts with the directed graph of variables and operations generated by the python interpreter. -## Tooling +### Tooling Because the language is an embedded language, it can relay heavily on python tooling. While copapy is static typed, it uses Python to derive types during compile time wherever possible. It can get full benefit from python type checkers, to catch type errors even before compilation. Python and Copapy code can be combined seamlessly. Python acts as macro-language for the Copapy program. However, the project is designed in a way that the distinction has typically not to be considered by the programmer. + +## Developer Guide +Contributions are welcome, please open an issue or submit a pull request on GitHub. + +To get started with developing the package, follow these steps. + +First, clone the repository to your local machine using Git: + +```bash +git clone https://github.com/Nonannet/copapy.git +cd copapy +``` + +You may setup a venv: + +```bash +python -m venv .venv +source .venv/bin/activate # On Windows use `.venv\Scripts\activate` +``` + +Build and install the package and dev dependencies: + +```bash +pip install .[dev] +``` + +If this fails because you have no suitable c compiler installed you can either install a +compiler or use the binary from pypi: + +```bash +pip install copapy[dev] +``` + +When using pytest it will run the binary from pypi but the local python code from the repo. + +For running all tests you need the stencil object files and the compiled runner. +You can download the stencils and binary runner from GitHub or build them with gcc your self. + +For downloading the files run: + +```bash +python tools/get_binaries.py +``` + +To build the binaries from source on linux run: + +```bash +bash tools/build.sh +``` + +Ensure that everything is set up correctly by running the unit tests: + +```bash +pytest +``` + ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/pyproject.toml b/pyproject.toml index d9b30fa..2d487d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,9 @@ copapy = ["obj/*.o", "py.typed"] dev = [ "ruff", "mypy", - "pytest" + "pytest", + "requests", + "types-requests" ] [tool.mypy] diff --git a/tools/get_binaries.py b/tools/get_binaries.py new file mode 100644 index 0000000..0ebd8ee --- /dev/null +++ b/tools/get_binaries.py @@ -0,0 +1,47 @@ +import os +import requests + +OWNER = "Nonannet" +REPO = "copapy" + +def main() -> None: + # Get all releases (includes prereleases) + api_url = f"https://api.github.com/repos/{OWNER}/{REPO}/releases" + resp = requests.get(api_url, timeout=10) + resp.raise_for_status() + releases = resp.json() + + assert releases, "No releases found." + + release = releases[0] # newest release (first in list) + tag = release["tag_name"] + print(f"Found latest release: {tag}") + + assets = release.get("assets", []) + assert assets, "No assets found for this release." + + for asset in assets: + url = asset["browser_download_url"] + name: str = asset["name"] + + if name.endswith('.o'): + dest = 'src/copapy/obj' + elif name == 'coparun.exe' and os.name == 'nt': + dest = 'bin' + elif name == 'coparun' and os.name == 'posix': + dest = 'bin' + else: + dest = '' + + if dest: + os.makedirs(dest, exist_ok=True) + print(f"- Downloading {name} ...") + r = requests.get(url, stream=True, timeout=30) + r.raise_for_status() + with open(os.path.join(dest, name), "wb") as f: + for chunk in r.iter_content(chunk_size=8192): + f.write(chunk) + print(f"- Saved {name} to {dest}") + +if __name__ == "__main__": + main()