Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project template improvements #92

Merged
merged 23 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0ed6904
project template: pre-commit autoupdate
sbidoul Sep 20, 2022
3077752
project template: Modernize gitaggregate
sbidoul Sep 20, 2022
65563f2
project template: drop support for old pythons and Odoos
sbidoul Sep 20, 2022
46002ce
project template: use hatch-odoo
sbidoul Sep 20, 2022
0922e68
Update pre-commit config
sbidoul Sep 20, 2022
2099aa2
Fix flake8 warning
sbidoul Sep 20, 2022
9065488
Fix test that relied on Odoo 10 support
sbidoul Sep 20, 2022
e54e559
project template: use latest odoo-ci image
sbidoul Sep 20, 2022
8203ec5
Read version from pyproject.toml instead of acsoo.cfg
sbidoul Sep 21, 2022
93ea590
tag_requirements: don't require trigram
sbidoul Sep 21, 2022
b4b14a2
We don't need acsoo.cfg anymore \o/
sbidoul Sep 21, 2022
16c5a84
project template: make manifest black-compliant
sbidoul Sep 24, 2022
f22d1e8
project template: add dummy test
sbidoul Sep 24, 2022
944db0c
project template: add scripts package
sbidoul Sep 24, 2022
e7dcd53
project template: improve build and install
sbidoul Sep 24, 2022
7e6454b
project template: tweak coverage
sbidoul Sep 24, 2022
89deeb5
project template: capitalize name
sbidoul Sep 24, 2022
506dbbb
project template: python_version selection
sbidoul Sep 24, 2022
03a215e
Don't run tests in project template while testing acsoo
sbidoul Sep 24, 2022
8ea0072
project template: pytest is for dev
sbidoul Oct 3, 2022
e09a2a8
project template: coverage report test files
sbidoul Oct 3, 2022
818b7d3
project template: test after install
sbidoul Oct 3, 2022
82d1429
project template: add acsoo.cfg with checklog example
sbidoul Oct 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.8.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -21,18 +21,18 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
name: flake8 except __init__.py
exclude: /__init__\.py$
additional_dependencies: ["flake8-bugbear==20.1.4"]
additional_dependencies: ["flake8-bugbear==22.9.11"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.38.0
hooks:
- id: pyupgrade
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
exclude: /__init__\.py$
41 changes: 22 additions & 19 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,38 +50,35 @@ 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))
if r not in (
"8.0",
"9.0",
"10.0",
"11.0",
"12.0",
"13.0",
"14.0",
"15.0",
"16.0",
):
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)
)
return r

@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
def trigram(self):
r = self.__cfg.get(SECTION, "trigram")
if not r:
raise click.ClickException("Missing trigram in {}.".format(self.__cfgfile))
return r
return self.__cfg.get(SECTION, "trigram", fallback="")

@property
def pushable(self):
Expand Down
14 changes: 7 additions & 7 deletions acsoo/tag_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def _get_last_sha(filename):
return check_output(["git", "log", "-n", "1", "--format=%h", filename]).strip()


def _has_tag_local(series, trigram, sha, repo_dir):
tag_re = re.compile(series + "[-_]" + trigram + "[-_]")
def _has_tag_local(series, sha, repo_dir):
tag_re = re.compile(series + "[-_]")
tags = check_output(["git", "tag", "--points-at", sha], cwd=repo_dir)
for tag in tags.split():
tag = tag.strip()
Expand All @@ -60,9 +60,9 @@ def _has_tag_local(series, trigram, sha, repo_dir):
return False


def _has_tag_remote(series, trigram, sha, repo_url):
def _has_tag_remote(series, sha, repo_url):
prefix = "refs/tags/"
tag_re = re.compile(prefix + series + "[-_]" + trigram + "[-_]")
tag_re = re.compile(prefix + series + "[-_]")
tag_lines = check_output(
["git", "ls-remote", "-t", repo_url], universal_newlines=True
)
Expand All @@ -84,7 +84,7 @@ def _is_committed(requirement):


