Skip to content

Commit 0f18c60

Browse files
committed
Merge branch 'main' into tests_for_post_usage
2 parents ba29785 + 10f1115 commit 0f18c60

28 files changed

+2317
-2192
lines changed

.github/workflows/linter.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
uses: abatilo/actions-poetry@v3
3131

3232
- name: Configure poetry
33+
shell: bash
3334
run: poetry config virtualenvs.in-project true
3435

3536
- name: Set up cache
@@ -44,8 +45,13 @@ jobs:
4445
run: poetry check --lock
4546

4647
- name: Install dependencies
48+
shell: bash
4749
run: poetry install --all-extras
4850

51+
- name: Ready the MyPy Cache
52+
shell: bash
53+
run: mkdir .mypy_cache
54+
4955
- uses: pre-commit/[email protected]
5056
env:
5157
SAFETY_API_KEY: ${{ secrets.SAFETY_API_KEY }}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
uses: abatilo/actions-poetry@v3
4646

4747
- name: Install dependencies
48-
run: poetry install
48+
run: poetry install --all-extras
4949

5050
- name: Run main tests
5151
shell: bash

.pre-commit-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ repos:
3838
entry: poetry run mypy --install-types --non-interactive
3939
language: system
4040
types: ['python']
41-
exclude: ^alembic/
4241
- id: pylint
4342
name: Pylint
4443
entry: poetry run pylint --rcfile=.python-lint
4544
language: system
4645
types: ['python']
47-
exclude: ^alembic/
4846
- id: flake8
4947
name: Flake8
5048
entry: poetry run flake8
@@ -62,7 +60,6 @@ repos:
6260
language: system
6361
types: ['python']
6462
exclude: (?x)(
65-
alembic|
6663
tests|
6764
scripts
6865
)

.python-lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
203203
# and thus existing member attributes cannot be deduced by static analysis). It
204204
# supports qualified module names, as well as Unix pattern matching.
205205
# We ignore Pulumi modules since we don't list them in pyproject.toml.
206-
ignored-modules=pulumi,pulumi_random,pulumi_azure_native,pulumi_postgresql
206+
ignored-modules=
207207

208208
# Show a hint with possible names when a member name was not found. The aspect
209209
# of finding the hint is based on edit distance.

.safety-policy.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ report:
1919
vulnerabilities:
2020
64459:
2121
reason: Python wide vulnerability.
22-
expires: '2024-12-12'
22+
expires: '2025-12-12'
2323
64396:
2424
reason: Python wide vulnerability.
25-
expires: '2024-12-12'
26-
67599:
27-
reason: Only applies if using private package repo.
28-
expires: '2026-04-17'
25+
expires: '2025-12-12'
2926
51668:
3027
reason: We cannot currently use SQL Alchemy v2.
31-
expires: '2024-12-12'
32-
70612:
33-
reason: We do not use untrusted templates that would require the from_string() method.
34-
expires: '2024-12-12'
28+
expires: '2025-12-12'
3529

3630

3731
fail-scan-with-exit-code:

alembic/env.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
"""Configuration for Alembic migrations."""
2+
13
from logging.config import fileConfig
4+
from typing import Literal, Optional
25

36
from sqlalchemy import engine_from_config, pool
7+
from sqlalchemy.sql.schema import SchemaItem
48

59
from alembic import context
610
from rctab.crud.models import metadata
711
from rctab.settings import Settings
812

13+
# pylint: disable=unused-argument
14+
# pylint: disable=no-member
15+
# pylint: disable=redefined-builtin
16+
917
settings = Settings()
1018
# this is the Alembic Config object, which provides
1119
# access to the values within the .ini file in use.
1220
config = context.config
1321
config.set_main_option("sqlalchemy.url", str(settings.postgres_dsn))
1422
# Interpret the config file for Python logging.
1523
# This line sets up loggers basically.
24+
assert config.config_file_name is not None
1625
fileConfig(config.config_file_name)
1726

1827
# add your model's MetaData object here
@@ -26,16 +35,26 @@
2635
# my_important_option = config.get_main_option("my_important_option")
2736
# ... etc.
2837

38+
SchemaType = Literal[
39+
"schema", "table", "column", "index", "unique_constraint", "foreign_key_constraint"
40+
]
2941

30-
def include_object(object, name, type_, reflected, compare_to):
31-
"""
32-
Exclude views from Alembic's consideration.
33-
"""
3442

