This os.write function is a low-level function whose API changed
between Python 2.7 and Python 3.x. With Python 2.7, it takes
a string as a parameter, whereas with Python 3.x, it takes
a bytestring.
This commit re-implements the function so as to make it compatible
with both Python 2 and Python 3.7, by avoiding the call to os.write
entirely. Instead, we convert the the file descriptor that mkstemp
returned, and use the regular methods of the File class from there.
This allows us to use a "with" clause, combined with contextlib.closing
to automate the closing of that file once we're done writing to it.
Change-Id: Ie3a46d1c2672e801c56488f452dfcece33c0ea77
TN: T605-002
When running the style_checker through a Python 3 interpreter
(Python 3.8 to be precise), the style_checker fails to detect
invalid uses of DOS line endings.
This was detected by running the "dos_EOL" testcase from the current
testsuite, where the test_doseol_ko_1_adb test found the output
returned by the style_checker was missing the following errors:
doseol-ko-1.adb:1: DOS line ending is not allowed
doseol-ko-1.adb:2: DOS line ending is not allowed
doseol-ko-1.adb:3: DOS line ending is not allowed [...]
This is caused by a change of default behavior in the "open" builtin
when reading text files, where line endings are now automatically
translated to '\n', instead of being left untouched.
This commit fixes the issue in a way that keeps the code compatible
with both Python 2.7 and Python 3.x.
Change-Id: I7a30c728455b78b7abb9ea7b2efc93ede35aab19
TN: T605-002 (umbreall TN for the transition to Python 3)
TN: T728-038 (TN for this specific compatibility issue)
With Python 3, the output buffer returned by Popen.communicate is
a bytes object, whereas all users of this class expect a string.
This change makes the code compatible for both Python 2 and Python 3,
by checking the type of the string, and coverting it to a string
assuming a UTF-8 encoding if not.
Note that this introduces one new line of code. The current testsuite,
which can only be run using gnatpython, which is Python-2-based,
does not cover that line. It will be covered when the testsuite is
converted over to pytest and made Python-3-based. In the meantime,
we temporarily accept that one line of code not being covered.
Change-Id: I476825b3c70f50cc9e8874bfd4f86d14f281885d
TN: T605-002
The Config.__read_config_file method iterates over a dictionary's keys
while at the same time modifying the dictionary itself. With Python 2,
the dictionary's "keys" method was returning a copy of these keys,
so this was no problem. However, with Python 3, this is no a copy.
As a result, when run with a Python 3 interpreter, this part of
the style_checker crashes with:
RuntimeError: dictionary changed size during iteration
This commits makes the code compatible with both Python 2 and
Python 3.
Change-Id: I2a357707bbb12818e51388383ee5a4472aa61577
TN: T605-002
Fix one instance of a call to log_error where we pass an exception,
instead of passing the exception's args parameter (the function expects
either a string, or an iterable or strings).
This commit changes the call so as to be compatible with both Python 2.7
and Python 3.x.
Change-Id: I26c86d0c0a4d1c5dfb268bd9b0615be32a17bb33
TN: T605-002
This commit allows the few testcases that were calling the style_checker
directly to now do so by calling self.run_style_checker instead.
This centralizes the way the style_checker is called, which is
a useful enhancement in and of itself. The other upside is that
it should make it easier to transition the testsuite to a different
framework, one that is independent of gnatpython or e3, should we
want to (the framework itself is currently self-sufficient; it would
be nice if we could make the testsuite not depend on those either,
since this is a project used by contributors outside of AdaCore).
Change-Id: I3640c504426d23d363db16069551249946400e8d
TN: T605-002
Currently, this method accepts a **run_kwargs argument, with
documentation saying that these arguments are simply passed down
to the Run class. This gets in the way when one wants to add
more named arguments taking a default value which are not
related to the Run class, something I'd like to do in a separate
commit.
So, this commit first renames the **run_kwargs argument into
a **kwargs argument, to avoid the confusion that kwargs is
exclusively used in the "call" to the "Run" class.
It then modifies the implementation to iterate over the kwargs
dictionary, picking the arguments this method support, and raising
an exception for the arguments that it does not support. At the moment,
the only argument the testsuite uses is "input", so that's the only
one that's include in this commit. More will be needed if/when needed.
A note explaining why we rely on *args and **kwargs for this method's
signature is also added, to clarify the intent.
Change-Id: I362883b1f2481b8c43b68d38fd3b49feee6565ef
TN: T605-002
This simplifies the call to the style_checker, and also avoids
duplicating how the style checker is being called.
Change-Id: If178d72f283fc693697849c37d276b88331279d3
TN: T605-002
Wildcard imports are flagged as an error by our style checker, and
it turns out that it is actually not needed, so this commit removes it
entirely.
Change-Id: Ib74e2114c5692b237a94eb635c0d63a889e2d626
TN: T605-002
The exact text of the warning reads:
RST215 Inline interpreted text or phrase reference start-string
without end-string.
I think it's the backtick character that's causing problems, easily
avoided by using double-quotes to quote the program name.
Change-Id: I645cfdcdf481e576a9794795f2beb39aa0977623
TN: RST215
This warning actually detected a bug. It looks like this bug wasn't
having an actual impact, but this definitely should have had the 'r'
string qualifier.
Change-Id: Ia41923c005b2f563481b735ef98a613c21453eb6
TN: T605-002
The name is useful to give a clue what we are looping over, even if
the actual contents is not important. So, this patch avoids the
violation by starting the name of the variable with an underscore
(and also adds "unused" to make it even clearer).
Change-Id: I623f861e2e2669e45ddb8a2b09179044f88c0d88
TN: T605-002
These options allow repositories to override the defaults and force
the Ada files to be checked against Ada 2012 (gnat12), or Ada 2020
(gnat2020).
Change-Id: Iadaba488f69634f7a5a7db1444ebc7156045aebe
TN: T618-059
Change-Id: I6e2166274f43f8f5b429c2eff547b7d1009d5720
TN: T613-005 (ticket where decision and compiler changes were made)
TN: T615-042 (corresponding IT ticket to do the work)
On a suggestion from Thomas Quinot, this commit reorganizes a bit
how we handle the various scenarios to make it a little simpler to
follow the logic, particularly in the case of sources from the 'gnat'
repository.
Change-Id: I80dcc83963949b7b5abc6b818bdfede4bcf5b4b7
TN: T217-001