def _ensure_tag(config, req, sha, repo_url, eggtag, dry_run):
ex_tag = _has_tag_remote(config.series, config.trigram, sha, repo_url)
ex_tag = _has_tag_remote(config.series, sha, repo_url)
if ex_tag:
click.echo("tag {ex_tag} already exists on {repo_url}@{sha}".format(**locals()))
return
Expand Down Expand Up @@ -130,7 +130,7 @@ def do_tag_requirements(config, src, requirement, yes, dry_run=False):
if not os.path.isdir(os.path.join(repo_dir, ".git")):
os.makedirs(repo_dir)
check_call(["git", "init"], cwd=repo_dir)
ex_tag = _has_tag_local(config.series, config.trigram, sha, repo_dir)
ex_tag = _has_tag_local(config.series, sha, repo_dir)
if ex_tag:
# this assumes that if we find the tag locally
# it is also present on the remote, in rare situations
Expand All @@ -150,7 +150,7 @@ def do_tag_requirements(config, src, requirement, yes, dry_run=False):
],
cwd=repo_dir,
)
ex_tag = _has_tag_local(config.series, config.trigram, sha, repo_dir)
ex_tag = _has_tag_local(config.series, sha, repo_dir)
if ex_tag:
click.echo("tag {ex_tag} already exists on {url}@{sha}".format(**locals()))
continue
Expand Down
29 changes: 1 addition & 28 deletions acsoo/templates/hooks.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
import os
import shutil

ODOO_PYTHON2 = ("8.0", "9.0", "10.0")
ODOO_KEEP_INIT_PY = ODOO_PYTHON2
ODOO_LEGACY_NS = ("8.0", "9.0")


def pre_render_project(configurator):
variables = configurator.variables
odoo_series = variables["odoo.series"]

if odoo_series in ODOO_PYTHON2:
python_version = "python"
else:
python_version = "python3"

configurator.variables["python_version"] = python_version
configurator.variables["odoo.major"] = int(odoo_series.split(".")[0])


def post_render_project(configurator):
variables = configurator.variables
root = configurator.target_directory
root = os.path.join(root, variables["project.name"])
odoo_series = variables["odoo.series"]
if odoo_series in ODOO_LEGACY_NS:
shutil.rmtree(os.path.join(root, "odoo"))
else:
shutil.rmtree(os.path.join(root, "odoo_addons"))

if odoo_series not in ODOO_KEEP_INIT_PY:
# Delete init file
filename = "__init__.py"
os.remove(os.path.join(root, "odoo", filename))
os.remove(os.path.join(root, "odoo", "addons", filename))
...
10 changes: 1 addition & 9 deletions acsoo/templates/project/+project.name+/.bumpversion.cfg.bob
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ commit = False

[bumpversion:file:.bumpversion.cfg]

[bumpversion:file:acsoo.cfg]
[bumpversion:file:pyproject.toml]

{{% if odoo.series in ['8.0', '9.0'] %}}
[bumpversion:file:odoo_addons/{{{ project.trigram }}}_all/__openerp__.py]

[bumpversion:file:odoo_addons/server_environment_files/dev/dev.conf]

[bumpversion:file:odoo_addons/server_environment_files/test/test.conf]
{{% else %}}
[bumpversion:file:odoo/addons/{{{ project.trigram }}}_all/__manifest__.py]

[bumpversion:file:odoo/addons/server_environment_files/dev/dev.conf]

[bumpversion:file:odoo/addons/server_environment_files/test/test.conf]
{{% endif %}}
19 changes: 16 additions & 3 deletions acsoo/templates/project/+project.name+/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[run]
omit=
venv*
src*
source =
./odoo/addons
dynamic_context = test_function
branch = True
parallel = True

[report]
omit =
*/scenarios/*
*/lib/*
*/__manifest__.py

# Regexes for lines to exclude from consideration
exclude_lines =
pragma: no cover
raise NotImplementedError
2 changes: 1 addition & 1 deletion acsoo/templates/project/+project.name+/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/src
/release
/release*/
/.project
/.settings
/.pydevproject
Expand Down
68 changes: 39 additions & 29 deletions acsoo/templates/project/+project.name+/.gitlab-ci.yml.bob
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ before_script:
}

variables:
PYTHON: {{{ python_version }}}
PYTHON: python{{{ project.python_version }}}

pre-commit:
stage: test
image: python:3
image: python:{{{ project.python_version }}}
cache:
key: pre-commit
paths:
Expand All @@ -36,25 +36,36 @@ build:
stage: build
# use odoo-{{{ odoo.series }}} runner so we have the pre-cloned odoo
# except for that optimization, we don't need odoo dependencies for this job
image: ghcr.io/acsone/odoo-ci-image:v20210928.0
image: ghcr.io/acsone/odoo-ci-image:v20220907.0
tags:
- odoo-{{{ odoo.series }}}
script:
{{% if odoo.enterprise -%}}
- start_ssh_agent
- virtualenv --python=$PYTHON venv
- venv/bin/pip wheel --no-deps -r requirements.txt -e . --wheel-dir=./release
{{% endif -%}}
- virtualenv --python=$PYTHON venv && source venv/bin/activate
# install pinned build dependencies
- pip install "--only-binary=:all:" -r requirements-build.txt
# download/build all dependencies, with --no-build-isolation,
# to use the pinned build deps we just installed
- |
for group in '' '-test' '-doc' '-build' ; do
pip wheel --no-build-isolation --use-pep517 --wheel-dir=./release${group} -r requirements${group}.txt
done
# build the project
- pip wheel --no-build-isolation --no-index --no-deps --wheel-dir=./release-project .
artifacts:
expire_in: 1 week
paths:
- release/
- release*/
name: "${CI_PROJECT_NAME}-${CI_JOB_ID}-build"
interruptible: true

