crimes


Namecrimes JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/eddieantonio/crimes
SummaryImport C files into Python, illegally.
upload_time2024-08-06 16:34:04
maintainerNone
docs_urlNone
authorEddie Antonio Santos
requires_python<4.0,>=3.11
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Crimes

Blur the line between C and Python.

First, write some C code:

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

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

Then import that C code into Python:

```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:

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

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

```python
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:

```sh
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:

```sh
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:

```sh
export CC=gcc-13
```

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

```sh
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!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eddieantonio/crimes",
    "name": "crimes",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Eddie Antonio Santos",
    "author_email": "hello@eddieantonio.ca",
    "download_url": "https://files.pythonhosted.org/packages/4b/4b/2bfa502d40be1f880df92c1e6b51b71d8b9d81d09adad1e6a1cf28be0b49/crimes-0.1.1.tar.gz",
    "platform": null,
    "description": "# Crimes\n\nBlur the line between C and Python.\n\nFirst, write some C code:\n\n```c\n/* hello.c */\n#include <stdio.h>\n\nvoid hello(void) {\n    printf(\"Hello world from C!\\n\");\n}\n```\n\nThen import that C code into Python:\n\n```python\nimport crimes\n\ncrimes.commit()\n\nfrom hello import hello\n\nhello()  # prints \"Hello world from C!\"\n```\n\nAll you had to do is call `crimes.commit()`!\n\n## What if I am a terrible C programmer?\n\nNot to worry! `crimes` will print your syntax errors as part of the normal Python traceback:\n\n```c\n/* hello.c */\n#include <stdio.h>\n\n/* missing ')' on the next line: */\nvoid hello(void {\n    printf(\"Hello world from C!\\n\");\n}\n```\n\n```python\nimport crimes\n\ncrimes.commit()\n\nfrom hello import hello  # raises an error here\n```\n\nGives you this error:\n\n```\nTraceback (most recent call last):\n  File \"/tmp/example.py\", line 6, in <module>\n    from hello import hello  # type: ignore\n    ^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/tmp/hello.c\", line 5, in hello.c\n    void hello(void {\n                    ^\ncrimes.exceptions.CCompileError: expected ';', ',' or ')' before '{' token\n```\n\n# Install\n\n> [!WARNING]\n> This is currently pretty hacky.\n> I provide absolutely no guarantee that this will work on your machine.\n> Here's how I got it working on my machine, which running macOS.\n> I highly doubt this library works at all on Windows.\n\nFirst, install the library:\n\n```sh\npip install crimes\n```\n\nNext, make sure you have a compatible version of GCC.\nAny version of GCC 9.0 or greater should work. On most Linux distros,\nyou probably already have this installed. On macOS though... Apple\nthought it was a good idea to symlink `gcc` to `clang`. This does not\nwork. So first, install _actual_ GCC using brew:\n\n```sh\nbrew install gcc@13\n```\n\nNext, before using this module, make sure that `CC` is set to use\n`gcc-13`. You can do this universally like this:\n\n```sh\nexport CC=gcc-13\n```\n\n...but I prefer to do it per-process:\n\n```sh\nenv CC=gcc-13 python3 my-program-that-commits-crimes.py\n```\n\n\n# Copying\n\nCopyright \u00a9 2023 Eddie Antonio Santos. Apache-2.0 licensed. See\n`LICENSE` for details. _Especially_ the Disclaimer of Warranty!\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Import C files into Python, illegally.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/eddieantonio/crimes"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "189d294f3b63311739a95f94d39544aee27ec530356f6c4d2fc19ef5cbaa5c9e",
                "md5": "bf14f16a22bc0af59e344d5d8c5a30b3",
                "sha256": "96fe487a9baa0f5051f710a7fd4644be6e6eb0645c46cd7dc50a58640355ff2d"
            },
            "downloads": -1,
            "filename": "crimes-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bf14f16a22bc0af59e344d5d8c5a30b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 12263,
            "upload_time": "2024-08-06T16:34:03",
            "upload_time_iso_8601": "2024-08-06T16:34:03.565097Z",
            "url": "https://files.pythonhosted.org/packages/18/9d/294f3b63311739a95f94d39544aee27ec530356f6c4d2fc19ef5cbaa5c9e/crimes-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b4b2bfa502d40be1f880df92c1e6b51b71d8b9d81d09adad1e6a1cf28be0b49",
                "md5": "f3ea7db4030f68d463e743bd1a213714",
                "sha256": "fdfc0066982a91aaf37f79485b697db27770f249636f25d21c40524f62850aa9"
            },
            "downloads": -1,
            "filename": "crimes-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f3ea7db4030f68d463e743bd1a213714",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 10186,
            "upload_time": "2024-08-06T16:34:04",
            "upload_time_iso_8601": "2024-08-06T16:34:04.565306Z",
            "url": "https://files.pythonhosted.org/packages/4b/4b/2bfa502d40be1f880df92c1e6b51b71d8b9d81d09adad1e6a1cf28be0b49/crimes-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-06 16:34:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eddieantonio",
    "github_project": "crimes",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "crimes"
}
        
Elapsed time: 0.67412s