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

Tighten GraphQL definition of environment type #43

Merged
merged 2 commits into from
Feb 7, 2024
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ Run [MkDocs] server to view documentation:
poetry run mkdocs serve
```

To generate a GraphQL schema file:

```
poetry run strawberry export-schema softpack_core.graphql:GraphQL.schema > schema.graphql
```


[pip]: https://pip.pypa.io
[Python installation guide]: http://docs.python-guide.org/en/latest/starting/installation/
Expand Down
12 changes: 10 additions & 2 deletions softpack_core/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
failed = 'failed'


@strawberry.enum
class Type(Enum):
"""Environment types."""

softpack = "softpack"
module = "module"


class Artifacts:
"""Artifacts repo access class."""

Expand All @@ -65,9 +73,9 @@
module_file = "module"
readme_file = "README.md"
built_by_softpack_file = ".built_by_softpack"
built_by_softpack = "softpack"
built_by_softpack = Type.softpack.value
generated_from_module_file = ".generated_from_module"
generated_from_module = "module"
generated_from_module = Type.module.value
users_folder_name = "users"
groups_folder_name = "groups"
credentials_callback = None
Expand Down Expand Up @@ -133,7 +141,7 @@
if Artifacts.module_file in self.obj:
info["state"] = State.ready
elif Artifacts.builder_out in self.obj:
info["state"] = State.failed

Check warning on line 144 in softpack_core/artifacts.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/artifacts.py#L144

Added line #L144 was not covered by tests
else:
info["state"] = State.queued

Expand Down Expand Up @@ -207,7 +215,7 @@
def signature(self) -> pygit2.Signature:
"""Get current pygit2 commit signature: author/committer/timestamp."""
# creating one of these implicitly looks up the current time.
return pygit2.Signature(

Check warning on line 218 in softpack_core/artifacts.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/artifacts.py#L218

Added line #L218 was not covered by tests
self.settings.artifacts.repo.author,
self.settings.artifacts.repo.email,
)
Expand Down
4 changes: 2 additions & 2 deletions softpack_core/schemas/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from strawberry.file_uploads import Upload

from softpack_core.app import app
from softpack_core.artifacts import Artifacts, Package, State
from softpack_core.artifacts import Artifacts, Package, State, Type
from softpack_core.module import GenerateEnvReadme, ToSoftpackYML
from softpack_core.schemas.base import BaseSchema

Expand Down Expand Up @@ -158,7 +158,7 @@
return InvalidInputError(message="all fields must be filled in")

if not re.fullmatch(r"^[a-zA-Z0-9_-]+$", self.name):
return InvalidInputError(

Check warning on line 161 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L161

Added line #L161 was not covered by tests
message="name must only contain alphanumerics, "
"dash, and underscore"
)
Expand Down Expand Up @@ -196,7 +196,7 @@
path: str
description: str
readme: str
type: str
type: Type
packages: list[Package]
state: Optional[State]
artifacts = Artifacts()
Expand Down Expand Up @@ -247,15 +247,15 @@
Returns:
A message confirming the success or failure of the operation.
"""
input_err = env.validate()

Check warning on line 250 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L250

Added line #L250 was not covered by tests
if input_err is not None:
return input_err

Check warning on line 252 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L252

Added line #L252 was not covered by tests

versionless_name = env.name

Check warning on line 254 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L254

Added line #L254 was not covered by tests
version = 1

while True:
env.name = versionless_name + "-" + str(version)

Check warning on line 258 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L258

Added line #L258 was not covered by tests
response = cls.create_new_env(
env, Artifacts.built_by_softpack_file
)
Expand All @@ -268,9 +268,9 @@
version += 1

# Send build request
try:
host = app.settings.builder.host
port = app.settings.builder.port

Check warning on line 273 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L271-L273

Added lines #L271 - L273 were not covered by tests
r = httpx.post(
f"http://{host}:{port}/environments/build",
json={
Expand All @@ -288,10 +288,10 @@
},
},
)
r.raise_for_status()
except Exception as e:
cls.delete(env.name, env.path)
return BuilderError(

Check warning on line 294 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L291-L294

Added lines #L291 - L294 were not covered by tests
message="Connection to builder failed: "
+ "".join(format_exception_only(type(e), e))
)
Expand Down Expand Up @@ -347,9 +347,9 @@
for pkg in env.packages
],
)
ymlData = yaml.dump(softpack_definition)

Check warning on line 350 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L350

Added line #L350 was not covered by tests

tree_oid = cls.artifacts.create_files(

Check warning on line 352 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L352

Added line #L352 was not covered by tests
new_folder_path,
[
(env_type, ""), # e.g. .built_by_softpack
Expand All @@ -361,7 +361,7 @@
tree_oid, "create environment folder"
)
except RuntimeError as e:
return InvalidInputError(

Check warning on line 364 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L364

Added line #L364 was not covered by tests
message="".join(format_exception_only(type(e), e))
)

Expand Down Expand Up @@ -572,13 +572,13 @@
tree_oid = cls.artifacts.create_files(
Path(folder_path), new_files, overwrite=True
)
cls.artifacts.commit_and_push(tree_oid, "write artifact")

Check warning on line 575 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L575

Added line #L575 was not covered by tests
return WriteArtifactSuccess(
message="Successfully written artifact(s)",
)

except Exception as e:
return InvalidInputError(

Check warning on line 581 in softpack_core/schemas/environment.py

View check run for this annotation

Codecov / codecov/patch

softpack_core/schemas/environment.py#L581

Added line #L581 was not covered by tests
message="".join(format_exception_only(type(e), e))
)

Expand Down
Loading