Skip to content

Commit

Permalink
Read version from pyproject.toml instead of acsoo.cfg
Browse files Browse the repository at this point in the history
Towards removing acsoo.cfg
  • Loading branch information
sbidoul committed Sep 21, 2022
1 parent 95f22da commit b888b14
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
24 changes: 20 additions & 4 deletions acsoo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import os
from configparser import NoOptionError, NoSectionError, RawConfigParser
from pathlib import Path

import click
import tomli

DEFAULT_CONFIG_FILE = "acsoo.cfg"
SECTION = "acsoo"
Expand All @@ -31,6 +33,10 @@ def __init__(self, filename):
)
self.__cfgfile = filename
self.__cfg.read(filename)
pyproject_path = Path("pyproject.toml")
self.__pyproject = {}
if pyproject_path.is_file():
self.__pyproject = tomli.loads(pyproject_path.read_text())

@staticmethod
def add_default_map_reader(reader):
Expand All @@ -44,9 +50,13 @@ def get_default_map(self):

@property
def series(self):
r = self.__cfg.get(SECTION, "series")
r = self.__pyproject.get("tool", {}).get("hatch-odoo", {}).get(
"odoo_version_override", None
) or self.__cfg.get(SECTION, "series")
if not r:
raise click.ClickException("Missing series in {}.".format(self.__cfgfile))
raise click.ClickException(
"Odoo series not found in pyproject.toml and {}.".format(self.__cfgfile)
)
if r not in ("14.0", "15.0", "16.0"):
raise click.ClickException(
"Unsupported series {} in {}.".format(r, self.__cfgfile)
Expand All @@ -55,9 +65,15 @@ def series(self):

@property
def version(self):
r = self.__cfg.get(SECTION, "version")
r = self.__pyproject.get("project", {}).get("version", None) or self.__cfg.get(
SECTION, "version"
)
if not r:
raise click.ClickException("Missing version in {}.".format(self.__cfgfile))
raise click.ClickException(
"Missing version in pyproject.toml and {}.".format(self.__cfgfile)
)
if r.startswith(self.series + ".") and len(r.split(".")) > 4:
r = r[len(self.series) + 1 :]
return r

@property
Expand Down
2 changes: 0 additions & 2 deletions acsoo/templates/project/+project.name+/acsoo.cfg.bob
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
[acsoo]
trigram={{{ project.trigram }}}
series={{{ odoo.series }}}
version=1.0.0
2 changes: 1 addition & 1 deletion acsoo/templates/project/+project.name+/pyproject.toml.bob
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ packages = ["odoo"]

[tool.hatch-odoo]
# If our addons have non standard version numbers, let's help hatch-odoo discover the Odoo version.
#odoo_version_override = "16.0"
odoo_version_override = "{{{ odoo.series }}}"
# Add dependencies that are not declared in Odoo addons manifests.
dependencies = [
"click-odoo-contrib",
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ install_requires =
setuptools # must use odoo-autodiscover>=2 in Odoo<=10
wheel>=0.29
httpx
tomli

[options.entry_points]
console_scripts =
Expand Down

0 comments on commit b888b14

Please sign in to comment.