Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces a simple package manager for aya. Aya can now download and install packages from the web and use them like regular libraries
This PR also includes major changes to
importlib
andimport
statements. See below for more information.Demo
Example package (spec below): https://github.com/nick-paul/sample.aya
Aya's package manager is intended to be used directly in the REPL. To use the package manager, first import it:
Install a package
Install from a github stub or directly with a zip URL
Can also use direct zip URL if hosted elsewhere
Now you can import the package normally:
List installed packages
Run package tests
Run package entrypoint
This is useful if a package is intended to be a standalone app or demo instead of a library
Update an existing package
Remove a package
Package development
No specific commands exist for developing a package yet but you can simply create a repo in the
pkg/
folder and it will be available.pkg.init
to add files (pkg.aya, package.json, src/, ect) when creating a packagePackage Spec
What is an aya package?
Example: nick-paul/sample.aya
More complicated example: nick-paul/trimesh.aya
__pkg__.aya
: The entrypoint for the package. This file should bring package variables into scope. It should generally only have import/require statements in itpackage.json
: Package metadataname
: The package name.aya
extensionversion
: Version ismajor.minor.patch
formatauthor
: Package authorsrc/
: Location of aya source filestest/
: Location of aya test files. All aya files in this folder will be ran when usingpkg.test
Changes to
importlib
importlib
now defines two global keywords: import & requireimport
import <module>
: import the module and assign it to the module nameExample
Assume "sample.aya" has variables "foo" and "bar"
import sample
will define the variablesample
to the dict:{ ...:foo ...:bar}
.Use
sample.foo
&sample.bar
to access imported namesValid import statements
Standard imports: Search for files in "<importlib._path>/.aya"
import "example"
import "example.aya"
(extension optional, no extension preferred)Relative imports: Search for files relative to the file with the import statement
import ".relative"
import ".relative.aya"
(extension optional, no extension preferred)import ".src/relative.aya"
Package imports: If the import points to a directory, it will look for
<path>/__pkg__.aya
import "src/package"
(assumessrc/package/__pkg__.aya
exists)Identifier imports: Identifiers will be converted to strings before importing
import example
(same as import "example")import .example
(ERROR: Will import "example" not ".example")a nomal aya expression
import foo.bar
(Parsed as{(import foo) .bar}
)import foo/bar
(Parsed as{(import foo) / bar}
)Multiple imports: Wrap multiple imports in a block
import {foo bar}
import {example "./src/foo"}
(same rules as above apply, can be an identifier or string)require
Require is similar to import but imports names directly into the current scope.
You can specify which names to import or import all with a wildcard.
When using the wildcard, names with a leading underscore will not be imported
Example
Assume "sample.aya" has variables "foo", "bar", and "_baz"
require sample {foo}
will bringfoo
into the current scope.sample
andsample.bar
are undefinedrequire sample {foo bar}
will bringfoo
andbar
into the current scoperequire sample *
will bringfoo
andbar
into the current scope._baz
will not be importedsince it has a leading underscore
require sample {foo _baz}
will bringfoo
and_baz
into the current scope even though _baz has a leading underscoreValid require statements
require math {sin cos tan}
require ".math" {sin cos tan}
require "math" {"sin" "cos" "tan"}
require "./src/math" {"sin" "cos" "tan"}
*
will bring all variables that do not start with a leading_
into scoperequire math *
require "./src/math" *