Skip to content

Commit

Permalink
Refactor nox task names (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Nov 13, 2024
1 parent fc2fc48 commit 2e4803a
Show file tree
Hide file tree
Showing 23 changed files with 105 additions and 104 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Run lint
run: poetry run nox -s lint
run: poetry run nox -s lint:code

- name: Upload Artifacts
uses: actions/[email protected]
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Run type-check
run: poetry run nox -s type-check
run: poetry run nox -s lint:typing

Security:
name: Security Checks (Python-${{ matrix.python-version }})
Expand All @@ -108,7 +108,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Run security linter
run: poetry run nox -s security
run: poetry run nox -s lint:security

- name: Upload Artifacts
uses: actions/[email protected]
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Run Tests and Collect Coverage
run: poetry run nox -s coverage -- -- --db-version ${{ matrix.exasol-version }}
run: poetry run nox -s test:coverage -- -- --db-version ${{ matrix.exasol-version }}

- name: Upload Artifacts
uses: actions/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cp security-python3.9/.security.json ../
- name: Generate Report
run: poetry run nox -s report -- -- --format json | tee metrics.json
run: poetry run nox -s project:report -- -- --format json | tee metrics.json

- name: Upload Artifacts
uses: actions/[email protected]
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Generate GitHub Summary
run: |
echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY
poetry run nox -s report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY
Expand Down
21 changes: 17 additions & 4 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
## 🚨 Breaking Changes

* Dropped python 3.8 support
* Changed names of Documentation related nox tasks
- `build-docs` -> `docs:build`
- `open-docs` -> `docs:open`
- `clean-docs` -> `docs:clean`
* Changed names of all nox tasks

| Old Name | New Name | Description |
|--------------------|------------------------|----------------------------------------------------------------|
| fix | project:fix | Runs all automated fixes on the code base |
| check | project:check | Runs all available checks on the project |
| report | project:report | Collects and generates metrics summary for the workspace |
| unit-tests | test:unit | Runs all unit tests |
| integration-tests | test:integration | Runs all the integration tests |
| coverage | test:coverage | Runs all tests (unit + integration) and reports the code coverage |
| lint | lint:code | Runs the static code analyzer on the project |
| type-check | lint:typing | Runs the type checker on the project |
| security | lint:security | Runs the security linter on the project |
| build-build | docs:build | Builds the project documentation |
| open-open | docs:open | Opens the built project documentation |
| clean-docs | docs:clean | Removes the documentations build folder |
| prepare-release | release:prepare | Prepares the project for a new release |

## ✨ Added

Expand Down
2 changes: 1 addition & 1 deletion doc/developer_guide/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This can be achieved by running the following command:

.. code-block:: shell
nox -s prepare-release -- <major>.<minor>.<patch>
nox -s release:prepare -- <major>.<minor>.<patch>
Replace `<major>`, `<minor>`, and `<patch>` with the appropriate version numbers.
Once the PR is successfully merged, the release can be triggered (see next section).
Expand Down
2 changes: 1 addition & 1 deletion doc/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Tooling
Projects
________

Projects can run the nox task :code:`nox -s report` to generate their project metrics if they are using the :code:`exasol-toolbox`.
Projects can run the nox task :code:`nox -s project:report` to generate their project metrics if they are using the :code:`exasol-toolbox`.


Development
Expand Down
21 changes: 12 additions & 9 deletions doc/user_guide/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Execute the unit tests of the project:

.. code-block:: shell
nox -s unit-tests
nox -s test:unit
.. _existing:
Expand Down Expand Up @@ -184,17 +184,20 @@ You are ready to use the toolbox. With *nox -l* you can list all available tasks
$ nox -l
Sessions defined in <PATH_TO_YOUR_PROJECT>/noxfile.py:
* fix -> Runs all automated fixes on the code base
- check -> Runs all available checks on the project
- lint -> Runs the linter on the project
- type-check -> Runs the type checker on the project
- unit-tests -> Runs all unit tests
- integration-tests -> Runs the all integration tests
- coverage -> Runs all tests (unit + integration) and reports the code coverage
* project:fix -> Runs all automated fixes on the code base
- project:check -> Runs all available checks on the project
- project:report -> Collects and generates metrics summary for the workspace
- test:unit -> Runs all unit tests
- test:integration -> Runs the all integration tests
- test:coverage -> Runs all tests (unit + integration) and reports the code coverage
- lint:code -> Runs the static code analyzer on the project
- lint:typing -> Runs the type checker on the project
- lint:security -> Runs the security linter on the project
- docs:multiversion -> Builds the multiversion project documentation
- docs:build -> Builds the project documentation
- docs:open -> Opens the built project documentation
- docs:clean -> Removes the documentations build folder
- report -> Collects and generates a metrics summary for the workspace
- release:prepare -> Prepares the project for a new release.
sessions marked with * are selected, sessions marked with - are skipped.
Expand Down
2 changes: 1 addition & 1 deletion exasol/toolbox/nox/_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _build_multiversion_docs(session: nox.Session, config: Config) -> None:

@nox.session(name="docs:multiversion", python=False)
def build_multiversion(session: Session) -> None:
"""Builds the project documentation"""
"""Builds the multiversion project documentation"""
_build_multiversion_docs(session, PROJECT_CONFIG)


Expand Down
2 changes: 1 addition & 1 deletion exasol/toolbox/nox/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _pyupgrade(session: Session, files: Iterable[str]) -> None:
)


