Commit Graph

79 Commits

Author SHA1 Message Date
Alexander Cyon
4a2942bb4e Fix typos in: cmake, tools, utils, unittests, validation-test
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2024-07-12 02:34:00 +03:00
Dave Abrahams
8e2b48b6b3 [gyb] Support -o with relative path (#67995)
Fixes a surprising bug where a relative output file path would be interpreted relative to the directory of the `.gyb` file being processed rather than the current working directory upon invocation.
2023-09-11 11:12:23 -07:00
Daniel Duan
3dfc40898c [NFC] Remove Python 2 imports from __future__ (#42086)
The `__future__` we relied on is now,  where the 3 specific things are
all included [since Python 3.0](https://docs.python.org/3/library/__future__.html):

* absolute_import
* print_function
* unicode_literals
* division

These import statements are no-ops and are no longer necessary.
2022-04-13 14:01:30 -07:00
Daniel Duan
fdae97aaad [gyb] Remove Python 2 (#42046) 2022-03-28 12:29:39 -07:00
Saleem Abdulrasool
7779fb3450 test: normalize the path before opening
The tests mix path separators when passing paths to `gyb`.  Ensure that
we normalize the path string to allow the use of mixed path separators.
2020-07-29 10:58:43 -07:00
Saleem Abdulrasool
bfd5207071 gyb: special case list for conversion
In order to deal with encoding conversions for Python 2 and Python 3,
the string had to be passed through CStringIO for Python 2.  On Python
3, the strings are unicode.
2020-07-21 18:13:53 -07:00
Saleem Abdulrasool
c6a5e01c20 gyb: force I/O in UTF-8
We would rely on the system encoding, which if unspecified would fall
back to `C` treating the encoding as ASCII.  This fails with unicode
data in Python3.  Thanks to @tbkka for the brilliant idea of forcing the
encoding when reading the file.  This improves the test pass rate on
Linux with Python 3.
2020-07-20 22:23:38 -07:00
tbkka
a6aa7a5f3f Minor python3 lint fixes (#33009) 2020-07-20 17:09:42 -07:00
Saleem Abdulrasool
fedf81f544 validation: fix nosetest in gyb for Python 3
The file-like object's `write` method in Python 3 returns the number of
bytes that are written.  This was not previously checked and is not
particularly interesting.  Simply blackhole the bytes written, repairing
the test on Python 3.
2020-07-13 20:43:23 +00:00
Brent Royal-Gordon
dab60f04ca Partially revert "Keep gyb from messing up line endings on Windows"
This reverts most of commit 85599f7582b8809be889f589fe4d1d95e09ec945; it turns out the ‘b’ flag changes behavior more drastically in Python 3.

Fixes SR-12328, rdar://problem/60230415.
2020-03-11 10:47:22 -07:00
Brent Royal-Gordon
85599f7582 Keep gyb from messing up line endings on Windows
GYB opens its inputs and outputs in text mode. This is a problem because the recommendation in Windows is to check everything out in LF mode to avoid breaking tests, so gybbing a file ends up converting LFs to CRLFs. That broke test/SILGen/magic_identifier_file_conflicting.swift.gyb.

Modify GYB to open its files in binary mode instead of text mode. This is a no-op everywhere but Windows.

Note that this change is incomplete: it’s somewhat difficult to switch stdin and stdout to binary mode in Python 2. I’ve added FIXME comments about this.
2020-03-05 23:30:37 -08:00
Ross Bayer
c096e29967 [Python: flake8] Update the utils/python_lint.py script to fail with a non-zero exit code if flake8 and flake8-import-order are not installed. 2020-02-03 13:10:15 -08:00
Ross Bayer
bb4e5fe86b [Python: flake8] Appease the utils/python_lint.py script. 2020-01-17 01:03:20 -08:00
Gwynne Raskind
02603ca57a Fix typo in comment 2019-01-13 21:15:56 -06:00
Lynn Kirby
43f188a061 [gyb] Fix Windows path normalization
A number of gyb tests (gyb --test) were failing on Windows. It appears it was
introduced by commit d57b41e which altered the behaviour of line
directives to print paths with forward-slashes even on Windows.

This commit changes two areas of gyb.py:

1. Doctests use normalized paths where applicable.

2. Path normalization is done early in ParseContext initialization
instead of when formatting line directives in ExecutionContext.append_text.

Fixes: SR-9644
2019-01-11 21:16:39 -05:00
Dave Abrahams
a6ffb59bd1 Fix python linter issues 2019-01-07 15:21:36 -08:00
Dave Abrahams
d3aa33ae52 Tweak help for the --line-directive option
Most people don't know what this is for and set it to "", robbing themselves of usability benefits.  I'm going to add more help text to line-directive to explain that.
2019-01-04 17:38:45 -08:00
Graydon Hoare
71da5ec519 Fix flake8 warning W605 invalid escape sequence. 2018-11-06 11:38:39 -08:00
Saleem Abdulrasool
d57b41e717 gyb: alter windows path for filename substitutions
When building on Windows, the filepath contains `\` as the path
separator.  Substitute `/` for the path separator prior to replacement.
This allows clang to properly compile the source file.  Windows supports
both as a path separator and this matches what clang does by default for
the filepaths when preprocessing.  This allows gyb generated files to
build on Windows.
2018-03-01 12:22:07 -08:00
Harlan
aed3c47571 [gyb] Rework line directives to allow for C++-style directives (#13965)
This patch reworks the line-directive command line argument for gyb to
take in a python-style format string with `line` and `file` variables
to be substituted.
2018-01-16 14:42:48 -05:00
Hugh Bellamy
9c953ab8cb Merge pull request #8384 from hughbe/gyb-pyc-fixes
Make sure to lint the interpreted, not compiled python file
2017-03-28 10:08:53 +07:00
Hugh Bellamy
c4d2ff24df Make sure to lint the interpreted, not compiled python file 2017-03-28 09:14:07 +07:00
Hugh Bellamy
0b2e5bf468 Fix GYB tests on Windows
SR-4371
2017-03-27 14:20:21 +07:00
Dave Abrahams
b52cf92609 Merge pull request #8292 from hughbe/gyb-line-direcrtive-cleanup
Cleanup recent line-directive and gyb test fixes
2017-03-26 23:54:40 -07:00
Dave Abrahams
5109788c95 Merge pull request #8360 from hughbe/python-more-fixes
Couple of fixes to python-linting
2017-03-26 23:03:56 -07:00
Hugh Bellamy
abfca72357 Run python linting on the file if running doctests 2017-03-27 12:31:56 +07:00
Dave Abrahams
895f90f997 Delete trailing whitespace
pyhon-lint is complaining and we need to fix that but I want to get this in first.
2017-03-26 12:35:51 -07:00
Dave Abrahams
bc287359f4 [gyb] Fix line-directive mapping of multiline substitutions
fixes https://bugs.swift.org/browse/SR-4362
2017-03-25 14:49:20 -07:00
Dave Abrahams
7019b84676 [gyb] expand files found relative to template 2017-03-25 14:48:16 -07:00
Hugh Bellamy
da9035cbb4 Cleanup recent line-directive and gyb test fixes 2017-03-25 15:45:27 +07:00
Hugh Bellamy
8671854674 Properly python lint remaining files 2017-03-23 14:06:46 +07:00
Dave Abrahams
a174c634c6 [gyb] Add, effectively, an #include directive 2017-03-22 07:47:56 -07:00
Dave Abrahams
621293fbbe [gyb] use line directives absent explicit request
The few places that are explicitly using execute_template could benefit
2017-03-22 00:47:10 -07:00
Hugh Bellamy
54e2c6893a Fix GYB doctests on Windows 2017-03-20 15:48:37 +07:00
Hugh Bellamy
fa3543d3c5 Fix some pylint errors for double whitespace after class/function 2017-02-17 15:37:19 +07:00
Jason Toffaletti
b9118b02f8 [gyb] check isinstance(result, basestring) before string comparison
Guard against types that override __eq__ and do things like
raise TypeError when the types being compared don't match.
2017-02-09 23:41:06 -08:00
practicalswift
ee871c7938 [python] Bring code base in line with PEP-8 again 2016-09-16 19:33:04 +02:00
Michael Gottesman
751e8c51ac [python] Make python lint pass (#4296) 2016-08-14 22:49:14 -04:00
Chris Williams
8edc5cb86d Avoid truncating floats in gyb 2016-08-01 14:27:51 -07:00
rintaro ishizaki
9e10ce049f [gyb] Add __file__ binding 2016-06-15 11:49:43 +09:00
Rintaro Ishizaki
4bae3d4068 [gyb] Make utils/gyb --test to really perform doctest
Because utils/gyb is just a launcher, `doctest.testmod()` without
explicit module doesn't perform doctest of `gyb` module.
It used to perform doctest of `util/gyb`, the `__main__` module.
2016-06-10 18:04:57 +09:00
Rintaro Ishizaki
0006a54c34 [gyb] Get doctest to pass
Mainly, because of `from __future__ import print_function`, doctest was
broken.
2016-06-10 17:22:35 +09:00
practicalswift
c760f6dfbf [gardening] Add whitespace: "foo,bar" → "foo, bar" 2016-04-12 22:31:46 +02:00
practicalswift
1edb62dc38 [Python] Make flake8 linting pass without errors/warning (w/ default rules) 2016-03-13 20:19:51 +01:00
Chris Lattner
4992474168 Add support for #sourceLocation in its ratified forms. Switch gyb to produce
the new form.  This keeps accepting #setline for now, but we should rip it out
at some point.
2016-03-11 22:21:42 -08:00
practicalswift
0796eaad1f [Python] Fix 80-column violations 2016-03-09 23:52:11 +01:00
practicalswift
c69ffe4eb6 [Python] Use new style class definitions: "class A" → "class A(object)" 2016-03-09 09:42:42 +01:00
Brian Gesiak
c9000af795 Merge pull request #1526 from practicalswift/fix-pep8-violations-ii
[Python] Fix five classes of PEP-8 violations (E101/E111/E128/E302/W191)
2016-03-08 23:55:46 -05:00
practicalswift
e8c0600727 [Python] NotImplemented → NotImplementedError
From the Python documentation:
* NotImplemented: "Special value which can be returned by the 'rich comparison'
  special methods (__eq__(), __lt__(), and friends), to indicate that the
  comparison is not implemented with respect to the other type."
* NotImplementedError: "This exception is derived from RuntimeError. In user
  defined base classes, abstract methods should raise this exception when they
  require derived classes to override the method."
2016-03-08 13:56:01 +01:00
practicalswift
265835fdfc [Python] Use consistent import ordering for Python code
Ordering used:
1.) standard library imports
2.) third party imports
3.) local package imports

Each group is individually alphabetized.
2016-03-07 23:25:16 +01:00