Skip to content

Commit

Permalink
chore: swap black/isort/flake8 for ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Oct 31, 2024
1 parent 6033f35 commit ea5d5f2
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 70 deletions.
11 changes: 7 additions & 4 deletions harvey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ def parse_github_webhook(request: requests.Request) -> Tuple[Dict[str, object],

logger.error(message)

response = {
'success': success,
'message': message,
}, status_code
response = (
{
'success': success,
'message': message,
},
status_code,
)

return response
2 changes: 1 addition & 1 deletion harvey/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# - https://bugs.python.org/issue30385
# - https://github.com/unbit/uwsgi/issues/1722
# - https://github.com/Justintime50/harvey/issues/72
os.environ["no_proxy"] = "*"
os.environ['no_proxy'] = '*'


def bootstrap() -> bool:
Expand Down
2 changes: 1 addition & 1 deletion harvey/repos/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def store_deployment_details(webhook: Dict[str, Any], final_output: str = 'NA'):
attempts[-1] = attempt

database_table[Webhook.deployment_id(webhook)] = {
'project': Webhook.repo_full_name(webhook).replace("/", "-"),
'project': Webhook.repo_full_name(webhook).replace('/', '-'),
'commit': Webhook.repo_commit_id(webhook),
# This timestamp will be the most recent attempt's timestamp, important to have at the root for sorting
'timestamp': now,
Expand Down
2 changes: 1 addition & 1 deletion harvey/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def format_project_name(project_name: str) -> str:
"""Formats a project name for use throughout Harvey."""
return project_name.replace("/", "-")
return project_name.replace('/', '-')


def setup_logger():
Expand Down
33 changes: 11 additions & 22 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ SCRIPTS_DIR := "scripts"
bandit:
{{VIRTUAL_BIN}}/bandit -r {{PROJECT_NAME}}/

# Runs the Black Python formatter against the project
black:
{{VIRTUAL_BIN}}/black {{PROJECT_NAME}}/ {{TEST_DIR}}/ {{SCRIPTS_DIR}}/

# Checks if the project is formatted correctly against the Black rules
black-check:
{{VIRTUAL_BIN}}/black {{PROJECT_NAME}}/ {{TEST_DIR}}/ {{SCRIPTS_DIR}}/ --check

# Builds the project in preparation for release
build:
{{VIRTUAL_BIN}}/python -m build
Expand All @@ -30,15 +22,11 @@ clean:
coverage:
{{VIRTUAL_BIN}}/pytest {{TEST_DIR}}/unit --cov={{PROJECT_NAME}} --cov-branch --cov-report=html --cov-report=lcov --cov-report=term-missing --cov-fail-under=75

# Run flake8 checks against the project
flake8:
{{VIRTUAL_BIN}}/flake8 {{PROJECT_NAME}}/ {{TEST_DIR}}/ {{SCRIPTS_DIR}}/

# Lints the project
lint: black-check isort-check flake8 mypy bandit
lint: ruff-check mypy bandit

# Runs all formatting tools against the project
lint-fix: black isort
lint-fix: ruff

# Install the project locally
install:
Expand All @@ -49,19 +37,20 @@ install:
integration:
venv/bin/python {{TEST_DIR}}/integration/test_deployment.py

# Sorts imports throughout the project
isort:
{{VIRTUAL_BIN}}/isort {{PROJECT_NAME}}/ {{TEST_DIR}}/ {{SCRIPTS_DIR}}/

# Checks that imports throughout the project are sorted correctly
isort-check:
{{VIRTUAL_BIN}}/isort {{PROJECT_NAME}}/ {{TEST_DIR}}/ {{SCRIPTS_DIR}}/ --check-only

# Run the service in production
prod:
docker compose -f docker-compose.yml -f docker-compose-prod.yml up -d --build
venv/bin/uwsgi --ini uwsgi.ini --virtualenv venv

# Formats the project
ruff:
{{VIRTUAL_BIN}}/ruff check --fix
{{VIRTUAL_BIN}}/ruff format

# Checks the project for formatting issues
ruff-check:
{{VIRTUAL_BIN}}/ruff check

# Run the service locally
run:
docker compose up -d --build
Expand Down
30 changes: 17 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
[tool.black]
preview = true
[tool.ruff]
line-length = 120
skip-string-normalization = true

[tool.isort]
profile = "black"
line_length = 120
indent = 4
force_grid_wrap = 2
multi_line_output = 3
sections = "FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER"
lines_after_imports = 2
include_trailing_comma = true
use_parentheses = true
[tool.ruff.lint]
# `E` and `F` for error/warning codes, `I` for isort support
select = ["E", "F", "I"]

[tool.ruff.format]
quote-style = "single"

[tool.ruff.lint.isort]
section-order = [
"future",
"standard-library",
"third-party",
"first-party",
"local-folder",
]
lines-after-imports = 2

[tool.mypy]
disable_error_code = "import-untyped"
2 changes: 1 addition & 1 deletion scripts/remove_old_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main():
file_created_at = os.stat(file_location).st_ctime
file_age = file_created_at + LOG_LIFE
if current_time > file_age:
print(f"Deleting: {file_location}...")
print(f'Deleting: {file_location}...')
os.remove(file_location)


Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
version=version,
description='The lightweight Docker Compose deployment runner.',
long_description=long_description,
long_description_content_type="text/markdown",
long_description_content_type='text/markdown',
url='http://github.com/justintime50/harvey',
author='Justintime50',
license='MIT',
Expand All @@ -60,9 +60,9 @@
]
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
install_requires=REQUIREMENTS,
extras_require={
Expand Down
34 changes: 17 additions & 17 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ def mock_client():
@pytest.fixture
def mock_webhook(branch='main'):
mock_webhook = {
"ref": f'refs/heads/{branch}',
"repository": {
"name": "TEST-repo-name",
"full_name": "TEST_user/TEST-repo-name",
"html_url": "https://test-html-url.com",
"ssh_url": "https://test-ssh-url.com",
"owner": {
"name": "TEST_owner",
'ref': f'refs/heads/{branch}',
'repository': {
'name': 'TEST-repo-name',
'full_name': 'TEST_user/TEST-repo-name',
'html_url': 'https://test-html-url.com',
'ssh_url': 'https://test-ssh-url.com',
'owner': {
'name': 'TEST_owner',
},
},
"commits": [
'commits': [
{
"id": 123456,
"author": {
"name": "test_user",
'id': 123456,
'author': {
'name': 'test_user',
},
"message": "Mock message",
'message': 'Mock message',
}
],
}
Expand All @@ -43,10 +43,10 @@ def mock_webhook(branch='main'):
def mock_webhook_object(branch='main'):
webhook = MagicMock()
webhook.json = {
"ref": f'refs/heads/{branch}',
"repository": {
"name": "TEST-repo-name",
"full_name": "TEST_user/TEST-repo-name",
'ref': f'refs/heads/{branch}',
'repository': {
'name': 'TEST-repo-name',
'full_name': 'TEST_user/TEST-repo-name',
},
}

Expand Down
12 changes: 6 additions & 6 deletions test/unit/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def test_open_project_config(mock_json, mock_isfile):
# We re-declare a basic mock webhook here because os.path.join on Python 3.7 gets
# angry with MagicMock objects being passed in
mock_webhook = {
"repository": {
"full_name": "TEST_user/TEST-repo-name",
'repository': {
'full_name': 'TEST_user/TEST-repo-name',
},
"commits": [
'commits': [
{
"id": 123456,
"author": {
"name": "test_user",
'id': 123456,
'author': {
'name': 'test_user',
},
}
],
Expand Down
1 change: 1 addition & 0 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from harvey.app import APP


if __name__ == '__main__':
APP.run()

0 comments on commit ea5d5f2

Please sign in to comment.