Skip to content

Commit e9311fe

Browse files
committed
Merge remote-tracking branch 'origin/master' into pylint
2 parents 9801911 + 4bf687a commit e9311fe

File tree

12 files changed

+197
-51
lines changed

12 files changed

+197
-51
lines changed

.bandit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
skips:
2+
- B101

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 4
7+
insert_final_newline = true
8+
end_of_line = lf
9+
10+
[*.{yml,yaml}]
11+
indent_size = 2

.flake8

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[flake8]
2+
max-line-length = 99
3+
ignore = W503
4+
exclude =
5+
.git
6+
.tox
7+
venv*
8+
9+
# pending revision
10+
cssselect/__init__.py
11+
cssselect/parser.py
12+
cssselect/xpath.py
13+
docs/conf.py
14+
setup.py
15+
tests/test_cssselect.py

.github/workflows/checks.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Checks
2+
on: [push, pull_request]
3+
4+
jobs:
5+
checks:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
include:
10+
- python-version: 3
11+
env:
12+
TOXENV: flake8
13+
- python-version: 3
14+
env:
15+
TOXENV: pylint
16+
- python-version: 3
17+
env:
18+
TOXENV: security
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Run check
29+
env: ${{ matrix.env }}
30+
run: |
31+
pip install -U pip
32+
pip install -U tox
33+
tox

.github/workflows/publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish
2+
on: [push]
3+
4+
jobs:
5+
publish:
6+
runs-on: ubuntu-latest
7+
if: startsWith(github.event.ref, 'refs/tags/')
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Set up Python 3.8
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: 3
16+
17+
- name: Check Tag
18+
id: check-release-tag
19+
run: |
20+
if [[ ${{ github.event.ref }} =~ ^refs/tags/[0-9]+[.][0-9]+[.][0-9]+(rc[0-9]+|[.]dev[0-9]+)?$ ]]; then
21+
echo ::set-output name=release_tag::true
22+
fi
23+
24+
- name: Publish to PyPI
25+
if: steps.check-release-tag.outputs.release_tag == 'true'
26+
run: |
27+
pip install --upgrade setuptools wheel twine
28+
python setup.py sdist bdist_wheel
29+
export TWINE_USERNAME=__token__
30+
export TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }}
31+
twine upload dist/*

.github/workflows/tests.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
4+
jobs:
5+
tests:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
include:
10+
- python-version: 2.7
11+
env:
12+
TOXENV: py
13+
- python-version: 3.5
14+
env:
15+
TOXENV: py
16+
- python-version: 3.6
17+
env:
18+
TOXENV: py
19+
- python-version: 3.7
20+
env:
21+
TOXENV: py
22+
23+
steps:
24+
- uses: actions/checkout@v2
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Run tests
32+
env: ${{ matrix.env }}
33+
run: |
34+
pip install -U tox
35+
tox
36+
37+
- name: Upload coverage report
38+
run: bash <(curl -s https://codecov.io/bash)

.travis.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

cssselect/xpath.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __repr__(self):
5656

5757
def add_condition(self, condition):
5858
if self.condition:
59-
self.condition = '%s and (%s)' % (self.condition, condition)
59+
self.condition = '(%s) and (%s)' % (self.condition, condition)
6060
else:
6161
self.condition = condition
6262
return self
@@ -180,7 +180,7 @@ def css_to_xpath(self, css, prefix='descendant-or-self::'):
180180
This string is prepended to the XPath expression for each selector.
181181
The default makes selectors scoped to the context node’s subtree.
182182
:raises:
183-
:class:`SelectorSyntaxError` on invalid selectors,
183+
:class:`~cssselect.SelectorSyntaxError` on invalid selectors,
184184
:class:`ExpressionError` on unknown/unsupported selectors,
185185
including pseudo-elements.
186186
:returns:
@@ -457,19 +457,19 @@ def xpath_nth_child_function(self, xpath, function, last=False,
457457
if a == 0:
458458
return xpath.add_condition('%s = %s' % (siblings_count, b_min_1))
459459

460-
expr = []
460+
expressions = []
461461

462462
if a > 0:
463463
# siblings count, an+b-1, is always >= 0,
464464
# so if a>0, and (b-1)<=0, an "n" exists to satisfy this,
465465
# therefore, the predicate is only interesting if (b-1)>0
466466
if b_min_1 > 0:
467-
expr.append('%s >= %s' % (siblings_count, b_min_1))
467+
expressions.append('%s >= %s' % (siblings_count, b_min_1))
468468
else:
469469
# if a<0, and (b-1)<0, no "n" satisfies this,
470470
# this is tested above as an early exist condition
471471
# otherwise,
472-
expr.append('%s <= %s' % (siblings_count, b_min_1))
472+
expressions.append('%s <= %s' % (siblings_count, b_min_1))
473473

474474
# operations modulo 1 or -1 are simpler, one only needs to verify:
475475
#
@@ -495,9 +495,14 @@ def xpath_nth_child_function(self, xpath, function, last=False,
495495
b_neg = '+%s' % b_neg
496496
left = '(%s %s)' % (left, b_neg)
497497

498-
expr.append('%s mod %s = 0' % (left, a))
498+
expressions.append('%s mod %s = 0' % (left, a))
499499

500-
xpath.add_condition(' and '.join(expr))
500+
if len(expressions) > 1:
501+
template = '(%s)'
502+
else:
503+
template = '%s'
504+
xpath.add_condition(' and '.join(template % expression
505+
for expression in expressions))
501506
return xpath
502507

503508
def xpath_nth_last_child_function(self, xpath, function):

pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ disable=assignment-from-no-return,
1717
no-else-return,
1818
no-member,
1919
no-self-use,
20+
raise-missing-from,
2021
redefined-builtin,
2122
redefined-outer-name,
2223
too-few-public-methods,

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
codecov
22
lxml;python_version!="3.4"
33
lxml<=4.3.5;python_version=="3.4"
4-
pytest
4+
pytest >=4.6, <4.7 # 4.7 drops support for Python 2.7 and 3.4
55
pytest-cov

0 commit comments

Comments
 (0)