summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-02-03 00:04:48 +1100
committerDamien George <damien@micropython.org>2023-02-24 11:40:22 +1100
commitce9f7cd00ab683e6b9a56d519525ba9d0fab63d0 (patch)
tree6cf8bf4ab1fb520ce678ad55c419c8d2f2900650
parent8d9a7fd22836de6aa16c9d208212092805fc5641 (diff)
tools/mpremote: Use hatch to build mpremote package.
This allows the entire configuration to be defined in a single file, including the logic for including pyboard.py and automatically versioning based on the git tag. Building the package works both via `python -m build` as well as `hatch build`. `python -m build ` has the advantage of automatically fetching all dependencies, you don't need to manually install any hatch packages. In order to make the versioning work, and also keep things simpler for end users, mpremote releases will now be the same as MicroPython releases and use the same tag. The version strings for mpremote will look like: - X.Y.Z -- clean build at the tag - X.Y.Z.postN+gHASH -- clean build, N revisions from the most recent tag - X.Y.Z.postN+gHASH.dYYYYMMDD -- dirty build, N revisions from out This commit extends on the idea from #8404. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r--tools/mpremote/.gitignore1
-rw-r--r--tools/mpremote/mpremote/__init__.py13
-rw-r--r--tools/mpremote/pyproject.toml54
-rw-r--r--tools/mpremote/requirements.txt2
-rw-r--r--tools/mpremote/setup.cfg25
5 files changed, 66 insertions, 29 deletions
diff --git a/tools/mpremote/.gitignore b/tools/mpremote/.gitignore
new file mode 100644
index 000000000..849ddff3b
--- /dev/null
+++ b/tools/mpremote/.gitignore
@@ -0,0 +1 @@
+dist/
diff --git a/tools/mpremote/mpremote/__init__.py b/tools/mpremote/mpremote/__init__.py
index 6a9beea82..d1416230b 100644
--- a/tools/mpremote/mpremote/__init__.py
+++ b/tools/mpremote/mpremote/__init__.py
@@ -1 +1,12 @@
-__version__ = "0.4.0"
+try:
+ from importlib.metadata import version, PackageNotFoundError
+
+ try:
+ __version__ = version("mpremote")
+ except PackageNotFoundError:
+ # Error loading package version (e.g. running from source).
+ __version__ = "0.0.0-local"
+except ImportError:
+ # importlib.metadata not available (e.g. CPython <3.8 without
+ # importlib_metadata compatibility package installed).
+ __version__ = "0.0.0-unknown"
diff --git a/tools/mpremote/pyproject.toml b/tools/mpremote/pyproject.toml
index 374b58cbf..1b6c2173d 100644
--- a/tools/mpremote/pyproject.toml
+++ b/tools/mpremote/pyproject.toml
@@ -1,6 +1,54 @@
[build-system]
requires = [
- "setuptools>=42",
- "wheel"
+ "hatchling",
+ "hatch-requirements-txt",
+ "hatch-vcs",
]
-build-backend = "setuptools.build_meta"
+build-backend = "hatchling.build"
+
+[project]
+name = "mpremote"
+description = "Tool for interacting remotely with MicroPython devices"
+readme = "README.md"
+authors = [
+ {name = "Damien George", email = "damien@micropython.org"},
+]
+urls = {Homepage = "https://github.com/micropython/micropython"}
+keywords = [
+ "hardware",
+ "micropython",
+]
+license = {text = "MIT"}
+classifiers = [
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: MIT License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python :: 3",
+ "Topic :: Software Development :: Embedded Systems",
+ "Topic :: System :: Hardware",
+]
+requires-python = ">=3.4"
+dynamic = ["dependencies", "version"]
+
+[project.scripts]
+mpremote = "mpremote.main:main"
+
+[tool.hatch.metadata.hooks.requirements_txt]
+files = ["requirements.txt"]
+
+[tool.hatch.version]
+source = "vcs"
+tag-pattern = "(?P<version>v(\\d+).(\\d+).(\\d+))"
+raw-options = { root = "../..", version_scheme = "post-release" }
+
+[tool.hatch.build]
+packages = ["mpremote"]
+
+# Also grab pyboard.py from /tools and add it to the package for both wheel and sdist.
+[tool.hatch.build.force-include]
+"../pyboard.py" = "mpremote/pyboard.py"
+
+# Workaround to allow `python -m build` to work.
+[tool.hatch.build.targets.sdist.force-include]
+"../pyboard.py" = "mpremote/pyboard.py"
+"requirements.txt" = "requirements.txt"
diff --git a/tools/mpremote/requirements.txt b/tools/mpremote/requirements.txt
new file mode 100644
index 000000000..e4ca98fca
--- /dev/null
+++ b/tools/mpremote/requirements.txt
@@ -0,0 +1,2 @@
+pyserial >= 3.3
+importlib_metadata >= 1.4
diff --git a/tools/mpremote/setup.cfg b/tools/mpremote/setup.cfg
deleted file mode 100644
index 7fae3cbcb..000000000
--- a/tools/mpremote/setup.cfg
+++ /dev/null
@@ -1,25 +0,0 @@
-[metadata]
-name = mpremote
-version = 0.4.0
-author = Damien George
-author_email = damien@micropython.org
-description = Tool for interacting remotely with MicroPython
-long_description = file: README.md
-long_description_content_type = text/markdown
-url = https://github.com/micropython/micropython
-project_urls =
- Bug Tracker = https://github.com/micropython/micropython/issues
-classifiers =
- Programming Language :: Python :: 3
- License :: OSI Approved :: MIT License
- Operating System :: OS Independent
-
-[options]
-packages = mpremote
-python_requires = >= 3.4
-install_requires =
- pyserial >= 3.3
-
-[options.entry_points]
-console_scripts =
- mpremote = mpremote.main:main