Skip to content

Commit

Permalink
Merge pull request #3 from richtluk/remove-some-qa-checks
Browse files Browse the repository at this point in the history
Remove unused-imports and print-statements QA checks
  • Loading branch information
xdaniel3 committed Aug 1, 2023
2 parents d9e5d68 + f2c536d commit 2ec2410
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 57 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ Helpers for python project quality assurance.
* `pydev qa migration-filenames` - run migration filenames QA check. Migration name should be in format "[0-9]{4}_migration.py" (ex. 0001_migration.py)
* `pydev qa missing-translations` - run missing translations QA check. It will try to generate a Django `makemessages` if there is one or more missing check is failed
* `pydev qa import-order` - run import order QA check. It will check if all the new python code imports have the right order defined with isort command
* `pydev qa unused-imports` - run unused imports QA check. It will check if the new python code does not contain unused imports
* `pydev qa test-method-names` - runs test method names QA check. It will check if the new test methods has the right name in format defined in `QA_DISALLOWED_TEST_METHOD_REGEXP` setting

#### Configuration
Expand Down
33 changes: 0 additions & 33 deletions developers_chamber/qa/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,6 @@ def _run_check(self):
)


class UnusedImportsQACheck(QACheck):
"""
Checks that there are no unused imports among changed files.
"""
name = 'Check unused imports'

def _run_check(self):
changed_files = [diff.b_path for diff in self._get_diffs()
if diff.b_path and self._is_python_file(diff.b_path)]
if changed_files:
output = self._run_command(
'flake8 --count --exit-zero --select=F401'
' --per-file-ignores="__init__.py:F401"'
' {}'.format(' '.join(changed_files))
)
if output != '0':
raise QAError('Found unused import(s):', output)


class RegexPyQACheck(QACheck):
"""
Helper for writing QAChecks which finds invalid regex patterns in python code.
Expand Down Expand Up @@ -166,17 +147,3 @@ def _found_invalid_patterns(self, invalid_patterns):
'\n'.join(('{}: {}'.format(file, value) for file, value in invalid_patterns))
)


class PrintStatementsQACheck(RegexPyQACheck):
"""
Checks if changes do not contain print statements.
"""
name = 'Checking for print statements'

pattern = r'(?:^|[^a-zA-Z0-9_])(print *\([^\)]*\))'

def _found_invalid_patterns(self, invalid_patterns):
raise QAError(
'Found print statement(s):',
'\n'.join(('{}: {}'.format(file, value) for file, value in invalid_patterns))
)
22 changes: 1 addition & 21 deletions developers_chamber/scripts/qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
MigrationFilenamesQACheck,
MissingMigrationsQACheck,
MissingTranslationsQACheck,
TestMethodNamesQACheck,
PrintStatementsQACheck,
UnusedImportsQACheck)
TestMethodNamesQACheck)
from developers_chamber.scripts import cli


Expand All @@ -24,9 +22,7 @@ def all():
MigrationFilenamesQACheck(),
MissingTranslationsQACheck(),
ImportOrderQACheck(),
UnusedImportsQACheck(),
TestMethodNamesQACheck(),
PrintStatementsQACheck(),
).run()


Expand Down Expand Up @@ -66,26 +62,10 @@ def import_order():
QACheckRunner(ImportOrderQACheck()).run()


@qa.command()
def unused_imports():
"""
Run unused imports QA check. It will check if the new python code does not contain unused imports and prints it.
"""
QACheckRunner(UnusedImportsQACheck()).run()


@qa.command()
def test_method_names():
"""
Runs test method names QA check. It will check if the new test methods has the right name in format defined in
QA_DISALLOWED_TEST_METHOD_REGEXP setting.
"""
QACheckRunner(TestMethodNamesQACheck()).run()


@qa.command()
def print_statements():
"""
Runs print statements names QA check. It will check if the new test methods do not have python print statements.
"""
QACheckRunner(PrintStatementsQACheck()).run()
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='skip-developers-chamber',
version='0.0.70.2',
version='1.0.0',
description='A small plugin which help with development, deployment, git',
keywords='django, skripts, easy live, git, bitbucket, Jira',
author='Druids team',
Expand All @@ -17,7 +17,6 @@
'click>=7.0',
'click-completion==0.5.2',
'coloredlogs==10.0',
'flake8>=4.0.1',
'gitpython==3.1.30',
'isort>=5.12.0',
'jira==2.0.0',
Expand Down

0 comments on commit 2ec2410

Please sign in to comment.