-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes `Standard.Base.Meta.Enso_Project.enso_project` to return a project descriptor for the *main* project, i.e., the one configured as a *root* for the engine. # Important Notes `enso_project` builtin no longer iterates the stack frames to infer the project descriptor. It derives it from the default package repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ type Example_Error_Type | |
- message: The message contained in the error type. | ||
Error message | ||
|
||
## The standard library data directory. | ||
## The data directory of the Examples project. | ||
data_dir : File | ||
data_dir = enso_project.data | ||
data_dir = | ||
this_proj = Project_Description.new Standard.Examples.Main | ||
this_proj.data | ||
|
||
## An example CSV file for experimenting with Table and its APIs. | ||
csv : File | ||
csv = enso_project.data / "food_shop_inventory.csv" | ||
csv = data_dir / "food_shop_inventory.csv" | ||
|
||
## The path to the CSV. | ||
csv_path : Text | ||
|
@@ -39,7 +41,7 @@ csv_path = csv.path | |
xls : File | ||
xls = | ||
url = "https://enso-data-samples.s3.us-west-1.amazonaws.com/spreadsheet.xls" | ||
file = enso_project.data / 'spreadsheet.xls' | ||
file = data_dir / 'spreadsheet.xls' | ||
if file.exists.not then | ||
Context.Output.with_enabled <| HTTP.fetch url . body . write file | ||
file | ||
|
@@ -54,15 +56,15 @@ xls = | |
xlsx : File | ||
xlsx = | ||
url = "https://enso-data-samples.s3.us-west-1.amazonaws.com/spreadsheet.xlsx" | ||
file = enso_project.data / 'spreadsheet.xlsx' | ||
file = data_dir / 'spreadsheet.xlsx' | ||
if file.exists.not then | ||
Context.Output.with_enabled <| HTTP.fetch url . body . write file | ||
file | ||
|
||
## A file that is used for writing temporary data as part of tests. | ||
scratch_file : File | ||
scratch_file = | ||
file = enso_project.data / "scratch_file" | ||
file = data_dir / "scratch_file" | ||
if file.exists.not then Nothing else | ||
Context.Output.with_enabled <| file.delete | ||
file | ||
|
@@ -169,7 +171,7 @@ uri = URI.parse "http://user:[email protected]/foo/bar?key=val" | |
image_file : File | ||
image_file = | ||
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Hue_alpha_falloff.png/320px-Hue_alpha_falloff.png" | ||
file = enso_project.data / "image.png" | ||
file = data_dir / "image.png" | ||
if file.exists.not then | ||
Context.Output.with_enabled <| HTTP.fetch url . body . write file | ||
file | ||
|
@@ -258,12 +260,12 @@ inventory_table = csv.read | |
## A simple table that contains basic item popularity data for the food shop. | ||
popularity_table : Table | ||
popularity_table = | ||
(enso_project.data / "food_shop_popularity.csv") . read | ||
(data_dir / "food_shop_popularity.csv") . read | ||
|
||
## A simple tablethat contains basic transaction data for the food shop. | ||
transactions_table : Table | ||
transactions_table = | ||
(enso_project.data / "food_shop_transactions.csv") . read | ||
(data_dir / "food_shop_transactions.csv") . read | ||
|
||
## An example regex match. | ||
match : Match | ||
|
125 changes: 125 additions & 0 deletions
125
...ntime-integration-tests/src/test/java/org/enso/interpreter/test/meta/EnsoProjectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package org.enso.interpreter.test.meta; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.enso.common.LanguageInfo; | ||
import org.enso.interpreter.util.ScalaConversions; | ||
import org.enso.pkg.QualifiedName; | ||
import org.enso.polyglot.PolyglotContext; | ||
import org.enso.polyglot.RuntimeOptions; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.enso.test.utils.ProjectUtils; | ||
import org.enso.test.utils.SourceModule; | ||
import org.graalvm.polyglot.Source; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class EnsoProjectTest { | ||
@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void noProjectWhenEvaluatingSingleFile() { | ||
try (var ctx = ContextUtils.createDefaultContext()) { | ||
var res = | ||
ContextUtils.evalModule( | ||
ctx, | ||
""" | ||
from Standard.Base import all | ||
from Standard.Base.Errors.Common import Module_Not_In_Package_Error | ||
main = | ||
enso_project.is_error | ||
"""); | ||
assertThat(res, notNullValue()); | ||
assertThat(res.asBoolean(), is(true)); | ||
} | ||
} | ||
|
||
@Test | ||
public void ensoProjectWorksInOneProject() throws IOException { | ||
var mainMod = | ||
new SourceModule( | ||
QualifiedName.fromString("Main"), | ||
""" | ||
from Standard.Base import all | ||
main = | ||
enso_project.name | ||
"""); | ||
var projDir = temporaryFolder.newFolder().toPath(); | ||
ProjectUtils.createProject("Proj", Set.of(mainMod), projDir); | ||
ProjectUtils.testProjectRun( | ||
projDir, | ||
(res) -> { | ||
assertThat(res.asString(), is("Proj")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void ensoProjectWorksInTwoProjects() throws IOException { | ||
var mainMod1 = | ||
new SourceModule( | ||
QualifiedName.fromString("Main"), | ||
""" | ||
from Standard.Base import all | ||
get_enso_project_name = | ||
enso_project.name | ||
"""); | ||
var mainMod2 = | ||
new SourceModule( | ||
QualifiedName.fromString("Main"), | ||
""" | ||
from local.Proj1 import get_enso_project_name | ||
main = | ||
get_enso_project_name | ||
"""); | ||
var projDir1 = temporaryFolder.newFolder().toPath(); | ||
var projDir2 = temporaryFolder.newFolder().toPath(); | ||
ProjectUtils.createProject("Proj1", Set.of(mainMod1), projDir1); | ||
ProjectUtils.createProject("Proj2", Set.of(mainMod2), projDir2); | ||
ProjectUtils.testProjectRun( | ||
projDir2, | ||
(res) -> { | ||
assertThat(res.asString(), is("Proj2")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void ensoProjectCanBeCalledFromJava() throws IOException { | ||
var mainMod = | ||
new SourceModule( | ||
QualifiedName.fromString("Main"), | ||
""" | ||
from Standard.Base import all | ||
main = | ||
42 | ||
"""); | ||
var projDir = temporaryFolder.newFolder().toPath(); | ||
ProjectUtils.createProject("Proj", Set.of(mainMod), projDir); | ||
var mainModFile = projDir.resolve("src").resolve("Main.enso"); | ||
assertThat(mainModFile.toFile().exists(), is(true)); | ||
try (var ctx = | ||
ContextUtils.defaultContextBuilder() | ||
.option(RuntimeOptions.PROJECT_ROOT, projDir.toAbsolutePath().toString()) | ||
.build()) { | ||
var mainSrc = Source.newBuilder(LanguageInfo.ID, mainModFile.toFile()).build(); | ||
// First eval the source so that everything is compiled. | ||
ctx.eval(mainSrc); | ||
var polyCtx = new PolyglotContext(ctx); | ||
var mod = polyCtx.getTopScope().getModule("Standard.Base.Meta.Enso_Project"); | ||
var assocType = mod.getAssociatedType(); | ||
var ensoProjMethod = mod.getMethod(assocType, "enso_project").get(); | ||
var projDescr = ensoProjMethod.execute(ScalaConversions.seq(List.of(assocType))); | ||
assertThat(projDescr.hasMembers(), is(true)); | ||
assertThat(projDescr.getMetaObject().getMetaSimpleName(), is("Project_Description")); | ||
assertThat(projDescr.hasMember("name"), is(true)); | ||
assertThat(projDescr.invokeMember("name").asString(), is("Proj")); | ||
} | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
...integration-tests/src/test/scala/org/enso/interpreter/test/semantic/EnsoProjectTest.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.