From e23f1dd3c29851c5130f075b55d0341012785629 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Fri, 9 Jun 2023 10:27:19 -0400 Subject: [PATCH 1/2] From to setup.cfg+setuptools to pyproject.toml+hatch --- Makefile | 57 ++++++++++++++++++++++++++++++++++-- docs/contributing.md | 3 +- pyproject.toml | 69 ++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 56 ----------------------------------- setup.py | 2 -- umap/__init__.py | 8 +---- 6 files changed, 126 insertions(+), 69 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/Makefile b/Makefile index 16166160..e9d16ec5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,32 @@ +.DEFAULT_GOAL := help + +.PHONY: install +install: ## Install the dependencies + python3 -m pip install --upgrade pip + python3 -m pip install -e . + +.PHONY: develop +develop: ## Install the test and dev dependencies + python3 -m pip install -e .[test,dev] + +.PHONY: version +version: ## Display the current version + @hatch version + +.PHONY: bump +bump: ## Bump the current version to a new minor one + @hatch version fix + +.PHONY: docker +docker: ## Create a new Docker image and publish it + $(eval VERSION=$(shell hatch version)) + @echo "Version to build: ${VERSION}" + docker build -t umap/umap:${VERSION} . + docker push umap/umap:${VERSION} + + test: py.test -xv umap/tests/ -develop: - pip install -e .[test,dev] release: test compilemessages python setup.py sdist bdist_wheel test_publish: @@ -33,14 +58,42 @@ tx_pull: jsdir = umap/static/umap/js/ filepath = "${jsdir}*.js" +.PHONY: pretty pretty: ## Apply PrettierJS to all JS files (or specified `filepath`) ./node_modules/prettier/bin-prettier.js --write ${filepath} +.PHONY: lebab lebab: ## Convert JS `filepath` to modern syntax with Lebab, then prettify ./node_modules/lebab/bin/index.js --replace ${filepath} --transform arrow,arrow-return ./node_modules/lebab/bin/index.js --replace ${filepath} --transform let ./node_modules/lebab/bin/index.js --replace ${filepath} --transform template $(MAKE) pretty filepath=${filepath} +.PHONY: lebab-all lebab-all: $(jsdir)* ## Convert all JS files to modern syntax with Lebab + prettify for file in $^ ; do $(MAKE) lebab filepath=$${file}; done + + +.PHONY: help +help: + @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) + +# See https://daniel.feldroy.com/posts/autodocumenting-makefiles +define PRINT_HELP_PYSCRIPT # start of Python section +import re, sys + +output = [] +# Loop through the lines in this file +for line in sys.stdin: + # if the line has a command and a comment start with + # two pound signs, add it to the output + match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) + if match: + target, help = match.groups() + output.append("\033[36m%-20s\033[0m %s" % (target, help)) +# Sort the output in alphanumeric order +output.sort() +# Print the help result +print('\n'.join(output)) +endef +export PRINT_HELP_PYSCRIPT # End of python section diff --git a/docs/contributing.md b/docs/contributing.md index 524c4411..05f7f8da 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -71,8 +71,7 @@ Now, the `umap` command will be available. To test your code, you will add to install umap from your git folder. Go to `~/wk/umap` and run: - pip install -e . - # or pip install -e ~/wk/umap + make install This command will check dependencies and install uMap from sources inside folder. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..f608ac8c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,69 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "umap-project" +dynamic = ["version"] +description = "Create maps with OpenStreetMap layers in a minute and embed them in your site." +readme = "README.md" +authors = [ + { name = "Yohan Boniface", email = "yb@enix.org" }, +] +maintainers = [ + { name = "David Larlet", email = "david@larlet.fr" }, +] +homepage = "https://github.com/umap-project/umap" +keywords = ["django", "leaflet", "geodjango", "openstreetmap", "map"] +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "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", +] +dependencies = [ + "Django>=4.1", + "django-agnocomplete==2.2.0", + "django-compressor==4.3.1", + "django-environ==0.10.0", + "Pillow==9.5.0", + "psycopg2==2.9.6", + "requests==2.30.0", + "social-auth-core==4.4.2", + "social-auth-app-django==5.2.0", +] + +[project.optional-dependencies] +dev = [ + "hatch==1.7.0", + "black==21.10b0", + "mkdocs==1.2.3", +] +test = [ + "factory-boy==3.2.1", + "pytest==6.2.5", + "pytest-django==4.5.2", +] +docker = [ + "uwsgi==2.0.21", +] + +[project.scripts] +umap = "umap.bin:main" + +[tool.hatch.version] +path = "umap/__init__.py" + +[tool.flake8] +# Black crazyness. +max-line-length = 88 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 725ed52f..00000000 --- a/setup.cfg +++ /dev/null @@ -1,56 +0,0 @@ -[metadata] -name = umap-project -version = 1.3.3 -description = Create maps with OpenStreetMap layers in a minute and embed them in your site. -long_description = file: README.md -long_description_content_type = text/markdown -author = Yohan Boniface -homepage = https://github.com/umap-project/umap -keywords = django leaflet geodjango openstreetmap map -classifiers = - Development Status :: 4 - Beta - Intended Audience :: Developers - Operating System :: OS Independent - Topic :: Software Development :: Libraries :: Python Modules - Programming Language :: Python - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - 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 - -[options] -packages = find: -include_package_data = True -install_requires = - Django>=4.1 - django-agnocomplete==2.2.0 - django-compressor==4.3.1 - django-environ==0.10.0 - Pillow==9.5.0 - psycopg2==2.9.6 - requests==2.30.0 - social-auth-core==4.4.2 - social-auth-app-django==5.2.0 - -[options.extras_require] -dev = - black==21.10b0 - mkdocs==1.2.3 -test = - factory-boy==3.2.1 - pytest==6.2.5 - pytest-django==4.5.2 -docker = - uwsgi==2.0.21 - -[options.entry_points] -console_scripts = - umap = umap.bin:main - -[flake8] -# Black crazyness. -max-line-length = 88 diff --git a/setup.py b/setup.py deleted file mode 100644 index 8bf1ba93..00000000 --- a/setup.py +++ /dev/null @@ -1,2 +0,0 @@ -from setuptools import setup -setup() diff --git a/umap/__init__.py b/umap/__init__.py index 046a98f3..e371c8ac 100644 --- a/umap/__init__.py +++ b/umap/__init__.py @@ -1,7 +1 @@ -try: - import pkg_resources -except ImportError: # pragma: no cover - pass -else: - if __package__: - VERSION = pkg_resources.get_distribution("umap-project").version +VERSION = "1.3.3" From 9ad47f8ef9eccf2e8927713613fcedffe4c94896 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Sat, 17 Jun 2023 09:36:50 -0400 Subject: [PATCH 2/2] Customize the build process with hatch --- Makefile | 6 ++++-- pyproject.toml | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e9d16ec5..ebea95cf 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,13 @@ docker: ## Create a new Docker image and publish it docker build -t umap/umap:${VERSION} . docker push umap/umap:${VERSION} +.PHONY: build +build: test compilemessages ## Build the Python package before release + @hatch build + test: py.test -xv umap/tests/ -release: test compilemessages - python setup.py sdist bdist_wheel test_publish: twine upload -r testpypi dist/* publish: diff --git a/pyproject.toml b/pyproject.toml index f608ac8c..318b4ee1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,14 @@ docker = [ "uwsgi==2.0.21", ] +[tool.hatch.build.targets.sdist] +include = [ + "/umap", +] + +[tool.hatch.build.targets.wheel] +packages = ["umap"] + [project.scripts] umap = "umap.bin:main"