@nox.session(python=False)
@nox.session(name="project:fix", python=False)
def fix(session: Session) -> None:
"""Runs all automated fixes on the code base"""
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
Expand Down
8 changes: 4 additions & 4 deletions exasol/toolbox/nox/_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ def _security_lint(session: Session, files: Iterable[str]) -> None:
)


@nox.session(python=False)
@nox.session(name="lint:code", python=False)
def lint(session: Session) -> None:
"""Runs the linter on the project"""
"Runs the static code analyzer on the project"
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_pylint(session, py_files)


@nox.session(name="type-check", python=False)
@nox.session(name="lint:typing", python=False)
def type_check(session: Session) -> None:
"""Runs the type checker on the project"""
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_type_check(session, py_files)


@nox.session(name="security", python=False)
@nox.session(name="lint:security", python=False)
def security_lint(session: Session) -> None:
"""Runs the security linter on the project"""
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
Expand Down
11 changes: 6 additions & 5 deletions exasol/toolbox/nox/_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from noxconfig import PROJECT_CONFIG


@nox.session(name="report", python=False)
@nox.session(name="project:report", python=False)
def report(session: Session) -> None:
"""
Collects and generates metrics summary for the workspace
Expand All @@ -28,11 +28,12 @@ def report(session: Session) -> None:
* :code:`rm .coverage .lint.txt`
* Run the following targets:
- :code:`nox -s coverage`
- :code:`nox -s lint`
- :code:`nox -s test:coverage`
- :code:`nox -s lint:code`
- :code:`nox -s lint:security`
"""
formats = tuple(fmt.name.lower() for fmt in Format)
usage = "nox -s report -- [options]"
usage = "nox -s project:report -- [options]"
parser = argparse.ArgumentParser(
description="Generates status report for the project", usage=usage
)
Expand All @@ -51,7 +52,7 @@ def report(session: Session) -> None:
)
if not all(file.exists() for file in required_files):
session.error(
"Please make sure you run the `coverage`, `security` and the `lint` target first"
"Please make sure you run the `test:coverage`, `lint:security` and the `lint:code` target first"
)
sha1 = str(
session.run("git", "rev-parse", "HEAD", external=True, silent=True)
Expand Down
29 changes: 3 additions & 26 deletions exasol/toolbox/nox/_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

def _create_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="nox -s prepare-release",
usage="nox -s prepare-release -- [-h] version",
prog="nox -s release:prepare",
usage="nox -s release:prepare -- [-h] version",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
Expand Down Expand Up @@ -89,7 +89,7 @@ def _add_files_to_index(session: Session, files: list[Path]) -> None:
session.run("git", "add", f"{file}")


@nox.session(name="prepare-release", python=False)
@nox.session(name="release:prepare", python=False)
def prepare_release(session: Session, python=False) -> None:
"""
Prepares the project for a new release.
Expand Down Expand Up @@ -146,26 +146,3 @@ def prepare_release(session: Session, python=False) -> None:
"--body",
'""',
)


@nox.session(name="release", python=False)
def release(session: Session, python=False) -> None:
"""
Creates a new release and publishing it to GitHub and pypi.
"""
session.error("Not implemented yet")
# Precondition(s):
# Convert ci-cd.yml workflow to cd.yml workflow
# Tests validation can be skipped. Branch protection together with
# PR and merge validation shoudl be sufficient
# ----------------------------------------------------------------------
# 0. Check that version isn't released yet (tag does not exist (origin))
# 0.1. update git information
# 0.2. check if origin does not have the tag yet
# 1. check if current branch is main/master
# 2. build wheel/package
# 3. create release tag
# 4. push release tag to origin
# 5. publish on gh
# 5. publish on pypi
# 6. output relase message/information
6 changes: 3 additions & 3 deletions exasol/toolbox/nox/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ def _coverage(
session.run(*command)


@nox.session(name="unit-tests", python=False)
@nox.session(name="test:unit", python=False)
def unit_tests(session: Session) -> None:
"""Runs all unit tests"""
context = _context(session, coverage=False)
_unit_tests(session, PROJECT_CONFIG, context)


@nox.session(name="integration-tests", python=False)
@nox.session(name="test:integration", python=False)
def integration_tests(session: Session) -> None:
"""
Runs the all integration tests
Expand All @@ -93,7 +93,7 @@ def integration_tests(session: Session) -> None:
_integration_tests(session, PROJECT_CONFIG, context)


@nox.session(name="coverage", python=False)
@nox.session(name="test:coverage", python=False)
def coverage(session: Session) -> None:
"""Runs all tests (unit + integration) and reports the code coverage"""
context = _context(session, coverage=True)
Expand Down
59 changes: 32 additions & 27 deletions exasol/toolbox/nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,57 @@
]


