Skip to content

Commit 8403d05

Browse files
authored
Merge pull request #5 from Mathics3/project-administion
The usual sanity checking stuff
2 parents 29ecc61 + 2ffea18 commit 8403d05

File tree

8 files changed

+81
-13
lines changed

8 files changed

+81
-13
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = tab
8+
indent_size = 4
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.py]
15+
indent_style = space
16+
indent_size = 4
17+
trim_trailing_whitespace: true

.github/workflows/autoblack.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
2+
# If all Python code in the pull request is compliant with Black then this Action does nothing.
3+
# Othewrwise, Black is run and its changes are committed back to the incoming pull request.
4+
# https://github.com/cclauss/autoblack
5+
6+
name: autoblack
7+
on: [pull_request]
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python 3.9
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.9
17+
- name: Install click
18+
run: pip install 'click==8.0.4'
19+
- name: Install Black
20+
run: pip install 'black==22.3.0'
21+
- name: Run black --check .
22+
run: black --check .
23+
- name: If needed, commit black changes to the pull request
24+
if: failure()
25+
run: |
26+
black .
27+
git config --global user.name 'autoblack'
28+
git config --global user.email '[email protected]'
29+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
30+
git checkout $GITHUB_HEAD_REF
31+
git commit -am "fixup: Format Python code with Black"
32+
git push

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/build
55
/dist
66
/pymathics_natlang.egg-info
7+
/tmp
78
__pycache__

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
default_language_version:
2+
python: python
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.0.1
6+
hooks:
7+
- id: check-merge-conflict
8+
- id: debug-statements
9+
stages: [commit]
10+
- id: end-of-file-fixer
11+
stages: [commit]
12+
- id: trailing-whitespace
13+
- repo: https://github.com/psf/black
14+
rev: 22.3.0
15+
hooks:
16+
- id: black
17+
language_version: python3
18+
exclude: 'mathicsscript/version.py'
19+
- repo: https://github.com/pycqa/flake8
20+
rev: 3.9.2
21+
hooks:
22+
- id: flake8
23+
stages: [commit]

pymathics/natlang/__main__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ def apply_n(self, text, n, evaluation, options):
389389
doc = self._nlp(text.value, evaluation, options)
390390
if doc:
391391
return ListExpression(
392-
itertools.islice(
393-
(String(sent.text) for sent in doc.sents), n.value
394-
),
392+
itertools.islice((String(sent.text) for sent in doc.sents), n.value),
395393
)
396394

397395

@@ -974,9 +972,7 @@ def apply(self, word, evaluation, options):
974972
evaluation, self._language_name(evaluation, options)
975973
)
976974
if wordnet:
977-
senses = self._senses(
978-
word.value.lower(), wordnet, language_code
979-
)
975+
senses = self._senses(word.value.lower(), wordnet, language_code)
980976
if senses:
981977
return ListExpression([String(syn.definition()) for syn, _ in senses])
982978
else:
@@ -1284,9 +1280,7 @@ def apply(self, word, evaluation, options):
12841280
evaluation, self._language_name(evaluation, options)
12851281
)
12861282
if wordnet:
1287-
if list(
1288-
wordnet.synsets(word.value.lower(), None, language_code)
1289-
):
1283+
if list(wordnet.synsets(word.value.lower(), None, language_code)):
12901284
return SymbolTrue
12911285
else:
12921286
return SymbolFalse
@@ -1512,9 +1506,7 @@ def apply(self, word, evaluation, options):
15121506
language_name = self.get_option(options, "Language", evaluation)
15131507
if not isinstance(language_name, String):
15141508
return
1515-
language_code = SpellingCorrectionList._languages.get(
1516-
language_name.value, None
1517-
)
1509+
language_code = SpellingCorrectionList._languages.get(language_name.value, None)
15181510
if not language_code:
15191511
return evaluation.message("SpellingCorrectionList", "lang", language_name)
15201512

pymathics/natlang/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
# This file is suitable for sourcing inside POSIX shell as
55
# well as importing into Python. That's why there is no
66
# space around "=" below.
7+
# fmt: off
78
__version__="5.0.0.dev0"

test/helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
session = MathicsSession(add_builtin=True, catch_interrupt=False)
44

5+
56
def check_evaluation(str_expr: str, str_expected: str, message=""):
67
"""Helper function to test that a WL expression against
78
its results"""

test/test_natlang.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# -*- coding: utf-8 -*-
22
from .helper import session, check_evaluation
33

4+
45
def test_natlang():
56

67
session.evaluate(
78
"""
89
LoadModule["pymathics.natlang"]
910
"""
10-
)
11+
)
1112

1213
for str_expr, str_expected, message in (
1314
(

0 commit comments

Comments
 (0)