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

Migrate to poetry #26

Merged
merged 17 commits into from
Dec 12, 2023
39 changes: 30 additions & 9 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'
Comment on lines -15 to 16

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add 3.12?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using flake8-django for linting, it doesn't support python 3.12 yet until PR doesn't merged rocioar/flake8-django#134

django-version:
Expand All @@ -37,20 +36,42 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dependencies

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Cache poetry dependencies
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install local dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction

- name: Install Django
run: |
pip install --upgrade pip wheel setuptools
pip install --requirement requirements/local_build.txt
pip install 'django${{ matrix.django-version }}'
poetry run pip install 'django${{ matrix.django-version }}'

- name: Prepare env
run: |
inv ci.prepare
poetry run inv ci.prepare

- name: Run checks ${{ matrix.python-version }}
run: inv git.run-hooks
run: poetry run inv pre-commit.run-hooks

- name: Upload results to coveralls
run: |
pip install coveralls
coveralls --service=github
poetry run pip install coveralls
poetry run coveralls --service=github

env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
45 changes: 38 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ repos:
- id: isort
name: isort (python)

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
exclude: node_modules|migrations|scripts|.venv|__init__.py
additional_dependencies: [
# A flake8 plugin that checks django code style.
# https://github.com/rocioar/flake8-django
flake8-django,
# required by flake8-django
django,
django_extensions,
# A plugin for Flake8 finding likely bugs and design problems in your program.
# https://github.com/PyCQA/flake8-bugbear
flake8-bugbear,
# A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
# https://github.com/m-burst/flake8-pytest-style
flake8-pytest-style,
# A flake8 plugin that warn about backslashes usage.
# https://github.com/wemake-services/flake8-broken-line
flake8-broken-line,
# A simple module that adds an extension for the fantastic pydocstyle tool to flake8.
# https://github.com/PyCQA/flake8-docstrings
flake8-docstrings,
# McCabe complexity checker.
# https://github.com/PyCQA/mccabe
mccabe,
# A flake8 plug-in loading the configuration from pyproject.toml
flake8-pyproject,
]

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
hooks:
Expand Down Expand Up @@ -44,20 +75,20 @@ repos:
types: [ file ]
stages: [ push ]

- id: linters
name: run linters
entry: inv linters.all
- id: tests
name: run tests
entry: inv ci.coverage
language: system
pass_filenames: false
types: [ python ]
stages: [ push ]

- id: tests
name: run tests
entry: inv tests.run-ci
- id: mypy
name: mypy
entry: inv mypy.run
language: system
pass_filenames: false
types: [ python ]
types: [ file ]
stages: [ push ]

- id: package_installation_verify
Expand Down
16 changes: 12 additions & 4 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ build:
os: ubuntu-22.04
tools:
python: "3.11"
jobs:
# Job for install dependencies with poetry
# Docs: https://docs.readthedocs.io/en/stable/build-customization.html#install-dependencies-with-poetry
post_create_environment:
# https://python-poetry.org/docs/#installing-manually
- pip install -U poetry
# Tell poetry to not use a virtual environment
- poetry config virtualenvs.create false
post_install:
# Install dependencies with 'docs' dependency group
# https://python-poetry.org/docs/managing-dependencies/#dependency-groups
- poetry install --with docs

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

python:
install:
- requirements: requirements/development.txt
11 changes: 4 additions & 7 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ Ready to contribute? Here's how to set up `django-import-export-extensions` for
3. Setup virtual environment using pyenv::

$ pyenv install 3.11
$ pyenv virtualenv 3.11 django-import-export-extensions
$ pyenv local django-import-export-extensions
$ pyenv activate django-import-export-extensions
$ pip install -r requirements/local_build.txt
$ inv project.init
$ pyenv shell $(pyenv latest 3.11)
$ poetry config virtualenvs.in-project true
$ poetry env use $(which python) && poetry install && source .venv/bin/activate

4. Create a branch for local development::

Expand All @@ -82,8 +80,7 @@ Ready to contribute? Here's how to set up `django-import-export-extensions` for
5. When you're done making changes, check that your changes pass flake8 and the
tests::

$ inv tests.run
$ inv linters.all
$ inv pre-commit.run-hooks

6. Commit your changes and push your branch to GitHub::

Expand Down
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ History

UNRELEASED
------------------
* Drop support of python 3.9
* Migrate from pip-tools to poetry
* Add base model for ``ImportJob`` and ``ExportJob``
* Extend import results template: show validation errors in table
* Add force-import feature: skip rows with errors while importing
Expand Down
6 changes: 3 additions & 3 deletions Makefile
yalef marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test: ## run tests quickly with the default Python
pytest

coverage: ## check code coverage quickly with the default Python
coverage run --source import_export_extensions --omit import_export_extensions/migrations -m pytest
coverage run -m pytest
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html
Expand All @@ -63,10 +63,10 @@ servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .

release: dist ## package and upload a release
twine upload dist/*
poetry publish

dist: clean ## builds source and wheel package
python -m build .
poetry build
ls -l dist

install: clean ## install the package to the active Python's site-packages
Expand Down
8 changes: 4 additions & 4 deletions import_export_extensions/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ def clean(

"""
if not value:
return []
return [] # pragma: no cover

# if value is one integer number
value = str(value)

# in some cases if click `enter` values `\n\r` inserted
if self.instance_separator == "\n":
if self.instance_separator == "\n": # pragma: no cover
value = value.replace("\r", "")

raw_instances = utils.clean_sequence_of_string_values(
Expand Down Expand Up @@ -287,7 +287,7 @@ def __init__(self, filename: str):
def render(self, value: Model, *args, **kwargs) -> typing.Optional[str]:
"""Convert DB value to URL to file."""
if not value:
return None
return None # pragma: no cover
yalef marked this conversation as resolved.
Show resolved Hide resolved

if self._get_default_storage() == DEFAULT_SYSTEM_STORAGE:
return f"http://localhost:8000{value.url}"
Expand All @@ -297,7 +297,7 @@ def render(self, value: Model, *args, **kwargs) -> typing.Optional[str]:
def clean(self, value: str, *args, **kwargs) -> typing.Optional[str]:
"""Get the file and check for exists."""
if not value:
return None
return None # pragma: no cover

internal_url = utils.url_to_internal_value(urlparse(value).path)

Expand Down
Loading