Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open python files #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
24 changes: 12 additions & 12 deletions tests/data/Valid.wml
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,25 @@
"id": "67188218-7988-45b2-9cdf-a95897f40eb4",
"orientation": 0,
"ports": {
"port1": {
"id": "port1",
"in_port": {
"id": "in_port",
"position": {
"x": 100,
"y": 0
},
"properties": {
"custom": "property"
"value": "in"
},
"type": "top"
},
"port2": {
"id": "port2",
"out_port": {
"id": "out_port",
"position": {
"x": 100,
"y": 80
},
"properties": {
"custom": "property"
"value": "out"
},
"type": "bottom"
}
Expand Down Expand Up @@ -502,22 +502,22 @@
"orientation": 0,
"type": "BashOperator",
"ports": {
"port1": {
"id": "port1",
"in_port": {
"id": "in_port",
"type": "top",
"properties": {
"custom": "property"
"value": "in"
},
"position": {
"x": 100,
"y": 0
}
},
"port2": {
"id": "port2",
"out_port": {
"id": "out_port",
"type": "bottom",
"properties": {
"custom": "property"
"value": "out"
},
"position": {
"x": 100,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dag_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def tearDown(self):
class TestDagToDagHandler(Fixture):
def test_valid_pyfile(self):
dag_file_handler = DagFileHandler(self.testfile, self.conf)
dags = dag_file_handler.dags
dag = dag_file_handler.dag

assert len(dags) == 1
# assert dags[0].dag_id == "ValidDag"
# assert len(dags) == 1
assert dag.dag_id == "ValidDag"
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist = True
envlist = py36, py37, lint
envlist = py36, py37, py38, lint

[testenv]
whitelist_externals = poetry
Expand Down
51 changes: 42 additions & 9 deletions windmill/http/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ...config.project_config import ProjectConfig
from ...exceptions import DagHandlerValidationError
from ...models.dags.dag_handler import DagHandler
from ...models.dags.dag_handler import DagHandler, DagFileHandler
from ...models.operators.operator_index import get_operator_index
from ...models.schemas.app_schemas import OperatorSchema, MinimalWmlSchema

Expand Down Expand Up @@ -49,15 +49,48 @@ def get_wmls(name=None):
logging.info(f"GET /v1/wml/{name}")

if name:
f_path = os.path.join(app.config["project_conf"].wml_dir, name)
if os.path.exists(f_path):
with open(f_path, "r") as f:
data = json.load(f)
return jsonify(data), 200
else:
return f"File {f_path} not found", 404
if os.path.splitext(name)[1] == ".wml":
f_path = os.path.join(app.config["project_conf"].wml_dir, name)
if os.path.exists(f_path):
try:
with open(f_path, "r") as f:
data = json.load(f)
return jsonify(data), 200
except TypeError as e:
logging.exception(f"Unable to parse WML file {f_path}")
return (
f"Unable to parse WML file {f_path} - internal state corrupted",
400,
)
except Exception as e:
logging.exception(f"Unable to parse WML file {f_path}")
return f"Internal error parsing WML", 400
else:
return f"File {f_path} not found", 404
elif os.path.splitext(name)[1] == ".py":
try:
dh = DagFileHandler(name, app.config["project_conf"])
return jsonify(dh.wml), 200
except DagHandlerValidationError as e:
logging.exception(f"Unable to parse python file {name}")
return f"Unable to parse python file {name}: {e}", 400
except FileNotFoundError:
return f"File {name} not found", 404
except Exception as e:
logging.exception(f"Unknown error parsing Python file {name}")
return f"Internal error parsing Python", 500
else:
return jsonify(os.listdir(app.config["project_conf"].wml_dir)), 200
return (
jsonify(
[
f
for f in os.listdir(app.config["project_conf"].wml_dir)
+ os.listdir(app.config["project_conf"].dags_dir)
if f.endswith(".wml") or f.endswith(".py")
]
),
200,
)


@app.route("/v1/wml/<name>", methods=["POST"])
Expand Down
Loading