Skip to content

Commit

Permalink
Merge branch 'master' into docker-infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
teoliphant authored Apr 22, 2022
2 parents 6a4d2b0 + fa0e7a1 commit 0ff6ec9
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 3 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: epython

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
main:

runs-on: ubuntu-latest
timeout-minutes: 35
defaults:
run:
shell: bash -l {0}
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
mamba-version: "*"
environment-file: conda/dev.yaml
channels: conda-forge,nodefaults
activate-environment: epython
use-mamba: true
miniforge-variant: Mambaforge

- name: installation
run: |
pip install .
epython tests/simpleone.epy --backend=cpython
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
*.egg-info/
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# epython

EPython is a typed-subset of the Python language useful for extending the language with new builtin types and methods.

The goal is to be able to write things like NumPy, SciPy, Pandas, bitarray, and any other extension module of Python in this language and get equivalent or better perfomance than writing it using the C-API typically provided.
Expand All @@ -13,12 +14,16 @@ If you are interested in contributing to the design and goals, then join the Dis

# Installation

pip install epython
```bash
pip install epython
```

# Usage

epython extmodule.epy --backend=cpython

```bash
epython extmodule.epy --backend=cpython
```

Produces a compiled extension module for the given Python backend.

## Docker Development
Expand All @@ -33,3 +38,23 @@ From the root of the repository.
To run the interactive session:

`docker run -p 8008:8000 -t epython-wasm:latest `

# Development

Create an environment for **epython**:

```bash
$ conda env create --file conda/dev.yaml
```

Activate the **epython** environment:

```bash
$ conda activate epython
```

Install it locally in development mode:

```bash
$ pip install -e .
```
6 changes: 6 additions & 0 deletions conda/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: epython
channels:
- conda-forge
- nodefaults
dependencies:
- python 3.9.*
2 changes: 2 additions & 0 deletions epython/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__version__ = "0.1.0"

import epython.importer

from .epython import register_func
49 changes: 49 additions & 0 deletions epython/importer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Importing this module allows import .epy files like .py files.
The main reason for naming epython files with the .epy file extension is to
avoid confusion with regular Python modules. A package may contain a number
of (sub-) modules of which only some are epython extensions.
For development of epython packages, it is nevertheless very useful to import
.epy files just like .pt files, which is possible by simply importing epython
first. E.g.
import epython
import myext # will import myext.epy
Without importing epython first, myext will not work, which helps to avoid
using epython extensions as pure Python modules (which will be quite slow).
"""
import sys
import imp
from os.path import isfile, join


class EPY_Importer(object):

def find_module(self, fullname, path=None):
name = fullname.rsplit('.', 1)[-1]
for dir_path in path or sys.path:
self.path = join(dir_path, name + '.epy')
if isfile(self.path):
self.modtype = imp.PY_SOURCE
return self
return None

def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]

mod = imp.new_module(fullname)
mod.__file__ = self.path
mod.__loader__ = self
with open(self.path, 'rb') as fi:
code = fi.read()

exec(code, mod.__dict__)
sys.modules[fullname] = mod
return mod


sys.meta_path.append(EPY_Importer())

0 comments on commit 0ff6ec9

Please sign in to comment.