Skip to content

Commit

Permalink
#314 - Switch to poetry
Browse files Browse the repository at this point in the history
- Remove setup.py
- Switch to pyproject.toml
- Update GitHub actions to use poetry
- Clean up code a bit according to feedback from flake8
- Update release guide
  • Loading branch information
reckart committed May 4, 2024
1 parent 12f7c22 commit 3bf380c
Show file tree
Hide file tree
Showing 16 changed files with 1,173 additions and 185 deletions.
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[run]
source=cassis
omit=
setup.py
cassis/__init__.py
cassis/__version__.py
tests/*
docs/*
9 changes: 4 additions & 5 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ jobs:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade -e .[test]
pip install poetry
make dependencies
- name: Run tests
run: |
pytest
run: make unit-tests
- name: Build package
run: |
python setup.py sdist
run: make build
- name: Publish package to TestPyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade -e .[test]
pip install flake8
pip install poetry
make dependencies
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
run: make lint

- name: Run tests
run: |
pytest --cov=./ --cov-report=xml
run: make coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
47 changes: 42 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
.PHONY: docs tests
PYTHON_FILES = cassis tests

test:
python -m pytest -m "not performance" tests/
# Dependencies
dependencies:
poetry install

# Tests
unit-tests:
poetry run py.test --cov=cassis --cov-branch --cov-fail-under=90 tests

tests: unit-tests integ-tests

coverage:
poetry run py.test --cov=cassis --cov-branch --cov-fail-under=90 --cov-report=xml:coverage.xml -m "not performance" tests

# Static analysis/linting
format:
black -l 120 cassis/
black -l 120 tests/
black cassis/
black tests/
isort --profile black $(PYTHON_FILES) --multi-line=3 --trailing-comma --force-grid-wrap=0 --use-parentheses --line-width=120

lint:
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 --select=E9,F63,F7,F82 --show-source $(PYTHON_FILES)
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
poetry run flake8 --exit-zero $(PYTHON_FILES)

# Docs
docs:
poetry run mkdocs serve

html:
cd docs && make html
cd docs && make html

# Building and publishing
build: unit-tests lint
poetry build

publish: build
poetry publish

# CI

ci-publish:
poetry publish --build --username "${PYPI_USERNAME}" --password "${PYPI_PASSWORD}" --no-interaction

ci-bump-version:
poetry run bump2version patch
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ Release

- Make sure all issues for the milestone are completed, otherwise move them to the next
- Checkout the ``main`` branch
- Bump the version in ``cassis/__version__.py`` to a stable one, e.g. ``__version__ = "0.6.0"``, commit and push, wait until the build completed. An example commit message would be ``No issue. Release 0.6.0``
- Bump the version in ``pyproject.toml`` to a stable one, e.g. ``__version__ = "0.6.0"``, commit and push, wait until the build completed. An example commit message would be ``No issue. Release 0.6.0``
- Create a tag for that version via e.g. ``git tag v0.6.0`` and push the tags via ``git push --tags``. Pushing a tag triggers the release to pypi
- Bump the version in ``cassis/__version__.py`` to the next development version, e.g. ``0.7.0-dev``, commit and push that. An example commit message would be ``No issue. Bump version after release``
- Bump the version in ``pyproject.toml`` to the next development version, e.g. ``0.7.0-dev``, commit and push that. An example commit message would be ``No issue. Bump version after release``
- Once the build has completed and pypi accepted the new version, go to the Github release and write the changelog based on the issues in the respective milestone
- Create a new milestone for the next version

1 change: 0 additions & 1 deletion cassis/__version__.py

This file was deleted.

4 changes: 2 additions & 2 deletions cassis/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from cassis.typesystem import (
FEATURE_BASE_NAME_HEAD,
FEATURE_BASE_NAME_LANGUAGE,
TYPE_NAME_DOCUMENT_ANNOTATION,
TYPE_NAME_FS_ARRAY,
TYPE_NAME_FS_LIST,
TYPE_NAME_SOFA,
Expand All @@ -21,8 +23,6 @@
TypeCheckError,
TypeSystem,
TypeSystemMode,
TYPE_NAME_DOCUMENT_ANNOTATION,
FEATURE_BASE_NAME_LANGUAGE,
)

_validator_optional_string = validators.optional(validators.instance_of(str))
Expand Down
4 changes: 2 additions & 2 deletions cassis/xmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from cassis.typesystem import (
_LIST_TYPES,
_PRIMITIVE_ARRAY_TYPES,
_PRIMITIVE_LIST_TYPES,
FEATURE_BASE_NAME_BEGIN,
FEATURE_BASE_NAME_END,
FEATURE_BASE_NAME_HEAD,
Expand Down Expand Up @@ -295,7 +294,8 @@ def deserialize(self, source: Union[IO, str], typesystem: TypeSystem, lenient: b
else:
view = cas.create_view(sofa.sofaID, xmiID=sofa.xmiID, sofaNum=sofa.sofaNum)

# Directly set the sofaString and offsetConverter for the sofa to avoid recomputing the offset convertion (slow!) when using the setter
# Directly set the sofaString and offsetConverter for the sofa to avoid recomputing the offset convertion
# (slow!) when using the setter
view.get_sofa()._sofaString = sofa.sofaString
view.get_sofa()._offset_converter = sofa._offset_converter
view.sofa_mime = sofa.mimeType
Expand Down
Loading

0 comments on commit 3bf380c

Please sign in to comment.