Skip to content

Commit

Permalink
Switch project builds to hatch (#259)
Browse files Browse the repository at this point in the history
* Adopt Hatch for packaging

* Add black config

* Formatting

* Replicate requirements in pyproject.toml

* Update project file

* Order classifiers

* Use hatch for PyPI publishing

* Update tox to use hatch, extra dependencies
  • Loading branch information
bennylope authored Nov 23, 2023
1 parent 5b97807 commit da77baa
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 39 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Publish package to PyPI

on:
on:
push:
branches: [master]
release:
Expand All @@ -21,13 +21,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install hatch
- name: Build and publish distribution
if: (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')) || github.event_name == 'release'
env:
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
hatch build
hatch publish
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
History
=======

2.4.0
-----

* Adopted Hatch as packaging tool with pyproject.toml

2.3.1
-----

Expand Down
75 changes: 75 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[project]
name = "django-organizations"
authors = [
{ name="Ben Lopatin", email="[email protected]" },
]
description = "Group accounts for Django"
readme = "README.rst"
requires-python = ">=3.8"
license = {text = "BSD License"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = [
"Django>=3.2",
"django-extensions>=2.0.8",
]
dynamic = ["version"]

[project.urls]
"Source" = "https://github.com/bennylope/django-organizations"
"Issues" = "https://github.com/bennylope/django-organizations/issues"
"Documentation" = "https://django-organizations.readthedocs.io/en/latest/"

[project.optional-dependencies]
tests = [
"pytest>=6.0",
"coverage",
"pytest-django>=3.0.0",
"pytest-cov>=2.4.0",
# Required to test default models
"django-extensions>=2.0.8",
"django-autoslug>=1.9.8,",
# Required for mocking signals
"mock-django==0.6.9",
]
docs = [
"Sphinx==3.5.4",
"furo==2021.4.11b34",
]
dev = [
"django-organizations[tests]",
"tox",
"black",
"ruff",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build]
sources = ["src"]
directory = "dist/"

[tool.hatch.version]
path = "src/organizations/__init__.py"

[tool.hatch.build.targets.wheel]
only-include = ["src/organizations"]
packages = ["src/oranizations"]

[tool.black]
target-version = ["py311"]
8 changes: 0 additions & 8 deletions requirements-dev.txt

This file was deleted.

14 changes: 0 additions & 14 deletions requirements-test.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/organizations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = "Ben Lopatin"
__email__ = "[email protected]"
__version__ = "2.3.1"
__version__ = "2.4.0"
2 changes: 1 addition & 1 deletion src/organizations/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
class OrganizationsConfig(AppConfig):
name = "organizations"
verbose_name = "Organizations"
default_auto_field = 'django.db.models.AutoField'
default_auto_field = "django.db.models.AutoField"
2 changes: 1 addition & 1 deletion src/organizations/backends/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def email_message(
body_template,
sender=None,
message_class=EmailMessage,
**kwargs
**kwargs,
):
"""
Returns an email message for a new user. This can be easily overridden.
Expand Down
4 changes: 2 additions & 2 deletions src/organizations/backends/modeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def send_invitation(self, invitation, **kwargs):
self.invitation_subject,
self.invitation_body,
invitation.invited_by,
**kwargs
**kwargs,
).send()

def email_message(
Expand All @@ -167,7 +167,7 @@ def email_message(
body_template, # type: Text
sender=None, # type: Optional[AbstractUser]
message_class=EmailMessage,
**kwargs
**kwargs,
):
"""
Returns an invitation email message. This can be easily overridden.
Expand Down
1 change: 1 addition & 0 deletions src/organizations/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


class OwnershipRequired(Exception):
"""
Exception to raise if the owner is being removed before the
Expand Down
6 changes: 3 additions & 3 deletions src/organizations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def save(self, *args, **kwargs):
"domain": get_current_site(self.request),
"organization": self.organization,
"sender": self.request.user,
}
},
)
# Send a notification email to this user to inform them that they
# have been added to a new organization.
Expand All @@ -101,7 +101,7 @@ def save(self, *args, **kwargs):
"domain": get_current_site(self.request),
"organization": self.organization,
"sender": self.request.user,
}
},
)
return OrganizationUser.objects.create(
user=user,
Expand Down Expand Up @@ -156,7 +156,7 @@ def save(self, **kwargs):
"organization": self.cleaned_data["name"],
"sender": self.request.user,
"created": True,
}
},
)
is_active = False
return create_organization(
Expand Down
2 changes: 1 addition & 1 deletion src/organizations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_organization(
is_active=None,
org_defaults=None,
org_user_defaults=None,
**kwargs
**kwargs,
):
"""
Returns a new organization, also creating an initial organization user who
Expand Down
2 changes: 1 addition & 1 deletion src/organizations/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def post(self, request, *args, **kwargs):
"domain": get_current_site(self.request),
"organization": self.organization,
"sender": request.user,
}
},
)
return redirect(self.get_success_url())

Expand Down
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ python =
3.11: py311
3.12: py312

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=0.22", "hatch-vcs>=0.2"]

[testenv]
package = wheel
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/organizations
commands = pytest {posargs} --cov=organizations
Expand All @@ -25,11 +30,11 @@ basepython =
py311: python3.11
py312: python3.12
deps =
setuptools>=49.6.0
hatch>=1.7.0
django32: Django>=3.2,<4
django41: Django>=4.1,<4.2
django42: Django>=4.2,<4.3
-r{toxinidir}/requirements-test.txt
extras = tests

[testenv:flake8]
basepython=python3
Expand Down

0 comments on commit da77baa

Please sign in to comment.