35-
return not object.info.get("is_view", False)
43+
def include_object(
44+
object: SchemaItem,
45+
name: Optional[str],
46+
type_: SchemaType,
47+
reflected: bool,
48+
compare_to: Optional[SchemaItem],
49+
) -> bool:
50+
"""Exclude views from Alembic's consideration."""
51+
if object.info:
52+
if object.info.get("is_view", False):
53+
return False
54+
return True
3655

3756

38-
def run_migrations_offline():
57+
def run_migrations_offline() -> None:
3958
"""Run migrations in 'offline' mode.
4059
4160
This configures the context with just a URL
@@ -61,7 +80,7 @@ def run_migrations_offline():
6180
context.run_migrations()
6281

6382

64-
def run_migrations_online():
83+
def run_migrations_online() -> None:
6584
"""Run migrations in 'online' mode.
6685
6786
In this scenario we need to create an Engine

alembic/versions/b65796c99771_squash.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Squash
1+
"""Squash (previous migrations).
22
33
Revision ID: b65796c99771
44
Revises:
@@ -12,6 +12,9 @@
1212

1313
from alembic import op
1414

15+
# pylint: disable=no-member
16+
# pylint: disable=invalid-name
17+
1518
# revision identifiers, used by Alembic.
1619
revision = "b65796c99771"
1720
down_revision = None
@@ -67,7 +70,8 @@ class FinanceHistorySql:
6770
DROP_FUNCTION = "DROP FUNCTION {schema}.finance_changed();"
6871

6972

70-
def upgrade():
73+
def upgrade() -> None:
74+
"""Upgrade the database."""
7175
op.execute(text("create schema accounting"))
7276
op.create_table(
7377
"user_cache",
@@ -362,9 +366,7 @@ def upgrade():
362366
sa.Column("subscription_id", postgresql.UUID(), nullable=False),
363367
sa.Column("display_name", sa.String(), nullable=False),
364368
sa.Column("state", sa.String(), nullable=False),
365-
sa.Column(
366-
"role_assignments", postgresql.JSONB(astext_type=sa.Text()), nullable=True
367-
),
369+
sa.Column("role_assignments", postgresql.JSONB(), nullable=True),
368370
sa.Column(
369371
"time_created",
370372
sa.DateTime(timezone=True),
@@ -385,7 +387,7 @@ def upgrade():
385387
sa.Column("id", sa.String(), nullable=False),
386388
sa.Column("name", sa.String(), nullable=True),
387389
sa.Column("type", sa.String(), nullable=True),
388-
sa.Column("tags", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
390+
sa.Column("tags", postgresql.JSONB(), nullable=True),
389391
sa.Column("billing_account_id", sa.String(), nullable=True),
390392
sa.Column("billing_account_name", sa.String(), nullable=True),
391393
sa.Column("billing_period_start_date", sa.Date(), nullable=True),
@@ -488,7 +490,8 @@ def upgrade():
488490
)
489491

490492

491-
def downgrade():
493+
def downgrade() -> None:
494+
"""Downgrade the database."""
492495
op.drop_table("cost_recovery", schema="accounting")
493496
op.execute(
494497
"DROP MATERIALIZED VIEW {schema}.usage_view;".format(schema="accounting")

docs/content/setup.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ TESTING=true pytest tests/
157157

158158
The `TESTING=true` env var is important so that database commits are rolled back between each unit test.
159159

160+
**Note:** Visual Studio Code will try to import your .env file into your environment, which will cause a number of tests to fail.
161+
To prevent this, we recommend changing the `python.envFile` setting to point to a non-existent file.
162+
See <https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file> for more.
163+
160164
**Note:** This will remove the contents of any [postgreSQL containers](#postgresql-container) you have running. If you don't want to lose them use [the helper script](#with-the-helper-script).
161165

162-
The tests for background tasks require Redis
166+
The tests for background tasks require Redis.
163167
Once you have a [Redis server](https://redis.io/docs/install/install-redis/) running (or a [Redis Docker](https://hub.docker.com/_/redis) container running), you can run the unit tests, including the background task tests, with:
164168

165169
```bash

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[mypy]
22
disallow_untyped_defs = True
33
ignore_missing_imports = True
4-
plugins = sqlmypy, pydantic.mypy
4+
plugins = pydantic.mypy

0 commit comments

Comments
 (0)