diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..02896a1 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9fac042..b6745fa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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)' diff --git a/django_sass/__init__.py b/django_sass/__init__.py index df40a21..eed258c 100644 --- a/django_sass/__init__.py +++ b/django_sass/__init__.py @@ -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. diff --git a/django_sass/apps.py b/django_sass/apps.py index d0c0d32..c14ae0f 100644 --- a/django_sass/apps.py +++ b/django_sass/apps.py @@ -2,4 +2,4 @@ class DjangoSassConfig(AppConfig): - name = 'django_sass' + name = "django_sass" diff --git a/django_sass/management/commands/sass.py b/django_sass/management/commands/sass.py index d6238d7..566376a 100644 --- a/django_sass/management/commands/sass.py +++ b/django_sass/management/commands/sass.py @@ -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)) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..24b9307 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[tool.black] +line-length = 80 +target-version = ['py36', 'py37', 'py38'] +# Regular expression of files to exclude. +exclude = ''' +/( + migrations +)/ +''' diff --git a/requirements-dev.txt b/requirements-dev.txt index 04040a6..42a3c6e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ -e ./ +black flake8 mypy pytest diff --git a/setup.py b/setup.py index 16244c7..5e88b2c 100644 --- a/setup.py +++ b/setup.py @@ -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( @@ -11,8 +13,10 @@ author="CodeRed LLC", author_email="info@coderedcorp.com", 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", diff --git a/testproject/app1/apps.py b/testproject/app1/apps.py index 1824a7b..708ee94 100644 --- a/testproject/app1/apps.py +++ b/testproject/app1/apps.py @@ -2,4 +2,4 @@ class App1Config(AppConfig): - name = 'app1' + name = "app1" diff --git a/testproject/app2/apps.py b/testproject/app2/apps.py index 008e3c5..8ecc489 100644 --- a/testproject/app2/apps.py +++ b/testproject/app2/apps.py @@ -2,4 +2,4 @@ class App2Config(AppConfig): - name = 'app2' + name = "app2" diff --git a/testproject/manage.py b/testproject/manage.py index fb52456..ee87d59 100644 --- a/testproject/manage.py +++ b/testproject/manage.py @@ -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: @@ -17,5 +17,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/testproject/testproject/settings.py b/testproject/testproject/settings.py index d5ea872..520873b 100644 --- a/testproject/testproject/settings.py +++ b/testproject/testproject/settings.py @@ -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 @@ -32,56 +32,55 @@ # 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"), } } @@ -89,9 +88,9 @@ # 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 @@ -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/" diff --git a/testproject/testproject/urls.py b/testproject/testproject/urls.py index 0c86156..919da34 100644 --- a/testproject/testproject/urls.py +++ b/testproject/testproject/urls.py @@ -17,5 +17,5 @@ from django.urls import path urlpatterns = [ - path('admin/', admin.site.urls), + path("admin/", admin.site.urls), ] diff --git a/testproject/testproject/wsgi.py b/testproject/testproject/wsgi.py index bee623a..2b24860 100644 --- a/testproject/testproject/wsgi.py +++ b/testproject/testproject/wsgi.py @@ -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() diff --git a/testproject/tests.py b/testproject/tests.py index 78a1e87..ee8779c 100644 --- a/testproject/tests.py +++ b/testproject/tests.py @@ -11,7 +11,6 @@ class TestDjangoSass(unittest.TestCase): - def setUp(self): self.outdir = os.path.join(THIS_DIR, "out") @@ -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): @@ -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. @@ -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):