Skip to content

Commit

Permalink
chore: add pre-commit lint to remove trailing whitespace (#104)
Browse files Browse the repository at this point in the history
* chore: add pre-commit lint to remove trailing whitespace

* use ruff instead of tox
  • Loading branch information
vincentsarago committed May 14, 2024
1 parent c7a4b0e commit 0f25752
Show file tree
Hide file tree
Showing 38 changed files with 198 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "VS Code DEV Container for AWS CDK development",
"image": "jsii/superchain:1-buster-slim-node16"
}
}
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## :warning: Checklist if your PR is changing anything else than documentation
- [ ] Posted the link to a successful manually triggered deployment workflow (successful including the resources destruction)

## Merge request description
## Merge request description
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
required: false
DS_RELEASE_BOT_PRIVATE_KEY:
required: false

jobs:
build_and_package:
name: Build and package
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deployment

on:
workflow_dispatch:

jobs:
build_package_and_deploy:
name: Build, package and deploy
Expand Down Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Generate distribution packages
run: npm run package


- name: Install deployment environment
id: install_deploy_env
run: |
Expand All @@ -40,7 +40,7 @@ jobs:
pip install dist/python/*.gz
cd integration_tests/cdk
pip install -r requirements.txt
npm install
npm install
deactivate
cd -
Expand All @@ -56,7 +56,7 @@ jobs:
PROJECT_ID: ${{ steps.short-sha.outputs.sha }}
run: |
source .deployment_venv/bin/activate
# synthesize the stack
cd integration_tests/cdk
npx cdk synth --debug --all --require-approval never
Expand All @@ -65,7 +65,7 @@ jobs:
npx cdk deploy --ci --all --require-approval never
deactivate
cd -
- name: Tear down any infrastructure
if: always()
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/distribute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
name: python
path: dist

- run: pip install twine

- run: twine upload dist/*
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint

on:
push:
branches:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
8 changes: 5 additions & 3 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.9]
python: [3.11]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install Tox and any other packages
run: pip install tox

- name: Run Tox
# Run tox using the version of Python in `PATH`
run: tox -e py
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ __pycache__
.tox
tests/*.egg*
tests/*venv*
tests/__pycache__
tests/__pycache__
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

# Optionally both commit and push
default_stages: [commit]

# Regex for files to exclude
# Don't lint the generated JSON metadata files
exclude: "diagrams/"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ _Warning_: If you rebase `main`, you must ensure that the commits referenced by

## Tests

Each pull request to `main` is added to a [merge queue](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue#triggering-merge-group-checks-with-github-actions) so that a "deployment test" workflow can run before the merge actually happens. If the deployment fails, the merge is cancelled. Here is [the definition of this workflow](https://github.com/developmentseed/eoapi-cdk/blob/main/.github/workflows/deploy.yaml) and the [tests definition](https://github.com/developmentseed/eoapi-cdk/blob/main/tests).
Each pull request to `main` is added to a [merge queue](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue#triggering-merge-group-checks-with-github-actions) so that a "deployment test" workflow can run before the merge actually happens. If the deployment fails, the merge is cancelled. Here is [the definition of this workflow](https://github.com/developmentseed/eoapi-cdk/blob/main/.github/workflows/deploy.yaml) and the [tests definition](https://github.com/developmentseed/eoapi-cdk/blob/main/tests).
10 changes: 5 additions & 5 deletions integration_tests/cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ This is a wrapper CDK code that is used to test a deployment of the `eoapi-cdk`
- python
- docker
- node
- AWS credentials environment variables configured to point to an account.
- AWS credentials environment variables configured to point to an account.

## Installation

Install python dependencies with
Install python dependencies with

```
python -m venv .venv
Expand All @@ -28,7 +28,7 @@ pip install eoapi-cdk

Or alternatively, compile and package from the root of this repository to get the python version of the constructs locally.

Also install node dependencies with
Also install node dependencies with

```
npm install
Expand All @@ -42,7 +42,7 @@ npx cdk --version

## Deployment

First, synthesize the app
First, synthesize the app

```
npx cdk synth --all
Expand All @@ -52,4 +52,4 @@ Then, deploy

```
npx cdk deploy --all --require-approval never
```
```
34 changes: 11 additions & 23 deletions integration_tests/cdk/app.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
from config import build_app_config, AppConfig
from aws_cdk import (
Stack,
aws_ec2,
aws_rds,
App,
RemovalPolicy
)
from aws_cdk import App, RemovalPolicy, Stack, aws_ec2, aws_rds
from config import AppConfig, build_app_config
from constructs import Construct
from eoapi_cdk import (
PgStacApiLambda,
PgStacDatabase,
TitilerPgstacApiLambda,
TiPgApiLambda,
TitilerPgstacApiLambda,
)


class VpcStack(Stack):
def __init__(self, scope: Construct, app_config: AppConfig, id: str, **kwargs) -> None:
super().__init__(
scope,
id=id,
tags=app_config.tags,
**kwargs
)
def __init__(
self, scope: Construct, app_config: AppConfig, id: str, **kwargs
) -> None:
super().__init__(scope, id=id, tags=app_config.tags, **kwargs)

self.vpc = aws_ec2.Vpc(
self,
Expand All @@ -31,7 +22,7 @@ def __init__(self, scope: Construct, app_config: AppConfig, id: str, **kwargs) -
aws_ec2.SubnetConfiguration(
name="ingress", subnet_type=aws_ec2.SubnetType.PUBLIC, cidr_mask=24
),
]
],
)

self.vpc.add_interface_endpoint(
Expand Down Expand Up @@ -88,7 +79,7 @@ def __init__(
),
allocated_storage=app_config.db_allocated_storage,
instance_type=aws_ec2.InstanceType(app_config.db_instance_type),
removal_policy=RemovalPolicy.DESTROY
removal_policy=RemovalPolicy.DESTROY,
)

pgstac_db.db.connections.allow_default_port_from_any_ipv4()
Expand All @@ -101,7 +92,7 @@ def __init__(
"description": f"{app_config.stage} STAC API",
},
db=pgstac_db.db,
db_secret=pgstac_db.pgstac_secret
db_secret=pgstac_db.pgstac_secret,
)

TitilerPgstacApiLambda(
Expand Down Expand Up @@ -145,10 +136,7 @@ def __init__(
pgstac_infra_stack_id = f"pgstac{app_config.project_id}"

pgstac_infra_stack = pgStacInfraStack(
scope=app,
vpc=vpc_stack.vpc,
app_config=app_config,
id=pgstac_infra_stack_id
scope=app, vpc=vpc_stack.vpc, app_config=app_config, id=pgstac_infra_stack_id
)

app.synth()
2 changes: 1 addition & 1 deletion integration_tests/cdk/cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"aws-cn"
]
}
}
}
12 changes: 3 additions & 9 deletions integration_tests/cdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@


class AppConfig(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env"
)
aws_default_account: str = pydantic.Field(
description="AWS account ID"
)
project_id: str = pydantic.Field(
description="Project ID", default="eoapicdk"
)
model_config = SettingsConfigDict(env_file=".env")
aws_default_account: str = pydantic.Field(description="AWS account ID")
project_id: str = pydantic.Field(description="Project ID", default="eoapicdk")
stage: str = pydantic.Field(description="Stage of deployment", default="test")
# because of its validator, `tags` should always come after `project_id` and `stage`
tags: Dict[str, str] | None = pydantic.Field(
Expand Down
1 change: 0 additions & 1 deletion integration_tests/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
"aws-cdk": "2.130.0"
}
}

22 changes: 10 additions & 12 deletions lib/database/bootstrapper_runtime/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def handler(event, context):
)
with psycopg.connect(eoapi_db_admin_conninfo, autocommit=True) as conn:
with conn.cursor() as cur:
print(
f"Registering Extension in '{eoapi_params['dbname']}' database..."
)
print(f"Registering Extension in '{eoapi_params['dbname']}' database...")
register_extensions(cursor=cur)

print("Starting PgSTAC Migration ")
Expand Down Expand Up @@ -247,18 +245,18 @@ def handler(event, context):
customization(cursor=cur, params=params)

# Make sure the user can access the database
eoapi_user_dsn = (
"postgresql://{user}:{password}@{host}:{port}/{dbname}".format(
dbname=eoapi_params["dbname"],
user=eoapi_params["username"],
password=eoapi_params["password"],
host=admin_params["host"],
port=admin_params["port"],
)
eoapi_user_dsn = "postgresql://{user}:{password}@{host}:{port}/{dbname}".format(
dbname=eoapi_params["dbname"],
user=eoapi_params["username"],
password=eoapi_params["password"],
host=admin_params["host"],
port=admin_params["port"],
)
print("Checking eoAPI user access to the PgSTAC database...")
with PgstacDB(dsn=eoapi_user_dsn, debug=True) as pgdb:
print(f" OK - User has access to pgstac db, pgstac schema version: {pgdb.version}")
print(
f" OK - User has access to pgstac db, pgstac schema version: {pgdb.version}"
)

except Exception as e:
print(f"Unable to bootstrap database with exception={e}")
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export * from "./stac-api";
export * from "./titiler-pgstac-api";
export * from "./stac-browser";
export * from "./tipg-api";
export * from "./utils";
export * from "./utils";

0 comments on commit 0f25752

Please sign in to comment.