Skip to content

Commit

Permalink
replace setup.py with pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 7, 2023
1 parent c38cb92 commit f4e1600
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 111 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m pip install flake8 wheel
python -m pip install django==${{ matrix.django-version }}
python -m pip install djangorestframework==${{ matrix.drf-version }}
Expand All @@ -103,6 +104,8 @@ jobs:
celery -A tests worker &
- name: Test with unittest
run: python -m unittest discover -s tests -t . -v
- name: Test build
run: python -m build
npm:
name: "@wq/${{ matrix.package }}"
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -148,6 +151,7 @@ jobs:
- name: Publish to Github Packages
if: github.event_name == 'push'
run: |
python -m pip install setuptools-scm
./set_dev_version.sh
cd packages/$PACKAGE
echo "registry=https://npm.pkg.github.com/wq" > .npmrc
Expand Down
2 changes: 1 addition & 1 deletion data_wizard/static/app/js/wizard.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion data_wizard/static/data_wizard/js/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions data_wizard/static/data_wizard/js/progress-element.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions data_wizard/static/srchash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f05d835901f7edd722a77ee4dd976e47bed47556555ce6c8ea991bc750cbc89f
7 changes: 7 additions & 0 deletions packages/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .builder import ready, build


if ready():
print("No changes since last build.")
else:
build()
40 changes: 40 additions & 0 deletions packages/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from setuptools.build_meta import *
from setuptools_scm import get_version
import warnings

import builder


default_build_sdist = build_sdist
default_build_wheel = build_wheel


class UnsupportedOperation(Exception):
pass


def ensure_js_build(autobuild=False):
if builder.ready():
return
builder.log_hash()
version = get_version()
if ".dev" in version:
warnings.warn(
"Speed up dev builds by running python -m packages.builder first."
)
if autobuild:
builder.build()
else:
raise UnsupportedOperation(
"Run python -m packages.builder and commit before releasing."
)


def build_sdist(*args, **kwargs):
ensure_js_build(False)
return default_build_sdist(*args, **kwargs)


def build_wheel(*args, **kwargs):
ensure_js_build(True)
return default_build_wheel(*args, **kwargs)
60 changes: 60 additions & 0 deletions packages/builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pathlib
import hashlib
import subprocess

root = pathlib.Path(__file__).parent.parent


def ready():
if get_stored_hash() == compute_hash():
return True
else:
return False


def get_hash_path():
return root / "data_wizard" / "static" / "srchash.txt"


def get_stored_hash():
return get_hash_path().read_text()


def set_stored_hash(value):
return get_hash_path().write_text(value)


def compute_hash(log=False):
sha = hashlib.sha256()

def add_files(pattern):
for path in sorted(root.glob(pattern)):
if log:
print(" ", path.relative_to(root))
sha.update(path.read_bytes())

add_files("packages/*/src/**/*.js")
add_files("packages/*/package.json")

return sha.hexdigest()


def log_hash():
print("Computing hash...")
new_hash = compute_hash(log=True)
print("Old Hash:", get_stored_hash())
print("New Hash:", new_hash)


def build():
subprocess.check_call(["npm", "install"])
subprocess.check_call(["npm", "run", "build"])
set_stored_hash(compute_hash())


if __name__ == "__main__":
if ready():
print("No changes since last build.")
else:
log_hash()
build()
5 changes: 4 additions & 1 deletion packages/progress-element/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ export default [
exports: 'named',
globals: { jquery: '$' },
banner,
file: `${dir}/dist/${name}.js`,
file: `data_wizard/static/data_wizard/js/${name}.js`,
format: 'umd',
sourcemap: true,
indent: false,
sourcemapPathTransform(path) {
return path.replace('../../../../', 'django-data-wizard/');
},
},
],
},
Expand Down
64 changes: 64 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "backend"
backend-path = ["packages"]

[project]
name = "data-wizard"
dynamic = ["version"]
authors = [
{name = "S. Andrew Sheppard", email = "andrew@wq.io"},
]
description = "Interactive web-based wizard for importing structured data into Django models."
readme = "README.md"
requires-python = ">=3.7"
license = {text = "MIT"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: JavaScript",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Topic :: Scientific/Engineering :: GIS",
"Topic :: Database :: Database Engines/Servers",
]
dependencies = [
"djangorestframework",
"itertable>=2.1.0",
"natural-keys",
"html-json-forms",
"python-dateutil",
]

[project.urls]
Homepage = "https://django-data-wizard.wq.io/"
Documentation = "https://django-data-wizard.wq.io/"
Source = "https://github.com/wq/django-data-wizard"
"Release Notes" = "https://django-data-wizard.wq.io/releases/"
Issues = "https://github.com/wq/django-data-wizard/issues"
CI = "https://github.com/wq/django-data-wizard/actions/workflows/test.yml"

[tool.setuptools]
packages = [
"data_wizard",
"data_wizard.backends",
"data_wizard.management",
"data_wizard.management.commands",
"data_wizard.migrations",
"data_wizard.sources",
"data_wizard.sources.migrations",
]

[tool.setuptools_scm]
2 changes: 1 addition & 1 deletion set_dev_version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
VERSION=`python3 setup.py --version | \
VERSION=`python -m setuptools_scm | \
sed s/\.dev/-dev/ | \
sed s/+/./ | \
sed "s/\.d[0-9]\{8\}$//" | \
Expand Down
Loading

0 comments on commit f4e1600

Please sign in to comment.