import argparse

import nox
from nox import Session

from exasol.toolbox.nox._documentation import (
build_docs,
clean_docs,
open_docs,
)
from exasol.toolbox.nox._format import (
_code_format,
_pyupgrade,
fix,
)

# fmt: off
# isort: off
from noxconfig import PROJECT_CONFIG


@nox.session(name="project:check", python=False)
def check(session: Session) -> None:
"""Runs all available checks on the project"""
context = _context(session, coverage=True)
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_version(session, Mode.Check, PROJECT_CONFIG.version_file)
_pyupgrade(session, py_files)
_code_format(session, Mode.Check, py_files)
_pylint(session, py_files)
_type_check(session, py_files)
_coverage(session, PROJECT_CONFIG, context)

from exasol.toolbox.nox._metrics import report
from exasol.toolbox.nox._test import (
_coverage,
coverage,
integration_tests,
unit_tests,
)
from exasol.toolbox.nox._lint import (
_pylint,
_type_check,
lint,
type_check,
)
from exasol.toolbox.nox._metrics import report
from exasol.toolbox.nox._documentation import (
build_docs,
clean_docs,
open_docs,
)
from exasol.toolbox.nox._release import prepare_release
from exasol.toolbox.nox._shared import (
Mode,
_context,
_version,
python_files,
)
from exasol.toolbox.nox._test import (
_coverage,
coverage,
integration_tests,
unit_tests,
)
from noxconfig import PROJECT_CONFIG


@nox.session(name="check", python=False)
def check(session: Session) -> None:
"""Runs all available checks on the project"""
context = _context(session, coverage=True)
py_files = [f"{file}" for file in python_files(PROJECT_CONFIG.root)]
_version(session, Mode.Check, PROJECT_CONFIG.version_file)
_pyupgrade(session, py_files)
_code_format(session, Mode.Check, py_files)
_pylint(session, py_files)
_type_check(session, py_files)
_coverage(session, PROJECT_CONFIG, context)
# isort: on
# fmt: on
2 changes: 1 addition & 1 deletion exasol/toolbox/pre_commit_hooks/package_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
_VERSION_MODULE_TEMPLATE = cleandoc('''
# ATTENTION:
# This file is generated by exasol/toolbox/pre_commit_hooks/package_version.py when using:
# * either "poetry run nox -s fix"
# * either "poetry run nox -s project:fix"
# * or "poetry run version-check <path/version.py> --fix"
# Do not edit this file manually!
# If you need to change the version, do so in the project.toml, e.g. by using `poetry version X.Y.Z`.
Expand Down
4 changes: 3 additions & 1 deletion exasol/toolbox/sphinx/multiversion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,9 @@ def _main(args, argv):
os.path.join(args.outputdir, "index.html"), "w", encoding="utf-8"
) as f:
versions = [
ref.name for ref in gitrefs if re.match(config.smv_tag_whitelist, ref.name)
ref.name
for ref in gitrefs
if re.match(config.smv_tag_whitelist, ref.name)
]
versions = sorted(
versions, key=lambda v: ExasolVersion.from_string(v), reverse=True
Expand Down
Loading

0 comments on commit 2e4803a

Please sign in to comment.