Skip to content

Commit

Permalink
Format code with black (#7)
Browse files Browse the repository at this point in the history
* Added black to requirements and pipeline, ran black to reformat files
* Add editorconfig
  • Loading branch information
rcoldiron committed Mar 4, 2021
1 parent 885ef38 commit 5cd72da
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 56 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true

[*.{html,css,js,json,xml,yaml,yml}]
indent_size = 2

[*.{md,ps1,sh,py,rst}]
indent_size = 4
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ stages:
- script: flake8 .
displayName: 'CR-QC: Static analysis (flake8)'

- script: black --check .
displayName: 'CR-QC: Format check'

- script: mypy .
displayName: 'CR-QC: Type check (mypy)'

Expand Down
10 changes: 8 additions & 2 deletions django_sass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ def find_static_scss() -> List[str]:
return scss_files


def compile_sass(inpath: str, outpath: str, output_style: str = None, precision: int = None,
source_map: bool = False, include_paths: List[str] = None) -> None:
def compile_sass(
inpath: str,
outpath: str,
output_style: str = None,
precision: int = None,
source_map: bool = False,
include_paths: List[str] = None,
) -> None:
"""
Calls sass.compile() within context of Django's known static file paths,
and writes output CSS and/or sourcemaps to file.
Expand Down
2 changes: 1 addition & 1 deletion django_sass/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class DjangoSassConfig(AppConfig):
name = 'django_sass'
name = "django_sass"
4 changes: 3 additions & 1 deletion django_sass/management/commands/sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def handle(self, *args, **options) -> None:
precision=o_precision,
source_map=o_srcmap,
)
self.stdout.write("Updated files at %s" % time.time())
self.stdout.write(
"Updated files at %s" % time.time()
)
except sass.CompileError as exc:
self.stdout.write(str(exc))

Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.black]
line-length = 80
target-version = ['py36', 'py37', 'py38']
# Regular expression of files to exclude.
exclude = '''
/(
migrations
)/
'''
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-e ./
black
flake8
mypy
pytest
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from setuptools import setup, find_packages


with open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf8") as readme:
with open(
os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf8"
) as readme:
README = readme.read()

setup(
Expand All @@ -11,8 +13,10 @@
author="CodeRed LLC",
author_email="[email protected]",
url="https://github.com/coderedcorp/django-sass",
description=("The absolute simplest way to use Sass with Django. Pure Python, "
"minimal dependencies, and no special configuration required!"),
description=(
"The absolute simplest way to use Sass with Django. Pure Python, "
"minimal dependencies, and no special configuration required!"
),
long_description=README,
long_description_content_type="text/markdown",
license="BSD license",
Expand Down
2 changes: 1 addition & 1 deletion testproject/app1/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class App1Config(AppConfig):
name = 'app1'
name = "app1"
2 changes: 1 addition & 1 deletion testproject/app2/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class App2Config(AppConfig):
name = 'app2'
name = "app2"
4 changes: 2 additions & 2 deletions testproject/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testproject.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -17,5 +17,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
69 changes: 34 additions & 35 deletions testproject/testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-_wl=tq26(*wyvfza+ncg_436c53pu81d=07j62+vm5y2pc)f^'
SECRET_KEY = "-_wl=tq26(*wyvfza+ncg_436c53pu81d=07j62+vm5y2pc)f^"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -32,66 +32,65 @@
# Application definition

INSTALLED_APPS = [
'app1',
'app2',
'django_sass',

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"app1",
"app2",
"django_sass",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'testproject.urls'
ROOT_URLCONF = "testproject.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'testproject.wsgi.application'
WSGI_APPLICATION = "testproject.wsgi.application"


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -103,4 +102,4 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = "/static/"
2 changes: 1 addition & 1 deletion testproject/testproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
]
2 changes: 1 addition & 1 deletion testproject/testproject/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testproject.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")

application = get_wsgi_application()
40 changes: 32 additions & 8 deletions testproject/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class TestDjangoSass(unittest.TestCase):

def setUp(self):
self.outdir = os.path.join(THIS_DIR, "out")

Expand All @@ -29,7 +28,9 @@ def assert_output(self, real_outpath: str):
contents = f.read()
self.assertTrue("/* Tests: app1/scss/_include.scss */" in contents)
self.assertTrue("/* Tests: app2/scss/_samedir.scss */" in contents)
self.assertTrue("/* Tests: app2/scss/subdir/_subdir.scss */" in contents)
self.assertTrue(
"/* Tests: app2/scss/subdir/_subdir.scss */" in contents
)
self.assertTrue("/* Tests: app2/scss/test.scss */" in contents)

def test_find_static_paths(self):
Expand All @@ -42,14 +43,35 @@ def test_find_static_sass(self):
files = find_static_scss()
# Assert that it found all of our scss files.
self.assertTrue(
os.path.join(THIS_DIR, "app1", "static", "app1", "scss", "_include.scss") in files)
os.path.join(
THIS_DIR, "app1", "static", "app1", "scss", "_include.scss"
)
in files
)
self.assertTrue(
os.path.join(THIS_DIR, "app2", "static", "app2", "scss", "_samedir.scss") in files)
os.path.join(
THIS_DIR, "app2", "static", "app2", "scss", "_samedir.scss"
)
in files
)
self.assertTrue(
os.path.join(THIS_DIR, "app2", "static", "app2", "scss", "test.scss") in files)
os.path.join(
THIS_DIR, "app2", "static", "app2", "scss", "test.scss"
)
in files
)
self.assertTrue(
os.path.join(THIS_DIR, "app2", "static", "app2", "scss", "subdir", "_subdir.scss")
in files)
os.path.join(
THIS_DIR,
"app2",
"static",
"app2",
"scss",
"subdir",
"_subdir.scss",
)
in files
)

def test_cli(self):
# Input and output paths relative to django static dirs.
Expand Down Expand Up @@ -91,7 +113,9 @@ def test_cli_srcmap(self):
self.assertEqual(proc.returncode, 0)
# Assert output is correct.
self.assert_output(outpath)
self.assertTrue(os.path.isfile(os.path.join(self.outdir, "test.css.map")))
self.assertTrue(
os.path.isfile(os.path.join(self.outdir, "test.css.map"))
)

@unittest.skip("Test needs fixed...")
def test_cli_watch(self):
Expand Down

0 comments on commit 5cd72da

Please sign in to comment.