Commit Graph

112 Commits

Author SHA1 Message Date
Joel Brobecker
f3cb597262 .gitreview: Change defaultbranch to legacy-python2
Change-Id: If2e3466d52a1df41c1211c31b0d62200effe5c5e
TN: T605-002
2020-08-12 10:49:51 -07:00
Joel Brobecker
268ed9d3a2 java.py: Avoid use of os.write (Python 3.x compatibility)
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
2020-07-28 18:07:47 -07:00
Joel Brobecker
570cbd7049 invalid DOS EOL not detected by style_checker when using Python 3
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)
2020-07-28 11:41:56 -07:00
Joel Brobecker
b131e02344 asclib/ex.py: Fix Python3 str/byte incompatilibity
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
2020-07-17 18:38:12 -07:00
Joel Brobecker
a6173abd22 config.py: fix Python3 compability issue iterating over dict keys
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
2020-07-17 18:26:15 -07:00
Joel Brobecker
a9f2a7d728 fix python3 incompatibility in main.py
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
2020-07-08 17:10:38 -07:00
Joel Brobecker
5142153194 TestCase.run_style_checker: Enhance to allow calling via Python interpreter
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
2020-06-23 11:53:55 -07:00
Joel Brobecker
ba84e08166 TestCase.run_style_checker: be more specific about what **kwargs can be
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
2020-06-23 11:40:16 -07:00
Joel Brobecker
9362e77827 Replace call to Run by call to self.run_style_checker in one test
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
2020-06-23 11:40:04 -07:00
Joel Brobecker
ebb584a5dd testsuite/lib/support.py: Remove unnecessary wildcard import
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
2020-06-23 11:39:58 -07:00
Joel Brobecker
adbbfe339e ada.py: add comment about language version in runtime files
Change-Id: I2dd5e012815be02215dbd0914f8ccdd49cd1ff9a
TN: T618-047
2020-06-21 11:06:38 -07:00
Joel Brobecker
95ab8dc1f2 fix flake8 RST215 violations (Inline interpreted text...)
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
2020-06-19 16:44:06 -07:00
Joel Brobecker
5ec490e3ba fix flake8 E741 violation (ambiguous variable name 'l')
Change-Id: I1180c0a27a9e7097a8fc904703bf935e83a5d6d7
TN: T605-002
2020-06-19 16:41:11 -07:00
Joel Brobecker
d631a8fc2f Fix flake8 W605 violation (invalid escape sequence '\s')
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
2020-06-19 16:39:03 -07:00
Joel Brobecker
aa9cc529c3 fix flake8 B007 violations (Loop control variable 'xxx' not used)
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
2020-06-19 16:33:05 -07:00
Joel Brobecker
e582323a22 fix W504 flake8 violations (line break after binary operator)
Change-Id: Ia10502485299fb39eb0594f06cacdd4dd0f4c54a
TN: T605-002
2020-06-19 16:30:04 -07:00
Joel Brobecker
ffb635342c fix flake8 E123 violations (closing bracket does not match indentation...)
Change-Id: If58426b7f60d2dd5096b889c54c0963d504808d3
TN: T605-002
2020-06-19 16:24:45 -07:00
Joel Brobecker
1677c55f68 fix D200 flake8 violations (One-line docstring should fit on one line)
Change-Id: I24435882e363eba281076024a414511ed3b315ee
TN: T605-002
2020-06-19 16:18:36 -07:00
Joel Brobecker
8a80b49318 Fix all D401 flake8 violations (First line should be in imperative mood)
Change-Id: I24371cdfddcb380d7f81e53154b660ba829b78d7
TN: T605-002
2020-06-19 16:16:13 -07:00
Joel Brobecker
4c2f6287fc Fix all D204 flake8 violations (1 blank line required after class docstring)
Change-Id: I8b59dd6b1ae6920ac52a1dfa7403d26c04d2c380
TN: T605-002
2020-06-19 16:13:01 -07:00
Joel Brobecker
a4326c978b Fix all flake8 D400 violations (first line should end with a period)
Change-Id: Ia12ae12450ceb303f268217b6882829ce41d7124
TN: T605-002
2020-06-19 16:09:37 -07:00
Joel Brobecker
69077c1667 Anod test: replace gnatpython references by references to e3
Change-Id: I939c58ecbe7e1a1f8259fd7216018170a951e9fc
TN: T605-002
2020-06-19 15:55:06 -07:00
Joel Brobecker
bae4e421d2 Ada: Add support for gnat12 and gnat2020 options
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
2020-06-19 15:55:06 -07:00
Joel Brobecker
8db1779ea1 Ada: Allow Ada 2012 constructs in "gnat" compiler core units
Change-Id: I6e2166274f43f8f5b429c2eff547b7d1009d5720
TN: T613-005 (ticket where decision and compiler changes were made)
TN: T615-042 (corresponding IT ticket to do the work)
2020-06-15 09:35:32 -07:00
Joel Brobecker
e46f10b6d1 simplify the implementation of the the Ada file checker
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
2020-02-19 14:49:07 +04:00