Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,52 @@ jobs:
which node
node -v
node src/lpython/tests/test_lpython.js

test_pip_pkgs:
name: Test PIP Installable Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: mamba-org/provision-with-micromamba@v15
with:
environment-file: ci/environment.yml
extra-specs: |
bison=3.4

- uses: hendrikmuhs/ccache-action@main
with:
variant: sccache
key: ${{ github.job }}-${{ matrix.os }}

- name: Setup Platform (Linux)
shell: bash -l {0}
run: |
echo "LFORTRAN_CMAKE_GENERATOR=Unix Makefiles" >> $GITHUB_ENV
echo "WIN=0" >> $GITHUB_ENV
echo "MACOS=0" >> $GITHUB_ENV
echo "ENABLE_RUNTIME_STACKTRACE=yes" >> $GITHUB_ENV

- name: Build Linux
shell: bash -l {0}
run: |
xonsh ci/build.xsh

- name: PIP install required packages
shell: bash -l {0}
run: |
python -m pip install lptypes lpynn numpy

- name: Test PIP Pacakges with Python
shell: bash -l {0}
run: |
python integration_tests/test_pip_import_01.py

- name: Test PIP Pacakges with LPython
shell: bash -l {0}
run: |
pip_pkg_path=$(python -c "import site; print(site.getsitepackages()[0])")
echo $pip_pkg_path
./src/bin/lpython integration_tests/test_pip_import_01.py -I $pip_pkg_path
39 changes: 39 additions & 0 deletions integration_tests/test_pip_import_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from lpynn.perceptron import init_perceptron, print_perceptron, normalize_input_vectors, Perceptron, train_dataset
from lptypes import i32, f64

def main0():
p: Perceptron = Perceptron(0, [0.0], 0.0, 0, 0.0, 0.0, 0)
init_perceptron(p, 2, 0.05, 10000, 90.0)
print_perceptron(p)
print("=================================")

input_vectors: list[list[f64]] = [[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0]]
outputs: list[i32] = [1, 1, 1, -1]

normalize_input_vectors(input_vectors)
train_dataset(p, input_vectors, outputs)
print_perceptron(p)
print("=================================")

assert p.cur_accuracy > 50.0
assert p.epochs_cnt > 1

def main1():
p: Perceptron = Perceptron(0, [0.0], 0.0, 0, 0.0, 0.0, 0)
init_perceptron(p, 2, 0.05, 10000, 90.0)
print_perceptron(p)
print("=================================")

input_vectors: list[list[f64]] = [[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [1.5, 1.0]]
outputs: list[i32] = [1, 1, -1, 1, -1]

normalize_input_vectors(input_vectors)
train_dataset(p, input_vectors, outputs)
print_perceptron(p)
print("=================================")

assert p.cur_accuracy > 50.0
assert p.epochs_cnt > 1

main0()
main1()
30 changes: 16 additions & 14 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ Result<std::string> get_full_path(const std::string &filename,
return file_path;
} else {
// If this is `lpython`, do a special lookup
if (filename == "lpython.py") {
file_path = runtime_library_dir + "/lpython/" + filename;
if (filename == "lpython.py" || filename == "lptypes.py") {
file_path = runtime_library_dir + "/lpython/" + "lpython.py";
status = read_file(file_path, input);
if (status) {
lpython = true;
Expand Down Expand Up @@ -3622,19 +3622,10 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
in any directory other than src/runtime will also
be ignored.
*/
if (mod_sym == "lpython") {
if (mod_sym == "lpython" || mod_sym == "lptypes" || mod_sym == "numpy") {
return ;
}

/*
If import_path is not empty then insert it
in the second priority. Top priority path
is runtime library path.
*/
for( auto& path: import_paths ) {
paths.push_back(path);
}

/*
Search all the paths in order and stop
when the desired module is found.
Expand Down Expand Up @@ -3696,7 +3687,13 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
if (!t) {
std::string rl_path = get_runtime_library_dir();
SymbolTable *st = current_scope;
std::vector<std::string> paths = {rl_path, parent_dir};
std::vector<std::string> paths;
for (auto &path:import_paths) {
paths.push_back(path);
}
paths.push_back(rl_path);
paths.push_back(parent_dir);

if (!main_module) {
st = st->parent;
}
Expand Down Expand Up @@ -3746,7 +3743,12 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
void visit_Import(const AST::Import_t &x) {
ASR::symbol_t *t = nullptr;
std::string rl_path = get_runtime_library_dir();
std::vector<std::string> paths = {rl_path, parent_dir};
std::vector<std::string> paths;
for (auto &path:import_paths) {
paths.push_back(path);
}
paths.push_back(rl_path);
paths.push_back(parent_dir);
SymbolTable *st = current_scope;
std::vector<std::string> mods;
for (size_t i=0; i<x.n_names; i++) {
Expand Down