Skip to content

Commit ecf49b2

Browse files
EmilyBourneyguclu
andauthored
Simplify epyccel import (pyccel#1855)
Move `epyccel.py` to `pyccel/commands/` folder. This allows a shortcut to be introduced for the import of the most commonly used `epyccel` function. It is now possible to do `from pyccel import epyccel`. Fixes pyccel#1836. --------- Co-authored-by: Yaman Güçlü <[email protected]>
1 parent c57e3ad commit ecf49b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+91
-72
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ All notable changes to this project will be documented in this file.
4141

4242
### Changed
4343

44+
- #1836 : Move `epyccel` module to `pyccel.commands.epyccel` and add support for shortcut import `from pyccel import epyccel`.
4445
- #1720 : functions with the `@inline` decorator are no longer exposed to Python in the shared library.
4546
- #1720 : Error raised when incompatible arguments are passed to an `inlined` function is now fatal.
4647
- \[TESTS\] Filter out cast warnings in cast tests.

docs/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ end module mod
393393
In addition to the `pyccel` command, the Pyccel library provides the `epyccel` Python function, whose name stands for "embedded Pyccel": given a pure Python function `f` with type annotations, `epyccel` returns a "pyccelised" function `f_fast` that can be used in the same Python session.
394394
For example:
395395
```python
396-
from pyccel.epyccel import epyccel
396+
from pyccel import epyccel
397397
from mod import f
398398

399399
f_fast = epyccel(f)
@@ -434,7 +434,7 @@ Finally we compare the timings obtained on an Intel Core 3 architecture.
434434
```bash
435435
In [1]: from numpy.random import random
436436
In [2]: from mod import quicksort
437-
In [3]: from pyccel.epyccel import epyccel
437+
In [3]: from pyccel import epyccel
438438

439439
In [4]: quicksort_fast = epyccel(quicksort)
440440
In [5]: x = random(100)

pyccel/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .version import __version__
2+
from .commands.epyccel import epyccel
23
from .commands.lambdify import lambdify

pyccel/epyccel.py renamed to pyccel/commands/epyccel.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# This file is part of Pyccel which is released under MIT License. See the LICENSE file or #
44
# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. #
55
#------------------------------------------------------------------------------------------#
6-
6+
""" File containing functions for calling Pyccel interactively (epyccel and epyccel_seq)
7+
"""
78

89
import inspect
910
import importlib
@@ -24,23 +25,37 @@
2425

2526
#==============================================================================
2627
def get_source_function(func):
28+
"""
29+
Get the source code from a function.
30+
31+
Get a string containing the source code of a function from a function
32+
object. Excessive indenting is stripped away.
33+
34+
Parameters
35+
----------
36+
func : Function
37+
A Python function.
38+
39+
Returns
40+
-------
41+
str
42+
A string containing the source code.
43+
44+
Raises
45+
------
46+
TypeError
47+
A type error is raised if the object passed to the function is not
48+
callable.
49+
"""
2750
if not callable(func):
2851
raise TypeError('Expecting a callable function')
2952

30-
lines = inspect.getsourcelines(func)
31-
lines = lines[0]
53+
lines, _ = inspect.getsourcelines(func)
3254
# remove indentation if the first line is indented
3355
a = lines[0]
3456
leading_spaces = len(a) - len(a.lstrip())
35-
code = ''
36-
for a in lines:
37-
if leading_spaces > 0:
38-
line = a[leading_spaces:]
39-
else:
40-
line = a
41-
code = '{code}{line}'.format(code=code, line=line)
4257

43-
return code
58+
return ''.join(a[leading_spaces:] for a in lines)
4459

4560
#==============================================================================
4661
def get_unique_name(prefix, path):

pyccel/commands/lambdify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sympy as sp
66
from packaging import version
77

8-
from pyccel.epyccel import epyccel
8+
from pyccel.commands.epyccel import epyccel
99
from pyccel.utilities.strings import random_string
1010

1111
if version.parse(sp.__version__) >= version.parse('1.8'):

tests/epyccel/recognised_functions/test_cmath_funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from numpy.random import rand, uniform
88
from numpy import isclose
99

10-
from pyccel.epyccel import epyccel
10+
from pyccel import epyccel
1111
from pyccel.decorators import template
1212

1313
RTOL = sys.float_info.epsilon*1000

tests/epyccel/recognised_functions/test_epyccel_pyc_math.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from numpy.random import randint, uniform
55
from numpy import isclose
66

7-
from pyccel.epyccel import epyccel
7+
from pyccel import epyccel
88

99
RTOL = 2e-14
1010
ATOL = 1e-15

tests/epyccel/recognised_functions/test_math_funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from numpy.random import rand, randint, uniform
77
from numpy import isclose
88

9-
from pyccel.epyccel import epyccel
9+
from pyccel import epyccel
1010
from pyccel.decorators import template
1111

1212

tests/epyccel/recognised_functions/test_numpy_funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88

99
from pyccel.decorators import template, types
10-
from pyccel.epyccel import epyccel
10+
from pyccel import epyccel
1111

1212
min_int8 = iinfo('int8').min
1313
max_int8 = iinfo('int8').max

tests/epyccel/recognised_functions/test_numpy_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test_numpy_funcs import matching_types
1111

1212
from pyccel.decorators import template
13-
from pyccel.epyccel import epyccel
13+
from pyccel import epyccel
1414

1515
numpy_basic_types_deprecated = tuple(int(v) for v in np.version.version.split('.'))>=(1,24,0)
1616

0 commit comments

Comments
 (0)