forked from mage-ai/mage-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2048e6a
commit c6c43ee
Showing
36 changed files
with
1,040 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,3 +159,6 @@ docker-compose.override.yml | |
|
||
# vscode | ||
.vscode/ | ||
|
||
# front-end | ||
node_modules |
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,66 @@ | ||
--- | ||
title: "Project setup" | ||
description: "How to set up a folder containing your Mage project code and other files." | ||
--- | ||
|
||
## Parent folder | ||
|
||
Create a parent folder that will contain your Mage project code: | ||
|
||
```bash | ||
mkdir data_monorepo | ||
``` | ||
|
||
Change directory into the parent folder: | ||
|
||
```bash | ||
cd data_monorepo | ||
``` | ||
|
||
## Create a Dockerfile | ||
|
||
Create an empty Dockerfile: | ||
|
||
```bash | ||
echo "" > Dockerfile | ||
``` | ||
|
||
Paste the contents from this [Dockerfile](https://github.com/mage-ai/docker/blob/master/Dockerfile) | ||
into the Dockerfile you just created. | ||
|
||
## Create a .gitignore file | ||
|
||
Create an empty .gitignore file: | ||
|
||
```bash | ||
echo "" > .gitignore | ||
``` | ||
|
||
Paste the following contents into the .gitignore file you just created: | ||
|
||
``` | ||
.DS_Store | ||
.gitkeep | ||
.log | ||
.logs/ | ||
.variables/ | ||
__pycache__/ | ||
docker-compose.override.yml | ||
logs/ | ||
mage-ai.db | ||
mage_data/ | ||
secrets/ | ||
``` | ||
|
||
## Create Mage project | ||
|
||
Follow these [instructions](/getting-started/setup) to create a Mage project in your | ||
current directory. If you named your project `demo_project`, your current folder structure | ||
will look like this: | ||
|
||
``` | ||
data_monorepo/ | ||
|-- demo_project/ | ||
|-- .gitignore | ||
|-- Dockerfile | ||
``` |
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from mage_ai.api.oauth_scope import OauthScope | ||
from mage_ai.api.operations import constants | ||
from mage_ai.api.policies.BasePolicy import BasePolicy | ||
from mage_ai.api.presenters.FilePresenter import FilePresenter | ||
|
||
|
||
class FilePolicy(BasePolicy): | ||
pass | ||
|
||
|
||
FilePolicy.allow_actions([ | ||
constants.CREATE, | ||
constants.LIST, | ||
], scopes=[ | ||
OauthScope.CLIENT_PRIVATE, | ||
]) | ||
|
||
FilePolicy.allow_read([] + FilePresenter.default_attributes, scopes=[ | ||
OauthScope.CLIENT_PRIVATE, | ||
], on_action=[ | ||
constants.CREATE, | ||
constants.LIST, | ||
]) | ||
|
||
FilePolicy.allow_write([ | ||
'dir_path', | ||
'name', | ||
'overwrite', | ||
], scopes=[ | ||
OauthScope.CLIENT_PRIVATE, | ||
], on_action=[ | ||
constants.CREATE, | ||
]) |
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,10 @@ | ||
from mage_ai.api.presenters.BasePresenter import BasePresenter | ||
|
||
|
||
class FilePresenter(BasePresenter): | ||
default_attributes = [ | ||
'children', | ||
'disabled', | ||
'name', | ||
'path', | ||
] |
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,44 @@ | ||
from mage_ai.api.errors import ApiError | ||
from mage_ai.api.resources.GenericResource import GenericResource | ||
from mage_ai.data_preparation.models.errors import FileExistsError | ||
from mage_ai.data_preparation.models.file import File | ||
from mage_ai.data_preparation.repo_manager import get_repo_path | ||
from typing import Dict | ||
|
||
|
||
class FileResource(GenericResource): | ||
@classmethod | ||
def collection(self, query, meta, user, **kwargs): | ||
return self.build_result_set( | ||
[File.get_all_files(get_repo_path())], | ||
user, | ||
**kwargs, | ||
) | ||
|
||
@classmethod | ||
def create(self, payload: Dict, user, **kwargs) -> 'FileResource': | ||
dir_path = payload['dir_path'] | ||
repo_path = get_repo_path() | ||
content = None | ||
|
||
if 'file' in payload: | ||
file = payload['file'][0] | ||
filename = file['filename'] | ||
content = file['body'] | ||
else: | ||
filename = payload['name'] | ||
|
||
try: | ||
file = File.create( | ||
filename, | ||
dir_path, | ||
repo_path=repo_path, | ||
content=content, | ||
overwrite=payload.get('overwrite', False), | ||
) | ||
|
||
return self(file.to_dict(), user, **kwargs) | ||
except FileExistsError as err: | ||
error = ApiError.RESOURCE_INVALID.copy() | ||
error.update(dict(message=str(err))) | ||
raise ApiError(error) |
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,7 @@ | ||
from mage_ai.api.resources.BaseResource import BaseResource | ||
|
||
class GenericResource(BaseResource): | ||
def __getattr__(self, name): | ||
def _missing(*args, **kwargs): | ||
return self.model.get(name) | ||
return _missing() |
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
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,5 @@ | ||
from mage_ai.errors.base import MageBaseException | ||
|
||
|
||
class FileExistsError(MageBaseException): | ||
pass |
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
Oops, something went wrong.