diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index fd2d1c3..f79e1f1 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -7,20 +7,20 @@ on: jobs: deploy: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + - uses: actions/checkout@v6 + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.12" + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + python -m pip install build + - name: Build distributions + run: python -m build + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore index aaa3a42..ec8a6db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc +__pycache__/ *.db .coverage MANIFEST diff --git a/dynamic_forms/__init__.py b/dynamic_forms/__init__.py index 6cf9a37..d7ae6f7 100644 --- a/dynamic_forms/__init__.py +++ b/dynamic_forms/__init__.py @@ -1,7 +1,5 @@ from django import forms -__version__ = "1.0.0" - def call_if_callable(value, *args, **kwargs): return value(*args, **kwargs) if callable(value) else value @@ -18,7 +16,7 @@ def __init__(self, field_class, *args, **kwargs): def make_real_field(self, form): return self.field_class( *(call_if_callable(arg, form) for arg in self.args), - **{name: call_if_callable(arg, form) for name, arg in self.kwargs.items()} + **{name: call_if_callable(arg, form) for name, arg in self.kwargs.items()}, ) def should_be_included(self, form): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1b6496f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" + +[project] +name = "django-forms-dynamic" +version = "1.0.0" +description = "Resolve form field arguments dynamically when a form is instantiated, not when it's declared." +readme = "README.md" +requires-python = ">=3.10" +license = "BSD-3-Clause" +license-files = ["LICENSE"] +authors = [{ name = "DabApps", email = "hello@dabapps.com" }] + +[project.urls] +Homepage = "https://github.com/dabapps/django-forms-dynamic" +Changelog = "https://github.com/dabapps/django-forms-dynamic/releases" +Issues = "https://github.com/dabapps/django-forms-dynamic/issues" + +[tool.setuptools.packages.find] +include = ["dynamic_forms*"] diff --git a/setup.py b/setup.py deleted file mode 100644 index e3f0ecc..0000000 --- a/setup.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from __future__ import print_function -from setuptools import setup -import re -import os - - -name = "django-forms-dynamic" -package = "dynamic_forms" -description = "Resolve form field arguments dynamically when a form is instantiated, not when it's declared." -url = "https://github.com/dabapps/django-forms-dynamic" -author = "DabApps" -author_email = "hello@dabapps.com" -license = "BSD" - -with open("README.md") as f: - readme = f.read() - - -def get_version(package): - """ - Return package version as listed in `__version__` in `init.py`. - """ - init_py = open(os.path.join(package, "__init__.py")).read() - return re.search("^__version__ = ['\"]([^'\"]+)['\"]", init_py, re.MULTILINE).group( - 1 - ) - - -def get_packages(package): - """ - Return root package and all sub-packages. - """ - return [ - dirpath - for dirpath, dirnames, filenames in os.walk(package) - if os.path.exists(os.path.join(dirpath, "__init__.py")) - ] - - -def get_package_data(package): - """ - Return all files under the root package, that are not in a - package themselves. - """ - walk = [ - (dirpath.replace(package + os.sep, "", 1), filenames) - for dirpath, dirnames, filenames in os.walk(package) - if not os.path.exists(os.path.join(dirpath, "__init__.py")) - ] - - filepaths = [] - for base, filenames in walk: - filepaths.extend([os.path.join(base, filename) for filename in filenames]) - return {package: filepaths} - - -setup( - name=name, - version=get_version(package), - url=url, - license=license, - description=description, - long_description=readme, - long_description_content_type="text/markdown", - author=author, - author_email=author_email, - packages=get_packages(package), - package_data=get_package_data(package), - python_requires=">=3.6", - project_urls={ - "Changelog": "https://github.com/dabapps/django-forms-dynamic/releases", - "Issues": "https://github.com/dabapps/django-forms-dynamic/issues", - } -)