.test_common:
stage: test
tags:
- odoo-{{{ odoo.series }}}
image: ghcr.io/acsone/odoo-ci-image:v20210928.0
image: ghcr.io/acsone/odoo-ci-image:v20220907.0
needs:
- job: build
artifacts: true
Expand All @@ -63,45 +74,40 @@ build:
license_check:
extends: .test_common
script:
- virtualenv --python=$PYTHON venv
- source venv/bin/activate
- pip install --no-index --find-links ./release -r requirements.txt
- virtualenv --python=$PYTHON venv && source venv/bin/activate
- pip install --no-deps --no-index ./release/*.whl
- manifestoo -d odoo/addons check-licenses

dev_status_check:
extends: .test_common
script:
- virtualenv --python=$PYTHON venv
- source venv/bin/activate
- pip install --no-index --find-links ./release -r requirements.txt
- virtualenv --python=$PYTHON venv && source venv/bin/activate
- pip install --no-deps --no-index ./release/*.whl
- manifestoo -d odoo/addons check-dev-status --default-dev-status=Beta

{{% if odoo.series in ['8.0', '9.0'] %}}
{{% set odoocmd = 'openerp-server' %}}
{{% else %}}
{{% set odoocmd = 'odoo' %}}
{{% endif %}}
test:
extends: .test_common
variables:
DB_NAME: "${CI_PROJECT_NAME}-${CI_JOB_ID}"
script:
- pipx install acsoo # for checklog
- start_ssh_agent # for pushing translations
- virtualenv --python=$PYTHON venv
- venv/bin/pip install coverage
- virtualenv --python=$PYTHON venv && source venv/bin/activate
# use --no-index so missing dependencies that would not be in *.whl are detected
# install the project in editable mode (-e) so coverage sees it
- venv/bin/pip install --no-index --find-links release -e .
- pip install --no-index --find-links=./release --find-links=./release-build --find-links=./release-test -e .[test]
- ADDONS_INIT=$(manifestoo -d odoo/addons list-depends --separator=,)
- echo Installing ${ADDONS_INIT}
- unbuffer venv/bin/click-odoo-initdb -c odoo-ci.cfg --new-database ${DB_NAME} --cache-prefix {{{ project.trigram }}} -m ${ADDONS_INIT} | acsoo checklog
- echo Installing dependent addons ${ADDONS_INIT}
- unbuffer click-odoo-initdb -c odoo-ci.cfg --new-database ${DB_NAME} --cache-prefix {{{ project.trigram }}} -m ${ADDONS_INIT} | acsoo checklog
- ADDONS_TEST=$(manifestoo -d odoo/addons list --separator=,)
- echo Testing ${ADDONS_TEST}
- unbuffer venv/bin/coverage run --branch venv/bin/{{{ odoocmd }}} -c odoo-ci.cfg -d ${DB_NAME} --stop-after-init --no-xmlrpc -i ${ADDONS_TEST} --test-enable | acsoo checklog
- venv/bin/coverage html
- venv/bin/coverage report
- if [ "${CI_COMMIT_REF_NAME}" = "master" ] ; then makepot ; fi
- echo Installing project addons ${ADDONS_TEST}
- unbuffer coverage run venv/bin/odoo -c odoo-ci.cfg -d ${DB_NAME} --stop-after-init -i ${ADDONS_TEST} | acsoo checklog
- echo Testing project addons ${ADDONS_TEST}
- unbuffer coverage run venv/bin/odoo -c odoo-ci.cfg -d ${DB_NAME} --stop-after-init --test-tags ${ADDONS_TEST} --test-enable | acsoo checklog
- coverage combine
- coverage html --show-contexts
- coverage xml
- coverage report # Show coverage report so the GitLab coverage regex below works
- if [ "${CI_COMMIT_REF_NAME}" = "master" ] ; then start_ssh_agent ; makepot ; fi
after_script:
- dropdb --if-exists ${DB_NAME}
coverage: '/TOTAL\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+\%)/'
Expand All @@ -110,6 +116,10 @@ test:
paths:
- htmlcov/
name: "${CI_PROJECT_NAME}-${CI_JOB_ID}-coverage-html"
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml

deploy-test:
stage: deploy
Expand Down
Loading