-
Notifications
You must be signed in to change notification settings - Fork 23
/
tasks.py
170 lines (132 loc) · 5.25 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
import sys
from pathlib import Path
from invoke import task
from rellu import ReleaseNotesGenerator, Version, initialize_labels
from rellu.tasks import clean # noqa
assert Path.cwd() == Path(__file__).parent # noqa: S101
REPOSITORY = "robotframework/PythonLibCore"
VERSION_PATH = Path("src/robotlibcore/__init__.py")
VERSION_PATTERN = '__version__ = "(.*)"'
RELEASE_NOTES_PATH = Path("docs/PythonLibCore-{version}.rst")
RELEASE_NOTES_TITLE = "Python Library Core {version}"
RELEASE_NOTES_INTRO = """
`Python Library Core`_ is a generic component making it easier to create
bigger `Robot Framework`_ test libraries. Python Library Core {version} is
a new release with **UPDATE** enhancements and bug fixes. **MORE intro stuff**
**REMOVE this section with final releases or otherwise if release notes contain
all issues.**
All issues targeted for Python Library Core {version.milestone} can be found
from the `issue tracker`_.
**REMOVE ``--pre`` from the next command with final releases.**
If you have pip_ installed, just run
::
pip install --pre --upgrade pip install robotframework-pythonlibcore
to install the latest available release or use
::
pip install pip install robotframework-pythonlibcore=={version}
to install exactly this version. Alternatively you can download the source
distribution from PyPI_ and install it manually.
Python Library Core {version} was released on {date}.
.. _PythonLibCore: https://github.com/robotframework/PythonLibCore
.. _Robot Framework: http://robotframework.org
.. _pip: http://pip-installer.org
.. _PyPI: https://pypi.python.org/pypi/robotframework-robotlibcore
.. _issue tracker: https://github.com/robotframework/PythonLibCore/issues?q=milestone%3A{version.milestone}
"""
@task
def set_version(ctx, version): # noqa: ARG001
"""Set project version in ``src/robotlibcore.py`` file.
Args:
version: Project version to set or ``dev`` to set development version.
Following PEP-440 compatible version numbers are supported:
- Final version like 3.0 or 3.1.2.
- Alpha, beta or release candidate with ``a``, ``b`` or ``rc`` postfix,
respectively, and an incremented number like 3.0a1 or 3.0.1rc1.
- Development version with ``.dev`` postfix and an incremented number like
3.0.dev1 or 3.1a1.dev2.
When the given version is ``dev``, the existing version number is updated
to the next suitable development version. For example, 3.0 -> 3.0.1.dev1,
3.1.1 -> 3.1.2.dev1, 3.2a1 -> 3.2a2.dev1, 3.2.dev1 -> 3.2.dev2.
"""
version = Version(version, VERSION_PATH, VERSION_PATTERN)
version.write()
print(version)
@task
def print_version(ctx): # noqa: ARG001
"""Print the current project version."""
print(Version(path=VERSION_PATH))
@task
def release_notes(ctx, version=None, username=None, password=None, write=False): # noqa: FBT002, ARG001
"""Generates release notes based on issues in the issue tracker.
Args:
version: Generate release notes for this version. If not given,
generated them for the current version.
username: GitHub username.
password: GitHub password.
write: When set to True, write release notes to a file overwriting
possible existing file. Otherwise, just print them to the
terminal.
Username and password can also be specified using ``GITHUB_USERNAME`` and
``GITHUB_PASSWORD`` environment variable, respectively. If they aren't
specified at all, communication with GitHub is anonymous and typically
pretty slow.
"""
version = Version(version, VERSION_PATH)
file = RELEASE_NOTES_PATH if write else sys.stdout
generator = ReleaseNotesGenerator(
REPOSITORY,
RELEASE_NOTES_TITLE,
RELEASE_NOTES_INTRO,
)
generator.generate(version, username, password, file)
@task
def init_labels(ctx, username=None, password=None): # noqa: ARG001
"""Initialize project by setting labels in the issue tracker.
Args:
username: GitHub username.
password: GitHub password.
Username and password can also be specified using ``GITHUB_USERNAME`` and
``GITHUB_PASSWORD`` environment variable, respectively.
Should only be executed once when taking ``rellu`` tooling to use or
when labels it uses have changed.
"""
initialize_labels(REPOSITORY, username, password)
@task
def lint(ctx):
in_ci = os.getenv("GITHUB_WORKFLOW")
print("Run ruff")
ruff_cmd = ["ruff", "check"]
if not in_ci:
ruff_cmd.append("--fix")
ruff_cmd.append("./src")
ruff_cmd.append("./tasks.py")
ruff_cmd.append("./utest")
ctx.run(" ".join(ruff_cmd))
print("Run black")
ctx.run("black src/ tasks.py utest atest/run.py")
print("Run tidy")
print(f"Lint Robot files {'in ci' if in_ci else ''}")
command = [
"robotidy",
"--transform",
"RenameTestCases",
"-c",
"RenameTestCases:capitalize_each_word=True",
"--lineseparator",
"unix",
"atest/",
]
if in_ci:
command.insert(1, "--check")
command.insert(1, "--diff")
ctx.run(" ".join(command))
@task
def atest(ctx):
ctx.run("python atest/run.py")
@task
def utest(ctx):
ctx.run("python utest/run.py")
@task(utest, atest)
def test(ctx):
pass