Git Product home page Git Product logo

crimes's Introduction

Crimes

Blur the line between C and Python.

First, write some C code:

/* hello.c */
#include <stdio.h>

void hello(void) {
    printf("Hello world from C!\n");
}

Then import that C code into Python:

import crimes

crimes.commit()

from hello import hello

hello()  # prints "Hello world from C!"

All you had to do is call crimes.commit()!

What if I am a terrible C programmer?

Not to worry! crimes will print your syntax errors as part of the normal Python traceback:

/* hello.c */
#include <stdio.h>

/* missing ')' on the next line: */
void hello(void {
    printf("Hello world from C!\n");
}
import crimes

crimes.commit()

from hello import hello  # raises an error here

Gives you this error:

Traceback (most recent call last):
  File "/tmp/example.py", line 6, in <module>
    from hello import hello  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/hello.c", line 5, in hello.c
    void hello(void {
                    ^
crimes.exceptions.CCompileError: expected ';', ',' or ')' before '{' token

Install

[!WARNING] This is currently pretty hacky. I provide absolutely no guarantee that this will work on your machine. Here's how I got it working on my machine, which running macOS. I highly doubt this library works at all on Windows.

First, install the library:

pip install crimes

Next, make sure you have a compatible version of GCC. Any version of GCC 9.0 or greater should work. On most Linux distros, you probably already have this installed. On macOS though... Apple thought it was a good idea to symlink gcc to clang. This does not work. So first, install actual GCC using brew:

brew install gcc@13

Next, before using this module, make sure that CC is set to use gcc-13. You can do this universally like this:

export CC=gcc-13

...but I prefer to do it per-process:

env CC=gcc-13 python3 my-program-that-commits-crimes.py

Copying

Copyright © 2023 Eddie Antonio Santos. Apache-2.0 licensed. See LICENSE for details. Especially the Disclaimer of Warranty!

crimes's People

Contributors

eddieantonio avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.