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

Update code-style using 'pre-commit run --all-files' #3547

Merged
merged 3 commits into from
Sep 8, 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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
64 changes: 32 additions & 32 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
name-template: '$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
name-template: "$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
version-resolver:
major:
labels:
- 'Type: Major'
- 'major'
- "Type: Major"
- "major"
minor:
labels:
- 'Type: Minor'
- 'minor'
- "Type: Minor"
- "minor"
patch:
labels:
- 'Type: Patch'
- 'patch'
- "Type: Patch"
- "patch"
default: patch
categories:
- title: '🚀 Features'
labels:
- 'Type: Feature'
- 'feature'
- title: '⚙️ Enhancements'
labels:
- 'Type: Enhancement'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'Type: Bug'
- 'fix'
- 'bugfix'
- 'bug'
- title: '🔧 Maintenance'
labels:
- 'Type: Maintenance'
- 'Type: Dependencies'
- 'dependencies'
- 'maintenance'
- title: '📜 Documentation'
labels:
- 'Type: Documentation'
- 'documentation'
- title: "🚀 Features"
labels:
- "Type: Feature"
- "feature"
- title: "⚙️ Enhancements"
labels:
- "Type: Enhancement"
- "enhancement"
- title: "🐛 Bug Fixes"
labels:
- "Type: Bug"
- "fix"
- "bugfix"
- "bug"
- title: "🔧 Maintenance"
labels:
- "Type: Maintenance"
- "Type: Dependencies"
- "dependencies"
- "maintenance"
- title: "📜 Documentation"
labels:
- "Type: Documentation"
- "documentation"
template: |
## Changes

Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ name: "CodeQL"

on:
push:
branches: [ main, test ]
branches: [main, test]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [main]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript, python
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript, python

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
branches:
- main
paths:
- 'docs/**'
- 'mkdocs.yml'
- "docs/**"
- "mkdocs.yml"

concurrency:
group: deploy
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/hypha-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Hypha CI

on:
Expand All @@ -16,7 +15,7 @@ concurrency:

env:
NODE_VERSION: 18
PYTHON_VERSION: '3.11'
PYTHON_VERSION: "3.11"

jobs:
build-fe:
Expand All @@ -26,7 +25,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache: "npm"
- name: install node dependencies
run: npm install --quiet
- name: builds static assets
Expand All @@ -41,8 +40,8 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
cache: "pip"
cache-dependency-path: "**/requirements*.txt"
- name: install python dependencies
run: |
python3 -m venv venv
Expand All @@ -58,7 +57,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache: "npm"
- name: install node dependencies
run: npm install --quiet
- name: run scss and js linting
Expand Down Expand Up @@ -100,8 +99,8 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
cache: "pip"
cache-dependency-path: "**/requirements*.txt"
- uses: codecov/codecov-action@v3
- name: install python dependencies
run: |
Expand Down
10 changes: 3 additions & 7 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"validateIndentation": 4,
"requireSpaceBeforeKeywords": [
"else",
"while",
"catch"
],
"requireSpaceBeforeKeywords": ["else", "while", "catch"],
"disallowMultipleVarDecl": {
"allExcept": ["undefined"]
},
"fileExtensions": [".js"],
"preset":"airbnb",
"preset": "airbnb",
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties"
}
}
14 changes: 7 additions & 7 deletions .stylelintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ rules:
max-nesting-depth:
- 4
- ignoreAtRules:
- each
- media
- supports
- include
- each
- media
- supports
- include
media-feature-name-no-vendor-prefix: true
media-feature-range-notation: prefix
no-descending-specificity: null
Expand All @@ -43,14 +43,14 @@ rules:
rule-empty-line-before:
- always-multi-line
- except:
- first-nested
- first-nested
ignore:
- after-comment
- after-comment
scss/at-extend-no-missing-placeholder: true
scss/at-function-pattern: "^[a-z]+([a-z0-9-]+[a-z0-9]+)?$"
scss/at-import-no-partial-leading-underscore: true
scss/at-import-partial-extension-blacklist:
- scss
- scss
scss/at-mixin-pattern: "^[a-z]+([a-z0-9-]+[a-z0-9]+)?$"
scss/at-rule-no-unknown: true
scss/comment-no-empty: null
Expand Down
4 changes: 1 addition & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"recommendations": [
"njpwerner.autodocstring"
]
"recommendations": ["njpwerner.autodocstring"]
}
31 changes: 14 additions & 17 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"0.0.0.0:9001"
],
"django": true
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": ["runserver", "0.0.0.0:9001"],
"django": true
}
]
}
18 changes: 9 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"makefile.extensionOutputFolder": "./.vscode",
"cSpell.words": [
"Anymail",
"coreutils",
"modelcluster",
"pagedown",
"WAGTAILADMIN",
"wagtailcore"
]
"makefile.extensionOutputFolder": "./.vscode",
"cSpell.words": [
"Anymail",
"coreutils",
"modelcluster",
"pagedown",
"WAGTAILADMIN",
"wagtailcore"
]
}
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ endif
lint:
@echo "Checking python code style with ruff"
ruff .
# black . --check
black . --check
@echo "Checking js and css code style."
npm run lint
# @TODO: enable once we have a consistent code style
# npx prettier . --check
npx prettier . --check


.PHONY: lint-fix
Expand Down
30 changes: 20 additions & 10 deletions addressfield/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

basepath = path.dirname(__file__)
filepath = path.abspath(path.join(basepath, "static", "addressfield.min.json"))
with open(filepath, encoding='utf8') as address_data:
countries = json.load(address_data)['options']
with open(filepath, encoding="utf8") as address_data:
countries = json.load(address_data)["options"]

VALIDATION_DATA = {country['iso']: country for country in countries}
VALIDATION_DATA = {country["iso"]: country for country in countries}

ADDRESS_FIELDS_ORDER = [
'thoroughfare', 'premise', 'localityname', 'administrativearea', 'postalcode', 'country'
"thoroughfare",
"premise",
"localityname",
"administrativearea",
"postalcode",
"country",
]


Expand All @@ -35,22 +40,27 @@ class AddressField(forms.CharField):
The field stores the address in a flattened form,
so the locality components are on the same level as country or premise
"""

widget = AddressWidget
data = VALIDATION_DATA

def clean(self, value, **kwargs):
country = value['country']
country = value["country"]
try:
country_data = self.data[country]
except KeyError:
raise ValidationError('Invalid country selected') from None
raise ValidationError("Invalid country selected") from None

fields = flatten_data(country_data['fields'])
fields = flatten_data(country_data["fields"])

missing_fields = set(country_data['required']) - {field for field, value in value.items() if value}
missing_fields = set(country_data["required"]) - {
field for field, value in value.items() if value
}
if missing_fields:
missing_field_name = [fields[field]['label'] for field in missing_fields]
raise ValidationError('Please provide data for: {}'.format(', '.join(missing_field_name)))
missing_field_name = [fields[field]["label"] for field in missing_fields]
raise ValidationError(
"Please provide data for: {}".format(", ".join(missing_field_name))
)

return super().clean(value, **kwargs)

Expand Down