Skip to content

Commit

Permalink
Upgrade bootstrap to Python3.11 and add ruff (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
trottomv authored Jan 11, 2023
1 parent e928e38 commit 5c33e24
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 254 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Python application

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

permissions:
contents: read
Expand All @@ -19,13 +19,12 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/test.txt
- name: Run Test
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ terraform.tfvars

# macOS
.DS_Store

# Ruff
.ruff_cache
23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.2.0"
rev: "v4.4.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -24,24 +24,17 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: "v2.34.0"
rev: "v3.3.1"
hooks:
- id: pyupgrade
args: [--py310-plus]
- repo: https://github.com/psf/black
rev: "22.3.0"
rev: "22.12.0"
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: "5.10.1"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.218
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: "4.0.1"
hooks:
- id: flake8
additional_dependencies:
- flake8-assertive~=2.1.0
- flake8-bugbear~=22.4.25
- flake8-docstrings~=1.6.0
- flake8-isort~=4.1.0
- id: ruff
args:
- --fix
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim-bullseye
FROM python:3.11-slim-bullseye

ARG DEBIAN_FRONTEND=noninteractive
ARG OUTPUT_BASE_DIR=/data
Expand Down
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
.PHONY: check
check: ## Check code formatting and import sorting
python3 -m black --check .
python3 -m isort --check .
python3 -m flake8
ruff .

.PHONY: fix
fix: ## Fix code formatting, linting and sorting imports
python3 -m black .
python3 -m isort .
python3 -m flake8
ruff --fix .

.PHONY: local
local: pip_update ## Install local requirements and dependencies
Expand All @@ -22,13 +20,13 @@ outdated: ## Check outdated requirements and dependencies

.PHONY: pip
pip: pip_update ## Compile requirements
python3 -m piptools compile --no-header --quiet --upgrade --output-file requirements/common.txt requirements/common.in
python3 -m piptools compile --no-header --quiet --upgrade --output-file requirements/local.txt requirements/local.in
python3 -m piptools compile --no-header --quiet --upgrade --output-file requirements/test.txt requirements/test.in
python3 -m piptools compile --no-header --quiet --resolver=backtracking --upgrade --output-file requirements/common.txt requirements/common.in
python3 -m piptools compile --no-header --quiet --resolver=backtracking --upgrade --output-file requirements/local.txt requirements/local.in
python3 -m piptools compile --no-header --quiet --resolver=backtracking --upgrade --output-file requirements/test.txt requirements/test.in

.PHONY: pip_update
pip_update: ## Update requirements and dependencies
python3 -m pip install -q -U pip~=22.0.0 pip-tools~=6.5.0 setuptools~=60.9.0 wheel~=0.37.0
python3 -m pip install -q -U pip~=22.3.0 pip-tools~=6.12.0 setuptools~=65.6.0 wheel~=0.38.0

.PHONY: precommit
precommit: ## Fix code formatting, linting and sorting imports
Expand Down
7 changes: 3 additions & 4 deletions bootstrap/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Web project initialization CLI constants."""

from typing import Dict

# Stacks

Expand Down Expand Up @@ -39,15 +38,15 @@

DEV_ENV_SLUG = "dev"

DEV_ENV_STACK_CHOICES: Dict[str, str] = {
DEV_ENV_STACK_CHOICES: dict[str, str] = {
"1": MAIN_STACK_SLUG,
}

STAGE_ENV_NAME = "staging"

STAGE_ENV_SLUG = "stage"

STAGE_ENV_STACK_CHOICES: Dict[str, str] = {
STAGE_ENV_STACK_CHOICES: dict[str, str] = {
"1": MAIN_STACK_SLUG,
"2": DEV_STACK_SLUG,
}
Expand All @@ -56,7 +55,7 @@

PROD_ENV_SLUG = "prod"

PROD_ENV_STACK_CHOICES: Dict[str, str] = {}
PROD_ENV_STACK_CHOICES: dict[str, str] = {}

# Env vars

Expand Down
60 changes: 31 additions & 29 deletions bootstrap/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def collect_vault_environment_secrets(self, env_name):
"""Collect the Vault secrets for the given environment."""
# Sentry env vars are used by the GitLab CI/CD
self.sentry_dsn and self.register_vault_environment_secret(
env_name, f"{self.service_slug}/sentry", dict(sentry_dsn=self.sentry_dsn)
env_name, f"{self.service_slug}/sentry", {"sentry_dsn": self.sentry_dsn}
)

def collect_vault_secrets(self):
Expand Down Expand Up @@ -262,47 +262,49 @@ def create_env_file(self):
def init_terraform_cloud(self):
"""Initialize the Terraform Cloud resources."""
click.echo(info("...creating the Terraform Cloud resources with Terraform"))
env = dict(
TF_VAR_admin_email=self.terraform_cloud_admin_email,
TF_VAR_create_organization=self.terraform_cloud_organization_create
env = {
"TF_VAR_admin_email": self.terraform_cloud_admin_email,
"TF_VAR_create_organization": self.terraform_cloud_organization_create
and "true"
or "false",
TF_VAR_environments=json.dumps(list(map(itemgetter("slug"), self.envs))),
TF_VAR_hostname=self.terraform_cloud_hostname,
TF_VAR_organization_name=self.terraform_cloud_organization,
TF_VAR_project_name=self.project_name,
TF_VAR_project_slug=self.project_slug,
TF_VAR_service_slug=self.service_slug,
TF_VAR_terraform_cloud_token=self.terraform_cloud_token,
)
"TF_VAR_environments": json.dumps(list(map(itemgetter("slug"), self.envs))),
"TF_VAR_hostname": self.terraform_cloud_hostname,
"TF_VAR_organization_name": self.terraform_cloud_organization,
"TF_VAR_project_name": self.project_name,
"TF_VAR_project_slug": self.project_slug,
"TF_VAR_service_slug": self.service_slug,
"TF_VAR_terraform_cloud_token": self.terraform_cloud_token,
}
self.run_terraform("terraform-cloud", env)

def init_gitlab(self):
"""Initialize the GitLab repository and associated resources."""
click.echo(info("...creating the GitLab repository and associated resources"))
env = dict(
TF_VAR_gitlab_token=self.gitlab_private_token,
TF_VAR_gitlab_url=self.gitlab_url,
TF_VAR_group_path=self.gitlab_group_path,
TF_VAR_group_variables=self.render_gitlab_variables_to_string("group"),
TF_VAR_project_name=self.project_name,
TF_VAR_project_slug=self.project_slug,
TF_VAR_project_variables=self.render_gitlab_variables_to_string("project"),
TF_VAR_service_dir=self.service_dir,
TF_VAR_service_slug=self.service_slug,
)
env = {
"TF_VAR_gitlab_token": self.gitlab_private_token,
"TF_VAR_gitlab_url": self.gitlab_url,
"TF_VAR_group_path": self.gitlab_group_path,
"TF_VAR_group_variables": self.render_gitlab_variables_to_string("group"),
"TF_VAR_project_name": self.project_name,
"TF_VAR_project_slug": self.project_slug,
"TF_VAR_project_variables": self.render_gitlab_variables_to_string(
"project"
),
"TF_VAR_service_dir": self.service_dir,
"TF_VAR_service_slug": self.service_slug,
}
self.run_terraform("gitlab", env)

def init_vault(self):
"""Initialize the Vault resources."""
click.echo(info("...creating the Vault resources with Terraform"))
self.collect_vault_secrets()
env = dict(
TF_VAR_project_slug=self.project_slug,
TF_VAR_secrets=json.dumps(self.vault_secrets),
TF_VAR_vault_address=self.vault_url,
TF_VAR_vault_token=self.vault_token,
)
env = {
"TF_VAR_project_slug": self.project_slug,
"TF_VAR_secrets": json.dumps(self.vault_secrets),
"TF_VAR_vault_address": self.vault_url,
"TF_VAR_vault_token": self.vault_token,
}
self.run_terraform("vault", env)

def get_terraform_module_params(self, module_name, env):
Expand Down
42 changes: 36 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
[tool.black]
target-version = ["py310"]

[tool.isort]
atomic = true
profile = "black"
target-version = ["py311"]

[tool.mypy]
python_version = "3.10"
python_version = "3.11"
ignore_missing_imports = true

[tool.ruff]
extend-exclude = [
"__pycache__",
".vscode*",
]
extend-ignore = [
"D203",
"D212",
"D213",
"D214",
"D215",
"D404",
"D405",
"D406",
"D407",
"D408",
"D409",
"D410",
"D411",
"D413",
"D415",
"D416",
"D417",
"E501",
]
select = ["B", "C", "D", "E", "F", "I", "W", "B9"]
target-version = "py311"

[tool.ruff.isort]
combine-as-imports = true
known-first-party = [
"bootstrap",
]
8 changes: 4 additions & 4 deletions requirements/common.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
black~=22.3.0
black~=22.12.0
click~=8.1.0
cookiecutter~=2.1.0
pip-tools~=6.6.0
pydantic~=1.9.0
types-python-slugify~=5.0.0
pip-tools~=6.12.0
pydantic~=1.10.0
types-python-slugify~=7.0.0
validators~=0.20.0
42 changes: 21 additions & 21 deletions requirements/common.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
arrow==1.2.2
arrow==1.2.3
# via jinja2-time
binaryornot==0.4.4
# via cookiecutter
black==22.3.0
black==22.12.0
# via -r requirements/common.in
certifi==2022.6.15
build==0.9.0
# via pip-tools
certifi==2022.12.7
# via requests
chardet==5.0.0
chardet==5.1.0
# via binaryornot
charset-normalizer==2.1.0
charset-normalizer==2.1.1
# via requests
click==8.1.3
# via
Expand All @@ -20,7 +22,7 @@ cookiecutter==2.1.1
# via -r requirements/common.in
decorator==5.1.1
# via validators
idna==3.3
idna==3.4
# via requests
jinja2==3.1.2
# via
Expand All @@ -32,19 +34,21 @@ markupsafe==2.1.1
# via jinja2
mypy-extensions==0.4.3
# via black
pathspec==0.9.0
packaging==23.0
# via build
pathspec==0.10.3
# via black
pep517==0.12.0
# via pip-tools
pip-tools==6.6.2
pep517==0.13.0
# via build
pip-tools==6.12.1
# via -r requirements/common.in
platformdirs==2.5.2
platformdirs==2.6.2
# via black
pydantic==1.9.1
pydantic==1.10.4
# via -r requirements/common.in
python-dateutil==2.8.2
# via arrow
python-slugify==6.1.2
python-slugify==7.0.0
# via cookiecutter
pyyaml==6.0
# via cookiecutter
Expand All @@ -54,19 +58,15 @@ six==1.16.0
# via python-dateutil
text-unidecode==1.3
# via python-slugify
tomli==2.0.1
# via
# black
# pep517
types-python-slugify==5.0.4
types-python-slugify==7.0.0.1
# via -r requirements/common.in
typing-extensions==4.3.0
typing-extensions==4.4.0
# via pydantic
urllib3==1.26.9
urllib3==1.26.13
# via requests
validators==0.20.0
# via -r requirements/common.in
wheel==0.37.1
wheel==0.38.4
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
Expand Down
5 changes: 2 additions & 3 deletions requirements/local.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-r test.in
ipdb~=0.13.0
pre-commit~=2.19.0
pyupgrade~=2.34.0
ipython~=8.8.0
pre-commit~=2.21.0
Loading

0 comments on commit 5c33e24

Please sign in to comment.