Skip to content

Commit

Permalink
Improve dev experience (#38)
Browse files Browse the repository at this point in the history
* Improve dev experience

* Add pytest and flake8 commands to readme

* Use --filename in flake8

* Lint all py files

* Add Makefile and update readme

* Lint
  • Loading branch information
mariosasko authored Jul 26, 2021
1 parent 6e9c563 commit e14d79e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 35 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,16 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install package and dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .[dev]
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 **/*.py --count --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 **/*.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Install package
run: |
# required because of entry points
pip install .
flake8 --filename=*.py --count --show-source --max-line-length=119 --statistics
# exit-zero treats all errors as warnings
flake8 --filename=*.py --count --exit-zero --max-line-length=119 --max-complexity=10 --statistics
- name: Test with pytest
run: |
pip install pytest
python -m pytest -vvv tests
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ignore models dir
spacy_udpipe/models

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: lint test

# Lint source code

lint:
# stop the build if there are Python syntax errors or undefined names
flake8 --filename=*.py --count --show-source --max-line-length=119 --statistics
# exit-zero treats all errors as warnings
flake8 --filename=*.py --count --exit-zero --max-line-length=119 --max-complexity=10 --statistics

# Run tests

test:
python -m pytest -vvv tests
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ This can be done for any of the languages supported by spaCy. For an exhaustive
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update the tests as appropriate. Tests are run automatically for each pull request on the master branch.
To start the tests locally, first, install the package with `pip install -e .`, then run [`pytest`](https://docs.pytest.org/en/latest/contents.html) in the root source directory.
To start the tests locally, first, install the package with `pip install -e .[dev]`, then run [`pytest`](https://docs.pytest.org/en/latest/contents.html) in the root source directory as follows:
```bash
make test
```
Additionally, run [`flake8`](https://flake8.pycqa.org/en/latest) with the following command to check for coding mistakes:
```bash
make lint
```

## License
* Source code: [MIT](https://choosealicense.com/licenses/mit/) © Text Analysis and Knowledge Engineering Lab (TakeLab)
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

27 changes: 18 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

import setuptools
from setuptools import find_packages, setup


def get_version(fname: str) -> str:
Expand All @@ -9,11 +9,11 @@ def get_version(fname: str) -> str:
"spacy_udpipe",
fname
)
with open(full_path, "r") as fp:
for l in fp:
if l.startswith("__version__"):
delim = '"' if '"' in l else "'"
return l.split(delim)[1]
with open(full_path, "r", encoding="utf-8") as fp:
for line in fp:
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError(
"Unable to find version string."
Expand All @@ -22,10 +22,10 @@ def get_version(fname: str) -> str:

URL = "https://github.com/TakeLab/spacy-udpipe"

with open("README.md", "r") as f:
with open("README.md", "r", encoding="utf-8") as f:
readme = f.read()

setuptools.setup(
setup(
name="spacy_udpipe",
version=get_version("__init__.py"),
description="Use fast UDPipe models directly in spaCy",
Expand All @@ -36,8 +36,11 @@ def get_version(fname: str) -> str:
author_email="[email protected]",
license="MIT",
keywords="nlp udpipe spacy python",
packages=setuptools.find_packages(),
packages=find_packages(),
install_requires=["spacy>=3.0.0,<4.0.0", "ufal.udpipe>=1.2.0"],
extras_require={
"dev": ["flake8", "pytest"],
},
python_requires=">=3.6",
entry_points={
"spacy_tokenizers": [
Expand All @@ -49,9 +52,15 @@ def get_version(fname: str) -> str:
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research"
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Text Processing",
],
project_urls={
"SpaCy": "https://spacy.io/",
Expand Down
5 changes: 1 addition & 4 deletions spacy_udpipe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
BASE_URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-3131" # noqa: E501
MODELS_DIR = os.path.join(os.path.dirname(__file__), "models")
with open(
os.path.join(
os.path.dirname(__file__),
"languages.json"
),
os.path.join(os.path.dirname(__file__), "languages.json"), encoding="utf-8"
) as f:
LANGUAGES = json.load(f)

Expand Down
10 changes: 4 additions & 6 deletions tests/languages/fr/test_fr_language.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

import pytest
from spacy.lang.fr import FrenchDefaults
from spacy.language import BaseDefaults
Expand All @@ -24,12 +22,12 @@ def test_get_defaults(lang: str) -> None:

def test_spacy_udpipe(lang: str) -> None:
nlp = load(lang=lang)

text = "Attention aux articles contractés!"
doc = nlp (text=text)
doc = nlp(text=text)

assert [t.orth_ for t in doc] == ["Attention", "à", "les", "articles", "contractés", "!"]

pos = [{"INTJ", "NOUN"}, {"ADP"}, {"DET"}, {"NOUN"}, {"VERB", "ADJ"}, {"PUNCT"}]
for i, t in enumerate(doc):
assert t.pos_ in pos[i]
Expand Down

0 comments on commit e14d79e

Please sign in to comment.