Skip to content
Snippets Groups Projects
Commit fc1fc1c9 authored by Manon Blanco's avatar Manon Blanco Committed by Yoann Schneider
Browse files

Use `pyproject.toml` to handle versioning

parent fcea4d09
No related branches found
No related tags found
1 merge request!458Use `pyproject.toml` to handle versioning
Pipeline #146613 passed
......@@ -26,6 +26,8 @@ repos:
- id: name-tests-test
args: ['--django']
- id: check-json
- id: check-toml
exclude: "^worker-{{cookiecutter.slug}}/pyproject.toml$"
- id: requirements-txt-fixer
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
......
.PHONY: release
release:
$(eval version:=$(shell cat VERSION))
echo $(version)
git commit VERSION -m "Version $(version)"
# Grep the version from pyproject.toml, squeeze multiple spaces, delete double and single quotes, get 3rd val.
# This command tolerates multiple whitespace sequences around the version number.
$(eval version:=$(shell grep -m 1 version pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3))
echo Releasing version $(version)
git commit pyproject.toml -m "Version $(version)"
git tag $(version)
git push origin master $(version)
0.3.6-rc3
......@@ -24,7 +24,8 @@ At Teklia, we use a simple version of [Git Flow][gitflow]:
- Developments should happen in branches, with merge requests to enable code
review and Gitlab CI pipelines.
- Project maintainers should use Git tags to create official releases, by
updating the `VERSION` file and using the same version string as the tag name.
updating the `project.version` key of the `pyproject.toml` file and using
the same version string as the tag name.
This process is reflected the template's `.gitlab-ci.yml` file.
......
......@@ -53,8 +53,8 @@ package, a Docker build, with the best development practices:
`setup.py`
: Configures the worker's Python package.
`VERSION`
: Official version number of your worker. Defaults to `0.1.0`.
`pyproject.toml`
: Configures the worker's Python package.
`ci/build.sh`
: Script that gets run by [CI](ci/index.md) pipelines
......
......@@ -4,8 +4,9 @@ build-backend = "setuptools.build_meta"
[project]
name = "arkindex-base-worker"
version = "0.3.6-rc3"
description = "Base Worker to easily build Arkindex ML workflows"
dynamic = ["version", "dependencies", "optional-dependencies"]
dynamic = ["dependencies", "optional-dependencies"]
authors = [
{ name = "Teklia", email = "contact@teklia.com" },
]
......@@ -34,8 +35,8 @@ Repository = "https://gitlab.teklia.com/workers/base-worker"
Authors = "https://teklia.com"
[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
optional-dependencies = {docs = { file = ["docs-requirements.txt"] }}
dependencies = { file = ["requirements.txt"] }
optional-dependencies = { docs = { file = ["docs-requirements.txt"] } }
[tool.ruff]
exclude = [".git", "__pycache__"]
......@@ -52,6 +53,8 @@ select = [
"I",
# Implicit Optional
"RUF013",
# Invalid pyproject.toml
"RUF200",
# pyupgrade
"UP",
# flake8-bugbear
......
#!/usr/bin/env python
from pathlib import Path
from setuptools import find_packages, setup
setup(
version=Path("VERSION").read_text().strip(),
packages=find_packages(),
)
setup(packages=find_packages())
......@@ -8,7 +8,7 @@ RUN apt-get update -q -y && apt-get install -q -y --no-install-recommends curl
# Install worker as a package
COPY worker_{{cookiecutter.slug}} worker_{{cookiecutter.slug}}
COPY requirements.txt setup.py VERSION ./
COPY requirements.txt setup.py pyproject.toml ./
RUN pip install . --no-cache-dir
# Add archi local CA
......
include requirements.txt
include VERSION
.PHONY: release
release:
$(eval version:=$(shell cat VERSION))
# Grep the version from pyproject.toml, squeeze multiple spaces, delete double and single quotes, get 3rd val.
# This command tolerates multiple whitespace sequences around the version number.
$(eval version:=$(shell grep -m 1 version pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3))
echo Releasing version $(version)
git commit VERSION -m "Version $(version)"
git commit pyproject.toml -m "Version $(version)"
git tag $(version)
git push origin master $(version)
0.1.0
[project]
name = "worker_{{ cookiecutter.slug }}"
version = "0.1.0"
description = "{{ cookiecutter.description }}"
dynamic = ["dependencies"]
requires-python = ">=3.10"
[project.scripts]
worker-{{ cookiecutter.slug }} = "worker_{{ cookiecutter.slug }}.worker:main"
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
[tool.ruff]
exclude = [".git", "__pycache__"]
ignore = ["E501"]
......
......@@ -2,52 +2,14 @@
# -*- coding: utf-8 -*-
import re
from pathlib import Path
from typing import List
from setuptools import find_packages, setup
MODULE = "worker_{{cookiecutter.slug}}"
COMMAND = "worker-{{cookiecutter.slug}}"
SUBMODULE_PATTERN = re.compile("-e ((?:(?!#egg=).)*)(?:#egg=)?(.*)")
def parse_requirements_line(line: str) -> str:
# Special case for git requirements
if line.startswith("git+http"):
assert "@" in line, "Branch should be specified with suffix (ex: @master)"
assert (
"#egg=" in line
), "Package name should be specified with suffix (ex: #egg=kraken)"
package_name: str = line.split("#egg=")[-1]
return f"{package_name} @ {line}"
# Special case for submodule requirements
elif line.startswith("-e"):
package_path, package_name = SUBMODULE_PATTERN.match(line).groups()
package_path: Path = Path(package_path).resolve()
# Package name is optional: use folder name by default
return f"{package_name or package_path.name} @ file://{package_path}"
else:
return line
def parse_requirements() -> List[str]:
path = Path(__file__).parent.resolve() / "requirements.txt"
assert path.exists(), f"Missing requirements: {path}"
return list(
map(parse_requirements_line, map(str.strip, path.read_text().splitlines()))
)
setup(
name=MODULE,
version=open("VERSION").read(),
description="{{ cookiecutter.description }}",
author="{{ cookiecutter.author }}",
author_email="{{ cookiecutter.email }}",
install_requires=parse_requirements(),
entry_points={"console_scripts": [f"{COMMAND}={MODULE}.worker:main"]},
packages=find_packages(),
python_requires=">=3.10",
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment