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

More tests, and performance profiling #68

Merged
merged 13 commits into from
Mar 13, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: CI
on:
push:
branches-ignore:
- "gh-pages"
branches:
- main
- "renovate/**"
pull_request:
jobs:
test_js:
Expand All @@ -21,28 +22,32 @@ jobs:
restore-keys: |
${{ runner.os }}-node-
- run: npm install --no-optional --no-audit --no-fund --progress=false
- run: npm --prefix website install
- run: npm run lint
- run: npm --prefix website run build
test_python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- run: pip install -e . && pip install -r requirements.txt
- run: make test-coverage
- run: make lint
- run: make benchmark
- run: cd website; python build_rules.py
test_python_compat:
needs: test_python
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python: 3.6
- python: 3.7
- python: 3.8
- python: 3.9
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- run: |
python -m pip install --upgrade pip
pip install -e '.[dev]'
- run: make test-coverage
- run: |
make lint
cd website; python build_rules.py
if: ${{ matrix.python == '3.9' }}
- run: pip install -e . && pip install $(cat requirements.txt | grep pytest)
- run: make test
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

## Unreleased

### Changed

- Add more descriptive error message for missing whitespace between HTML attributes ([#23 (comment)](https://github.com/thibaudcolas/curlylint/issues/23#issuecomment-700622837)).
- Move development dependencies from extras to separate `requirements.txt`.

### Fixed

- Fix Python 3.10 deprecation warning by importing Iterable from collections.abc.

## [v0.12.2](https://github.com/thibaudcolas/curlylint/releases/tag/v0.12.2) 2021-03-06

### Fixed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ make init # Install dependencies and initialise for development.
make lint # Lint the project.
make format # Format project files.
make test # Test the project.
make benchmark # Runs a one-off performance (speed, memory) benchmark.
make clean-pyc # Remove Python file artifacts.
make sdist # Builds package version
make publish # Publishes a new version to pypi.
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@ help: ## See what commands are available.

init: clean-pyc ## Install dependencies and initialise for development.
pip install --upgrade pip setuptools twine wheel
pip install -e '.[dev]'
pip install -e .
pip install -r requirements.txt

lint: ## Lint the project.
black --check **/*.py
flake8 **/*.py
mypy curlylint
mypy **/*.py

format: ## Format project files.
black **/*.py
npm run format

test: ## Test the project.
pytest --strict-config
PYTHONDEVMODE=1 pytest --strict-config

test-watch: ## Restarts the tests whenever a file changes.
nodemon -q -e py,json -w curlylint -x "clear && pytest --strict-config --exitfirst --new-first -q || true"
PYTHONDEVMODE=1 nodemon -q -e py,json -w curlylint -x "clear && pytest --strict-config --exitfirst --new-first -q || true"

test-coverage: ## Run the tests while generating test coverage data.
coverage run -m pytest --strict-config && coverage report && coverage html
PYTHONDEVMODE=1 coverage run -m pytest --strict-config && coverage report && coverage html

benchmark: ## Runs a one-off performance (speed, memory) benchmark.
PYTHONDEVMODE=1 python benchmark.py

clean-pyc: ## Remove Python file artifacts.
find . -name '*.pyc' -exec rm -f {} +
Expand Down
40 changes: 40 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import cProfile
from pstats import Stats

from curlylint.tests.utils import BlackRunner

from curlylint.cli import main

from memory_profiler import profile

runner = BlackRunner()

pr = cProfile.Profile()
pr.enable()

result = runner.invoke(main, ["--verbose", "tests/django/wagtailadmin/"])

pr.disable()
p = Stats(pr)

p.strip_dirs().sort_stats("cumulative").print_stats(10)

print(result.exit_code)
print(runner.stdout_bytes.decode())
print(runner.stderr_bytes.decode())

print("Measuring memory consumption")


@profile(precision=6)
def memory_consumption_run():
runner.invoke(
main,
[
"--verbose",
"tests/django/wagtailadmin/pages/listing/_page_title_choose.html",
],
)


memory_consumption_run()
3 changes: 2 additions & 1 deletion curlylint/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
# XXX: It could be better and simpler to only allow ASCII whitespaces here.
whitespace = P.regex(r"\s*")
mandatory_whitespace = P.regex(r"\s+")
spaces_between_attr = mandatory_whitespace.desc("space(s) between attributes")


def until(parser):
Expand Down Expand Up @@ -415,7 +416,7 @@ def make_attributes_parser(config, jinja):

attrs = interpolated(
(
whitespace.then(jinja_attr) | mandatory_whitespace.then(attribute)
whitespace.then(jinja_attr) | spaces_between_attr.then(attribute)
).many()
)

Expand Down
Loading