Skip to content

chore: clean up ahead of release #26

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

Merged
merged 10 commits into from
Jan 20, 2023
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
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[flake8]
per-file-ignores =
# ignore type hints returns in test
# Ignore type hints returns in test
tests/*: ANN201
**/__init__.py: F401
# Ignore invalid syntax in file that use python3.10
examples/pr_notifier/*: E999
extend-ignore =
# See: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html
E203,
Expand Down
1 change: 0 additions & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

3 changes: 1 addition & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The goal of the following guidelines is to have Pull Requests (PRs) that are fai

- **Pull Request title should respect [conventional commits](https://www.conventionalcommits.org/en/v1.0.0) specifications** and be clear on what is being changed.
- **Keep it readable for human reviewers** and prefer a subset of functionality (code) with tests and documentation over delivering them separately
- **Don't forget commenting code** to help reviewers understand
- **Don't forget commenting code** to help reviewers understand
- **Notify Work In Progress PRs** by prefixing the title with `[WIP]`
- **Please, keep us updated.**
We will try our best to merge your PR, but please notice that PRs may be closed after 30 days of inactivity.
Expand All @@ -63,4 +63,3 @@ Keep in mind only the **pull request title** will be used as commit message as w
See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).

Thank you for reading through all of this, if you have any question feel free to [reach us](README.md#reach-us)!

1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ labels: bug
## More info

<!-- verion of serverless-api-project used, your python version, your OS version, steps to reproduce, etc. -->

1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ labels: enhancement
<!-- e.g. @app.resource -->

### References

1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ If the change is not user facing, just write "NONE" in the release-note block be

- [ ] I have added unit test covering every changes I have made
- [ ] I have updated the relevant documentation

17 changes: 13 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
ci:
# Can't use a local installation of pylint with pre-commit.ci
skip: [pylint]

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.11.4
hooks:
- id: isort
name: isort (python)
Expand All @@ -30,7 +35,7 @@ repos:
"--rcfile=pyproject.toml",
]
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-annotations]
Expand All @@ -39,3 +44,7 @@ repos:
hooks:
- id: python-bandit-vulnerability-check
args: [--skip, "B101", --recursive, clumper]
- repo: https://github.com/regebro/pyroma
rev: "4.1"
hooks:
- id: pyroma
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def hello_world(event, context):
return "Hello World!"
```

Deploy it with `scw_serverless`:
Deploy it with `scw-serverless`:

```console
scw-serverless deploy app.py
Expand All @@ -26,10 +26,10 @@ scw-serverless deploy app.py
### Install

```console
pip install scw_serverless
pip install scw-serverless
```

This will install `scw-serverless`:
This will install the `scw-serverless` CLI:

```console
scw-serverless --help
Expand All @@ -53,7 +53,7 @@ def hello_world(event, context):
```

The configuration is done by passing arguments to the decorator.
To view which arguments are supported, head over to this [documentation](https://serverless-apifw-docs.s3-website.fr-par.scw.cloud/configuring.html) page.
To view which arguments are supported, head over to this [documentation](https://serverless-api-project.readthedocs.io/) page.

When you are ready, you can deploy your function with the `scw-serverless` CLI tool:

Expand All @@ -65,7 +65,7 @@ The tool will use your Scaleway credentials from your environment and config fil

## What’s Next?

To learn more about the framework, have a look at the [documentation](https://serverless-apifw-docs.s3-website.fr-par.scw.cloud/index.html).
To learn more about the framework, have a look at the [documentation](https://serverless-api-project.readthedocs.io/).
If you want to see it in action, we provide some [examples](https://github.com/scaleway/serverless-api-project/tree/main/examples) to get you started.

## Contributing
Expand Down
1 change: 0 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ We will follow up with you promptly with more information and a plan for remedia
We currently do not offer a paid security bounty program, but we would love to send some
Scaleway swag your way along with our deepest gratitude for your assistance in making
Scaleway a more secure Cloud ecosystem.

2 changes: 1 addition & 1 deletion examples/cron/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
inputs={"myname": "Georges"},
privacy="public",
)
def hello_cron(event: dict[str, Any], _context: dict[str, Any]):
def hello_cron(event: dict[str, Any], _context: dict[str, Any]) -> dict[str, Any]:
"""A simple cron that regularly greets you during business days."""
body = json.loads(event["body"])
my_name = body["myname"]
Expand Down
2 changes: 1 addition & 1 deletion examples/github_actions/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scw-serverless
scw-serverless~=0.0.2
40 changes: 26 additions & 14 deletions examples/pr_notifier/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def bucket_path(self) -> str:
def from_github(repository: dict[str, Any], pull_request: dict[str, Any]):
"""Creates from a GitHub PR.

.. seealso:: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
.. seealso::

GitHub Documentation
https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
"""
return PullRequest(
number=pull_request["number"],
Expand Down Expand Up @@ -191,11 +194,11 @@ def from_gitlab(
deletions=None,
)

def on_draft(self):
def on_draft(self) -> None:
"""Saves a PR marked as a draft to notify when it's ready."""
save_pr_to_bucket(self, "")

def on_created(self):
def on_created(self) -> None:
"""Sends a notification for a newly created PR."""
response = client.chat_postMessage(
channel=SLACK_CHANNEL, blocks=self._as_slack_notification()
Expand All @@ -206,13 +209,13 @@ def on_created(self):
timestamp = str(response["ts"])
save_pr_to_bucket(self, timestamp)

def on_updated(self):
def on_updated(self) -> None:
"""Performs the necessary changes when a PR is updated."""
_timestamp, pull = load_pr_from_bucket(self.bucket_path)
if pull.is_draft and not self.is_draft:
self.on_created()

def on_reviewed(self, review: Review, reviewer: Developer):
def on_reviewed(self, review: Review, reviewer: Developer) -> None:
"""Updates the notification when a new review is made."""
timestamp, pull = load_pr_from_bucket(self.bucket_path)
self.reviews = pull.reviews.copy()
Expand All @@ -233,7 +236,7 @@ def on_reviewed(self, review: Review, reviewer: Developer):
if not response["ok"]:
logging.warning(response["error"])

def on_closed(self):
def on_closed(self) -> None:
"""Sends a message in the thread when the PR is merged."""
if self.is_merged:
timestamp, _pull = load_pr_from_bucket(self.bucket_path)
Expand Down Expand Up @@ -297,19 +300,20 @@ def get_reminder_slack_blk(self, timestamp: str) -> blks.SectionBlock:
"""Gets the message to be added to the reminder."""
url = self.url
if SLACK_INSTANCE:
url = f"https://{ SLACK_INSTANCE }.slack.com/archives/{ SLACK_CHANNEL }/p{ timestamp }"
instance_url = f"https://{SLACK_INSTANCE}.slack.com"
url = f"{instance_url}/archives/{SLACK_CHANNEL}/p{timestamp}"
reminder = f"*<{url}|{self.title}>*"
return blks.SectionBlock(
text=blks.MarkdownTextObject(text=reminder, verbatim=True),
)


def delete_pr_from_bucket(bucket_path: str):
def delete_pr_from_bucket(bucket_path: str) -> None:
"""Deletes a PR."""
s3.Object(S3_BUCKET, bucket_path).delete()


def save_pr_to_bucket(pull: PullRequest, timestamp: str):
def save_pr_to_bucket(pull: PullRequest, timestamp: str) -> None:
"""Saves a PR associated with a Slack timestamp."""
s3.Object(S3_BUCKET, pull.bucket_path).put(
Body=json.dumps({"ts": timestamp, "pull_request": pull.to_dict()})
Expand All @@ -325,10 +329,13 @@ def load_pr_from_bucket(bucket_path: str) -> Tuple[str, PullRequest]:


@app.func()
def handle_github(event, _content):
def handle_github(event: dict[str, Any], _content: dict[str, Any]) -> dict[str, Any]:
"""Handles GitHub webhook request.

.. seealso:: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
.. seealso::

GitHub Events Documentation
https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
"""
body = json.loads(event["body"])
match body:
Expand Down Expand Up @@ -366,10 +373,13 @@ def handle_github(event, _content):


@app.func(min_scale=1, memory_limit=1024)
def handle_gitlab(event, _content):
def handle_gitlab(event: dict[str, Any], _content: dict[str, Any]) -> dict[str, Any]:
"""Handles GitLab webhook request.

.. seealso:: https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#merge-request-events
.. seealso::

GitLab Events Documentation
https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#merge-request-events
"""
body = json.loads(event["body"])
match body:
Expand Down Expand Up @@ -418,7 +428,9 @@ def handle_gitlab(event, _content):


@app.schedule(REMINDER_SCHEDULE)
def pull_request_reminder(_event, _content):
def pull_request_reminder(
_event: dict[str, Any], _content: dict[str, Any]
) -> dict[str, Any]:
"""Daily reminder to review opened pull-requests."""
blocks = [blks.HeaderBlock(text="PRs awaiting for review: "), blks.DividerBlock()]
for opened_pr in s3.Bucket(S3_BUCKET).objects.all():
Expand Down
2 changes: 1 addition & 1 deletion examples/pr_notifier/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
boto3~=1.26
dataclass-wizard~=0.22
scw_serverless==0.0.1b0
scw-serverless~=0.0.2
slack_sdk~=3.19
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ build-backend = "setuptools.build_meta"
name = "scw_serverless"
version = "0.0.2"
description = "An API framework to make it easy to work with Scaleway Serverless functions."
authors = [
{ name = "Scaleway Serverless Team", email = "opensource@scaleway.com" },
]
readme = "README.md"
requires-python = ">=3.9"
license = { file = "LICENSE" }
keywords = ["serverless", "scaleway", "functions", "cloud"]
keywords = ["serverless", "scaleway", "functions", "cloud", "faas"]

# Should be one of:
# 'Development Status :: 3 - Alpha'
Expand All @@ -23,12 +26,15 @@ classifiers = [
"Topic :: Internet",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

dependencies = [
"click >= 8",
"PyYAML >= 6",
"scaleway >= 0.2",
"scaleway >= 0.5",
# Requires support for pyproject.toml
"setuptools >= 61",
"requests >= 2",
Expand All @@ -43,9 +49,8 @@ repository = "https://github.com/scaleway/serverless-api-project"
scw-serverless = "scw_serverless.cli:main"

[tool.setuptools]
# Using: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#flat-layout
include-package-data = true
# See: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#flat-layout
packages = ["scw_serverless"]

[tool.setuptools.package-data]
scw_serverless = ["**/*.json", "**/*.yml"]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
click==8.1.3
PyYAML==6.0
scaleway==0.2.0
scaleway==0.5.0
setuptools==66.0.0
requests==2.28.2
typing_extensions==4.4.0
14 changes: 6 additions & 8 deletions scw_serverless/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
from typing import Any, Callable, List, Optional, Union

from typing_extensions import Unpack

if TYPE_CHECKING:
try:
from typing import Unpack
except ImportError:
from typing_extensions import Unpack
try:
from typing import Unpack
except ImportError:
from typing_extensions import Unpack
# pylint: disable=wrong-import-position # Conditional import considered a statement

from scw_serverless.config.function import Function, FunctionKwargs
from scw_serverless.config.route import HTTPMethod
from scw_serverless.triggers import CronTrigger
Expand Down
8 changes: 6 additions & 2 deletions scw_serverless/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
),
)

# TODO: link to the doc

@click.group()
def cli() -> None:
"""Deploy your Serverless functions on Scaleway's Cloud."""
"""Deploy your Serverless functions on Scaleway's Cloud.

Documentation:
https://serverless-api-project.readthedocs.io/en/latest/
"""


# TODO?: clean up the locals by introducing a class
Expand Down
6 changes: 4 additions & 2 deletions scw_serverless/config/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class FunctionKwargs(TypedDict):
:param timeout: Max duration to respond to a request.
:param description: Description. Defaults to the function docstring if defined.
:param http_option: Either "enabled" or "redirected".
If "redirected" (default), redirects http traffic to your function.
If "redirected" (default), allow http traffic to your function.
Blocked otherwise.
.. seealso:: https://developers.scaleway.com/en/products/functions/api/#create-a-function
.. seealso::

Scaleway Developers Documentation
https://developers.scaleway.com/en/products/functions/api/#create-a-function
"""

env: NotRequired[dict[str, str]]
Expand Down
5 changes: 4 additions & 1 deletion scw_serverless/config/generators/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def from_serverless(serverless: Serverless):
class TerraformGenerator(Generator):
"""Generates the Terraform configuration to deploy the functions.

.. seealso:: https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/function
.. seealso::

Scaleway Terraform Provider Documentation:
https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/function
"""

def __init__(self, instance: Serverless, deps_manager: DependenciesManager):
Expand Down
Loading