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

Refactor build process #1630

Merged
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude = build,.git,.tox
extend-ignore = E203
max-line-length = 88
114 changes: 114 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Release

on:
push:
branches:
- main
# for testing only
- release-4

jobs:
build:
name: Build Distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/django-import-export
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v1.2.3
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/django-import-export

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ dist/
.vscode

tests/database.db

# generated by setuptools-scm
import_export/_version.py
65 changes: 6 additions & 59 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,12 @@
## Release process

#### Pre release

- Set up `.pypirc` file to reference both pypi and testpypi.

#### Release

- Ensure that all code has been committed and integration tests have run on Github.
- If pushing directly to `main` branch, ensure this is done on the correct remote repo.
- `make messages` is intended to be run now to keep the translation files up-to-date.
- Run this if there have been any translations updates for the release. It is recommended to run this prior to any minor release.
- This creates updates to all translation files so there is no need to commit these unless there have been any translation changes.
- If 'no module named settings' error is seen, try unsetting `DJANGO_SETTINGS_MODULE` environment variable.

```bash
# check out clean version
# all git operations will be run against this source repo
git clone git@github.com:django-import-export/django-import-export.git django-import-export-rel

cd django-import-export-rel

# checkout any feature branch at this point
# git checkout develop

python3 -m venv venv
source venv/bin/activate
pip install -U pip setuptools wheel

pip install --exists-action=w --no-cache-dir -r requirements/deploy.txt

# zest.releaser pre-release
# (you can set the correct version in this step)
prerelease
```
The existing manual release process has been replaced with Github Actions as part of the CI / CD workflow.
This has been implemented using [this guide](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)

#### Perform the release

For the first pass you may choose not to upload only to testpypi (not pypi) so that you can check the release. You can check the release by manually downloading the files from testPyPI and checking the contents.

Once the test file have been checked, run again to upload to PyPI.

```bash
release

# resets the version and pushes changes to origin
postrelease

# remove the rel copy - no longer required
deactivate
cd ..
rm -rf django-import-export-rel
```

#### Add Release to Github

- Go to [Github releases](https://github.com/django-import-export/django-import-export/releases)
- Click 'Draft a new release'
- Enter the version number (e.g. 3.1.0)
- Select the correct tag
- Publish the release

### Check readthedocs
Now the release will be triggered on any commit to main and uploaded to TestPypi.
If the release is tagged, then a release to Pypi will occur.

Login to [readthedocs.org](https://readthedocs.org) to check that the build ran OK (click on 'Builds' tab).
To create a new published release, follow the instructions [here](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
Ensure you create the new tag to correspond with the release as required.
5 changes: 3 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Changelog
=========

3.3.2 (unreleased)
4.0.0 (unreleased)
------------------

- Nothing changed yet.
- Refactor build process (#1630)


3.3.1 (2023-09-14)
Expand Down Expand Up @@ -93,6 +93,7 @@ Documentation
3.1.0 (2023-02-21)
------------------

- Float and Decimal widgets use LANGUAGE_CODE on export (#1501)
- Add optional dehydrate method param (#1536)

- ``exceptions`` module has been undeprecated
Expand Down
14 changes: 4 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from importlib.metadata import version

import django

Expand Down Expand Up @@ -41,16 +42,9 @@
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
try:
from import_export import __version__

# The short X.Y version.
version = ".".join(__version__.split(".")[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
except ImportError:
version = release = "dev"
release = version("django-import-export")
# for example take major/minor
version = ".".join(release.split(".")[:2])

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand Down
14 changes: 13 additions & 1 deletion import_export/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
__version__ = "3.3.2.dev0"
try:
# https://smarie.github.io/python-getversion/#package-versioning-best-practices
# -- Distribution mode --
# import from _version.py generated by setuptools_scm during release
from ._version import version as __version__
except ImportError:
# -- Source mode --
# use setuptools_scm to get the current version from src using git
from os import path as _path

from setuptools_scm import get_version as _gv

__version__ = _gv(_path.join(_path.dirname(__file__), _path.pardir))
10 changes: 5 additions & 5 deletions import_export/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def import_row(
using_transactions=True,
dry_run=False,
raise_errors=None,
**kwargs
**kwargs,
):
"""
Imports data from ``tablib.Dataset``. Refer to :doc:`import_workflow`
Expand Down Expand Up @@ -848,7 +848,7 @@ def import_data(
use_transactions=None,
collect_failed_rows=False,
rollback_on_validation_errors=False,
**kwargs
**kwargs,
):
"""
Imports data from ``tablib.Dataset``. Refer to :doc:`import_workflow`
Expand Down Expand Up @@ -899,7 +899,7 @@ def import_data(
raise_errors,
using_transactions,
collect_failed_rows,
**kwargs
**kwargs,
)
if using_transactions and (
dry_run
Expand All @@ -917,7 +917,7 @@ def import_data_inner(
using_transactions,
collect_failed_rows,
rollback_on_validation_errors=None,
**kwargs
**kwargs,
):
if rollback_on_validation_errors is not None:
warnings.warn(
Expand Down Expand Up @@ -956,7 +956,7 @@ def import_data_inner(
using_transactions=using_transactions,
dry_run=dry_run,
row_number=i,
**kwargs
**kwargs,
)
if self._meta.use_bulk:
# persist a batch of rows
Expand Down
63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "django-import-export"
authors = [
{name = "Bojan Mihelač", email = "djangoimportexport@gmail.com"},
]
maintainers = [
{name = "Matthew Hegarty", email = "djangoimportexport@gmail.com"},
]
description = "Django application and library for importing and exporting data with included admin integration."
keywords = ["django", "import", "export"]
license = {file = "LICENSE"}
requires-python = ">=3.8"
dynamic = ["version", "readme"]
classifiers = [
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development",
]

dependencies = [
"diff-match-patch",
"Django>=3.2",
"tablib[html,ods,xls,xlsx,yaml]==3.5.0",
]

[project.urls]
Documentation = "https://django-import-export.readthedocs.io/en/stable/"
Repository = "https://github.com/django-import-export/django-import-export"
Changelog = "https://github.com/django-import-export/django-import-export/blob/main/docs/changelog.rst"

[tool.setuptools]
platforms = ["OS Independent"]
license-files = ["LICENSE"]

[tool.setuptools.dynamic]
version = {attr = "import_export.__init__.__version__"}
readme = {file = ["README.rst"]}

[tool.setuptools_scm]
write_to = "import_export/_version.py"

[tool.isort]
profile = "black"

[tool.coverage.run]
parallel = true
source = "import_export"
1 change: 0 additions & 1 deletion requirements/deploy.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
wheel
zest.releaser
18 changes: 0 additions & 18 deletions setup.cfg

This file was deleted.