Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare Release 31b4 #2947

Merged
merged 217 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
ae729da
Move JVM languages to their own module.
birkenfeld Feb 5, 2012
277c414
Copyright update.
birkenfeld Feb 5, 2012
6ccc97d
Style fixes.
birkenfeld Feb 5, 2012
346ad03
Improved Clojure highlighting.
Raynes Feb 11, 2012
c798716
Added support for Tea. http://teatrove.org
jaxzin Feb 25, 2012
96df745
Simplify character classes, ordering fixes
thatch Mar 9, 2012
58702ff
Merged in jaxzin/pygments-main (pull request #56)
birkenfeld Mar 10, 2012
c7d23e9
Style fixes, remove unneeded import.
birkenfeld Mar 10, 2012
ac8e90d
Move Kotlin to JVM lexers, add changelog and authors entry.
birkenfeld Mar 10, 2012
df14e6f
Added lexer for Xtend http://xtend-lang.org
svenefftinge Apr 7, 2012
f4ecd2b
Added lexer for Xtend http://xtend-lang.org
svenefftinge Apr 7, 2012
5a3992e
add support for clojure namespaced keywords
mpenet May 16, 2012
655c4c1
initial Lasso lexer commit.
EricFromCanada Jun 1, 2012
2b71eed
Add lexer for Ceylon
chochos Jul 4, 2012
2cdce1d
Added lexers for BUGS, JAGS, and STAN
jrnold Aug 1, 2012
ba676fb
Add AspectJLexer as subclass of JavaLexer
kriegaex Aug 9, 2012
c5e98f1
merge with upstream
jrnold Aug 14, 2012
c27177f
merging latest from trunk
EricFromCanada Aug 17, 2012
01831b0
Merged in jrnold/pygments-main (pull request #89)
birkenfeld Aug 19, 2012
76e1a94
Merged in Oldes/pygments-main (pull request #62)
birkenfeld Aug 19, 2012
24bb5c9
Close fix-r branch.
birkenfeld Aug 19, 2012
72460fa
merge with branch-close commit
birkenfeld Aug 19, 2012
ec982a4
Merged in svenefftinge/pygments-main-xtend-support (pull request #68)
birkenfeld Aug 19, 2012
38756b8
Xtend: add attribution/changelog entry, remove a bunch of unnecessary…
birkenfeld Aug 19, 2012
c7d492c
Merge with kriegaex/pygments-main (pull request #90)
birkenfeld Aug 19, 2012
b6a217b
Closes #771: Java: allow generics <> characters in return argument type
birkenfeld Aug 19, 2012
be9849c
Merged in greghendershott/pygments-main (pull request #94)
birkenfeld Aug 23, 2012
d489b24
Centralize regex metachar escaping, since the surrogate support breaks
thatch Aug 27, 2012
c5cd3ad
fix triple-quote coloring in Scala
Sep 5, 2012
08ab35e
add CeylonLexer to __all__; move suffixes to MGTP instead of MGPT.
chochos Sep 26, 2012
9272682
avoid conflict
chochos Sep 26, 2012
dc8ecf1
add CeylonLexer to __all__
chochos Sep 26, 2012
822b52a
merge from birkenfeld/pygments-main
chochos Sep 26, 2012
7e091f3
Add Ceylon lexer properly.
thatch Oct 7, 2012
35015fd
Introduce a very simple vim modeline parser.
mgorny Oct 19, 2012
6c7e30d
Allow case-insensitive hex literals in all jvm languages
thatch Oct 30, 2012
ad3fa24
Closes #824: add clojure "deref" operator, a single @.
birkenfeld Dec 25, 2012
b71526f
Happy new year 2013.
birkenfeld Jan 9, 2013
b825bce
Fix a couple "make check" issues, mostly long lines.
birkenfeld Jan 9, 2013
9f6cd12
Fix stuff in new lexers found by regexlint.
birkenfeld Jan 12, 2013
b65179c
Update Ceylon syntax
chochos Mar 19, 2013
58f3ed4
Fix some problems pointed out by @birkenfeld
chochos Mar 20, 2013
12e4ae3
fix class names
chochos Mar 20, 2013
cb1d132
Add basic ClojureScript lexer
aiiie Apr 23, 2013
737a3b8
merge with mgorny/pygments-vim-modelines-r1 (pull request #118)
birkenfeld May 19, 2013
d8cc563
java: Decrease priority of method regex to avoid parsing 'else if ('…
Oct 3, 2013
a9aaf93
Simplify KotlinLexer
udalov Jan 8, 2014
8749e6b
Update Kotlin URL with the newer one
udalov Jan 8, 2014
a8ee23d
Update KotlinLexer
udalov Jan 8, 2014
57138a6
Merged in udalov/pygments-main/kotlin (pull request #271)
birkenfeld Jan 9, 2014
688c882
Closes #915: fix parsing of nested multiline comments.
birkenfeld Jan 9, 2014
82fd52b
new year in copyright notice
birkenfeld Jan 10, 2014
1b68ab3
Finalize single-source port for Py2.[67] and Py3.3+.
birkenfeld Jan 18, 2014
13bf671
use versionadded directives
birkenfeld Jan 19, 2014
ea5fa93
Adding support for underscores in Java integers.
Mar 13, 2014
959e697
Create PigLexer.
Mar 20, 2014
50c28f8
jvm.py edited online with Bitbucket
Mar 23, 2014
f352424
Merged in redcat9/pygments-main (pull request #304)
thatch Apr 14, 2014
5e29c83
Improve Pig lexer formatting and completness
thatch Apr 14, 2014
8f31684
Merged in brodie/pygments (pull request #191)
thatch Apr 14, 2014
c69b854
Include examplefile for ClojureScript
thatch Apr 14, 2014
2a06a94
Move GoloLexer to jvm.py; add hello world example
thatch Apr 14, 2014
55cdd3e
Merged in kwadrat/pygments-main2 (pull request #316)
thatch Apr 14, 2014
d8dfd95
Tweaking clojure keyword lexing
timgilbert Apr 16, 2014
b32dbdc
Add copy, atomic, release & class Objective-C keywords
jaingaurav Apr 22, 2014
3919cac
Merged birkenfeld/pygments-main into default
jaingaurav Apr 24, 2014
b88199a
Add a lexer for Jasmin
dscorbett May 5, 2014
6926729
Make requested changes to JasminLexer
dscorbett May 6, 2014
dd13afe
Add JasminLexer.analyse_text
dscorbett May 10, 2014
af0c769
Distinguish between Jasmin and Smali
dscorbett May 11, 2014
bcc91af
Fix some lines to be within 90 characters
jaingaurav May 12, 2014
f5bd7f5
Add support for unicode letters in Java identifiers
jaingaurav May 13, 2014
6dc9fd2
Match Java function name tokens even without leading whitespace
jaingaurav May 13, 2014
316619a
Improve support $ symbol in Java identifiers
jaingaurav May 13, 2014
4749631
Fix Jasmin and Smali code snippet detection
dscorbett May 14, 2014
78808d7
Replace all occurences of [a-zA-Z0-9_] with \w
jaingaurav May 15, 2014
24855d7
Replace all occurences of a-zA-Z0-9_ with \w
jaingaurav May 15, 2014
b926963
Replace a-z0-9_ with \w when IGNORECASE is set
jaingaurav May 16, 2014
b172c9c
Merged in dscorbett/pygments-jasmin (pull request #349)
thatch May 16, 2014
4acb0d0
Merged in jaingaurav2/pygments-main (pull request #357)
thatch May 16, 2014
dc9308f
Merged birkenfeld/pygments-main into default
jaingaurav May 16, 2014
57626e2
Add shebang support to Groovy lexer
jaingaurav May 17, 2014
91ebd7c
Only allow one shebang in Groovy files
jaingaurav May 17, 2014
855e7d3
Merged in timgilbert/pygments-main/clj-keyword-fix (pull request #326)
thatch May 17, 2014
20cc388
Apply default state transition in various lexers to avoid extra token…
jaingaurav May 18, 2014
e68b10a
Add token type Number.Bin
dscorbett May 19, 2014
6fa366d
Update ElixirLexer and example_elixir.ex
alco Jun 5, 2014
ffd8a0e
Merged in megajoule/pygments-main (pull request #372)
thatch Jun 8, 2014
95c662b
Fix regular expressions for identifiers in ElixirLexer
alco Jun 26, 2014
4b62520
add the new upcomming decorator syntax for Golo
yloiseau Aug 26, 2014
8869076
merge with megajoule/pygments-main.
birkenfeld Sep 16, 2014
ca6b423
Merged in yloiseau/pygments-main (pull request #396)
birkenfeld Sep 16, 2014
9d2b91c
fix global instantiation of GosuLexer.
birkenfeld Sep 16, 2014
74627fa
misc fixups in math.py and jvm.py
birkenfeld Sep 19, 2014
913fc01
Closes #1010: recognize string interpolation in Scala lexer.
birkenfeld Oct 7, 2014
fbfd247
Scala: add $$ escape for interpolated strings. (#1010)
birkenfeld Oct 7, 2014
d219476
ScalaLexer: Improve interpolated strings, adding triplequoted strings…
thatch Oct 7, 2014
4cd6362
Fix highlighting of Java enhanced for loops.
thatch Oct 7, 2014
25c29de
Use unistring.combine for slight speedup.
thatch Oct 15, 2014
f09bce4
all lexers: fix unescaped { and } so that the "regex" module can comp…
birkenfeld Oct 15, 2014
4d68730
Merge with -main
thatch Oct 15, 2014
4d7dfea
Fix "matches empty string" complaints from regexlint.
birkenfeld Oct 16, 2014
6f8eb89
More fixes thanks to regexlint.
birkenfeld Oct 16, 2014
7c1dbb7
Closes #1051: fix misrecognition of throw and return statements as me…
birkenfeld Nov 4, 2014
3c1725b
Closes #1050: highlight Java package names after "package" like after…
birkenfeld Nov 4, 2014
60f5453
Scala: fix recognition of Unicode => operator
birkenfeld Nov 6, 2014
b2efac3
Groovy: recognize triple quoted strings
birkenfeld Nov 6, 2014
a7eb1ba
JVM lexers: simplify charclasses
birkenfeld Nov 6, 2014
b1176cd
Add a lexer for crmsh
dmuhamedagic Nov 17, 2014
c41b6f3
Copyright year update.
birkenfeld Jan 21, 2015
4e1448c
Updated keywords for Ceylon language
quintesse Feb 17, 2015
4570dee
Close branch tako/updated-keywords-for-ceylon-language-1424201773270
quintesse Feb 17, 2015
07adc5a
Merged in tako/updated-keywords-for-ceylon-language-1424201773270 (pu…
quintesse Feb 17, 2015
b03ebc3
Minor fix for the Ceylon Lexer
quintesse Feb 18, 2015
23e03d5
Syntax highlight Gradle files with Groovy
selesse May 6, 2015
730291f
Merged birkenfeld/pygments-main into default
dmuhamedagic May 8, 2015
aa96c23
Merge with dejanm/pygments-main (pull request #440)
thatch Oct 15, 2015
48eb7cb
Fixes #1139: Correctly order symbol and char literals in ScalaLexer
thatch Oct 17, 2015
52d25e1
update list of Kotlin keywords according to language changes up to 1.…
Oct 20, 2015
eeb56dc
Merged in yole/pygments-main/kotlin-lexer (pull request #505)
birkenfeld Oct 20, 2015
ac857a5
Merge changes
nwhetsell Oct 24, 2015
b69910b
Improve numeric literal support in Java lexer
aldenrogers Jan 10, 2016
72faacb
merge default into stable
birkenfeld Jan 17, 2016
97d70d6
Merge with stable.
birkenfeld Feb 2, 2016
b02de48
Fix most complaints from regexlint.
birkenfeld Feb 14, 2016
aeb3c90
Java lexer: add "import static" (fixes #1228)
birkenfeld Apr 14, 2016
3278eeb
Speed up regex for searching numbers in jvm languages
spitty Apr 19, 2016
136b5fe
Add support for partials and path segments for Handlebars.
chipx86 Nov 4, 2016
f4c66a5
Copyright update.
birkenfeld Jan 22, 2017
7fda129
Merged in rrt/pygments-main (pull request #608)
birkenfeld Jan 22, 2017
5331b59
after release 2.2: merge default *into* stable
birkenfeld Jan 25, 2017
b61e144
Clojure: extend valid_name to contain "|".
birkenfeld Jan 29, 2017
0820438
Add the lexer for the SARL language.
gallandarakhneorg Apr 4, 2017
a7f87ff
Fix remaining 'DeprecationWarning: invalid escape sequence' occurrenc…
inducer Jun 19, 2018
c826200
Merge heads.
birkenfeld Nov 28, 2018
3495104
Merged in sgalland/pygments-main (pull request #717)
Dec 16, 2018
a9c570e
Update SARL added date, regenerate mapping.
Anteru Dec 16, 2018
edfd54c
Add lexers for DASM16, Augeas, TOML, and Slash
Freso Mar 31, 2019
91b8ba1
some fixes to the kotlin lexer to work with the corda kolin codebase
Apr 1, 2019
b573af4
Merged in nimmajbb/pygments-main/update-kotlin-lexer (pull request #808)
Apr 2, 2019
f0508a0
Merge ssh://hg@bitbucket.org/Freso/pygments-main manually.
Anteru Apr 30, 2019
aa42ab0
Fixup all headers and some more minor problems.
birkenfeld May 28, 2019
faa917d
Added tag 2.4.2 for changeset 800a6961ec37
birkenfeld May 28, 2019
f87b280
Java: support "var" contextual keyword (bitbucket PR #742)
birkenfeld Nov 24, 2019
a52c238
Java: update URL
birkenfeld Nov 24, 2019
4afe089
Java: make it less operator-heavy
birkenfeld Nov 24, 2019
13969ad
Update project to use modern Python features and idioms
jdufresne Nov 24, 2019
0c372c1
Fix #972: Resurrect patch from bug tracker
Blaisorblade Nov 28, 2019
e621a45
Only highlight `type` as a whole word
Blaisorblade Nov 28, 2019
68022aa
Same treatment for `forSome`
Blaisorblade Nov 28, 2019
055897b
Update copyright year (fixes #1514.)
Anteru Aug 22, 2020
d2dc9b0
all: fixup remaining regexlint warnings
birkenfeld Sep 6, 2020
2fe28ff
all: use yield from (#1537)
birkenfeld Sep 6, 2020
9468942
all: remove "u" string prefix (#1536)
birkenfeld Sep 8, 2020
38d7ba2
Fix a catastrophic backtracking bug in JavaLexer (#1594)
kurtmckee Nov 9, 2020
d66cabd
Update jvm.py (#1587)
bk322 Dec 5, 2020
2763646
sarl: fix indentation
birkenfeld Dec 25, 2020
a25811a
fix a lot more backtracking string regexes
birkenfeld Dec 25, 2020
7ebdf8a
all: weed out more backtracking string regexes
birkenfeld Dec 25, 2020
f0e6ec1
Bump copyright year.
Anteru Jan 3, 2021
79559cd
Fix several exponential/cubic complexity regexes found by Ben Caller/…
birkenfeld Jan 11, 2021
c1367a9
Run pyupgrade across codebase to modernize syntax and patterns (#1622)
jdufresne Jan 17, 2021
79a2512
Improve Kotlin lexer (#1699)
geralt-encore Feb 6, 2021
71bc9f6
Rewrite Scala lexer for Scala 3 (#1694)
MaximeKjaer Mar 1, 2021
2eb190f
groovy lexer: detect quoted function names (#1765)
alisonatwork May 2, 2021
b74d9e0
Scala lexer: Add support for the '\' operator (#1857)
lukapeschke Jul 9, 2021
5f7ab20
add min to analyse text for jasmin (#1619)
gandarez Jul 24, 2021
fc159c4
Java: do not lex whitespace as Label, do not lex "default" as Label
birkenfeld Jul 31, 2021
bb17262
Add new Java syntax: sealed classes and record types. (#1902)
benjaminp Sep 29, 2021
4813a88
yield keyword in Java (#1941)
xtay2 Nov 3, 2021
1c0cf01
Java: fix lexing of 'record' soft keyword (#2018)
amitkummer Jan 3, 2022
df2bf9f
Fix typos (#2030)
kianmeng Jan 18, 2022
9f8b43d
Happy new year.
birkenfeld Jan 25, 2022
e8a6ec0
Add support for .cljc clojure file extension (#2043)
dannyfreeman Jan 25, 2022
15a9ee4
Highlight Clojure ratios as Numbers (#2042)
TomFryers Jan 31, 2022
5e75009
Remove now redundant re.UNICODE and (?u) (#2058)
jeanas Jan 31, 2022
0384d38
Bump dependencies
pombredanne May 4, 2022
ee47813
Ensure configure runs quiet
pombredanne May 4, 2022
3955a7a
Bump
pombredanne May 4, 2022
12b769d
Bump commoncode
pombredanne May 4, 2022
684d687
Bump parameter-expansion
pombredanne May 4, 2022
aac7c52
Improve thirdparty scripts
pombredanne May 5, 2022
a2bbb24
Remove old and unused test configs
pombredanne May 6, 2022
7b21fca
Remove unused requirements
pombredanne May 6, 2022
7f5c090
Improve third-party processing
pombredanne May 6, 2022
8e39111
Use correct versions
pombredanne May 6, 2022
a22add7
Bump requirements
pombredanne May 6, 2022
af85a29
Revert Click to an earlier version
pombredanne May 6, 2022
20c819f
Adjust requirements for Python 3.6 support
pombredanne May 7, 2022
8d206ae
Merge remote-tracking branch 'upstream/develop' into prepare-31b4
pombredanne May 7, 2022
784e4d7
Do not use deprecated function
pombredanne May 7, 2022
8c706be
Remove unused variable
pombredanne May 7, 2022
dd2e22e
Improve error checking
pombredanne May 7, 2022
01d3bf3
Skip bz2 sdist
pombredanne May 7, 2022
c2d695a
Remove unused attribute
pombredanne May 7, 2022
d4a0d92
Rename file to target location
pombredanne May 9, 2022
ed7c7ba
Add ABOUT file to document origin
pombredanne May 9, 2022
c82a9f1
Add license header
pombredanne May 9, 2022
5bb8a20
Remove unused lexers, keep only Groovy
pombredanne May 9, 2022
7fb9401
Add new gradle tests
pombredanne May 9, 2022
b08d342
Include full trace in package scan error
pombredanne May 9, 2022
35c327b
Do not fail if package_data missing
pombredanne May 9, 2022
1cf3cc6
Bump dependencies
pombredanne May 9, 2022
1d6cd48
Bump dependencies
pombredanne May 9, 2022
025573d
Use correct syntax for ConfigParser
pombredanne May 9, 2022
ee30762
Update help test
pombredanne May 9, 2022
e15e32b
Remove headers from scans results
pombredanne May 9, 2022
7580697
Merge remote-tracking branch 'pygments/beforews' into prepare-31b4
pombredanne May 9, 2022
05b3319
Use new vendored GroovyLexer from pygments
pombredanne May 9, 2022
bbf5415
Do not use scan headers in tests files
pombredanne May 9, 2022
f463dc2
Mark Gradle test as failing for now
pombredanne May 9, 2022
be243d0
Mark edged pdf test case as failing for now
pombredanne May 9, 2022
50c22fa
Use only PyPI for downloads
pombredanne May 10, 2022
d1616b8
Use correct extractcode version
pombredanne May 10, 2022
f91c7f7
Include source for native builds
pombredanne May 10, 2022
501789a
Bump dependency versions
pombredanne May 10, 2022
e8f6465
Fix typo in comment
pombredanne May 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/scancode-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ jobs:
--python-version=$python_version \
--operating-system=$operating_system \
--wheels
venv/bin/python etc/scripts/fetch_thirdparty.py \
--requirements=requirements-native.txt \
--dest=thirdparty \
--sdists
venv/bin/python setup.py --quiet sdist --formats=$formats
venv/bin/python etc/release/scancode_rename_archives.py dist/ _py$python_version-$operating_system

Expand Down Expand Up @@ -210,6 +214,10 @@ jobs:
--python-version=$python_version \
--operating-system=$operating_system \
--wheels
venv/bin/python etc/scripts/fetch_thirdparty.py \
--requirements=requirements-native.txt \
--dest=thirdparty \
--sdists
venv/bin/python setup.py --quiet sdist --formats=$formats
venv/bin/python etc/release/scancode_rename_archives.py dist/ _py$python_version-$operating_system

Expand Down Expand Up @@ -260,6 +268,10 @@ jobs:
--python-version=$python_version \
--operating-system=$operating_system \
--wheels
venv/bin/python etc/scripts/fetch_thirdparty.py \
--requirements=requirements-native.txt \
--dest=thirdparty \
--sdists
venv/bin/python setup.py --quiet sdist --formats=$formats
venv/bin/python etc/release/scancode_rename_archives.py dist/ _py$python_version-$operating_system

Expand Down
6 changes: 2 additions & 4 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CLI_ARGS=$1
################################

# Requirement arguments passed to pip and used by default or with --dev.
REQUIREMENTS="--editable . --constraint requirements.txt"
REQUIREMENTS="--editable .[packages] --constraint requirements.txt"
DEV_REQUIREMENTS="--editable .[testing,packages] --constraint requirements.txt --constraint requirements-dev.txt"
DOCS_REQUIREMENTS="--editable .[docs] --constraint requirements.txt"

Expand Down Expand Up @@ -56,10 +56,8 @@ CFG_BIN_DIR=$CFG_ROOT_DIR/$VIRTUALENV_DIR/bin
# Thirdparty package locations and index handling
# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
# offline mode for scancode installation with no index at all
if [ -f "$CFG_ROOT_DIR/thirdparty" ]; then
if [ -d "$CFG_ROOT_DIR/thirdparty" ]; then
PIP_EXTRA_ARGS="--no-index --find-links $CFG_ROOT_DIR/thirdparty"
else
PIP_EXTRA_ARGS="--find-links https://thirdparty.aboutcode.org/pypi/simple/links.html"
fi

################################
Expand Down
2 changes: 0 additions & 2 deletions configure.bat
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ set "CFG_BIN_DIR=%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\Scripts"
if exist "%CFG_ROOT_DIR%\thirdparty" (
set PIP_EXTRA_ARGS=--no-index --find-links "%CFG_ROOT_DIR%\thirdparty"
)
set "PIP_EXTRA_ARGS=%PIP_EXTRA_ARGS% --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html"


@rem ################################
Expand All @@ -70,7 +69,6 @@ if not defined CFG_QUIET (
@rem ################################
@rem # Main command line entry point
set "CFG_REQUIREMENTS=%REQUIREMENTS%"
set "NO_INDEX=--no-index"

:again
if not "%1" == "" (
Expand Down
214 changes: 13 additions & 201 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import pytest


TRACE = True

"""
Expand All @@ -34,8 +33,6 @@
branches all the tests run: none are skipped.
"""



################################################################################
# pytest custom markers and CLI options
################################################################################
Expand All @@ -44,8 +41,17 @@


def pytest_configure(config):
config.addinivalue_line('markers', SLOW_TEST + ': Mark a ScanCode test as a slow, long running test.')
config.addinivalue_line('markers', VALIDATION_TEST + ': Mark a ScanCode test as a validation test, super slow, long running test.')
config.addinivalue_line(
'markers',
SLOW_TEST +
': Mark a ScanCode test as a slow, long running test.',
)

config.addinivalue_line(
'markers',
VALIDATION_TEST +
': Mark a ScanCode test as a validation test, super slow, long running test.',
)


TEST_SUITES = 'standard', 'all', 'validate'
Expand All @@ -71,62 +77,20 @@ def pytest_addoption(parser):
'Use the @pytest.mark.scanvalidate marker to mark a test as a "validate" test.'
)

group.addoption(
'--changed-only',
dest='changed_only',
action='store_true',
default=False,
help='Run only the subset of tests impacted by your changes.'
'If selected, you can provide an optional --base-branch and the '
'changes are checked against that branch. '
'Otherwise, a git diff is made against the current branch.',
)

group.addoption(
'--base-branch',
dest='base_branch',
action='store',
default=None,
help='Optional name branch of the branch diff against to find what has '
'changed if --changed-only is selected.',
)

group.addoption(
'--dry-run',
dest='dry_run',
action='store_true',
default=False,
help='Only print selected and deselected tests. Do not run anything.',
)

################################################################################
# Filter whcih tests to collect based on our CLI options and our custom markers
# Filter which tests to collect based on our CLI options and our custom markers
################################################################################


@pytest.mark.trylast
def pytest_collection_modifyitems(config, items):
test_suite = config.getvalue('test_suite')
changed_only = config.getoption('changed_only')
base_branch = config.getoption('base_branch')
dry_run = config.getoption('dry_run')

run_everything = test_suite == 'validate'
run_slow_test = test_suite in ('all', 'validate')

tests_to_run = []
tests_to_skip = []

if changed_only:
base_branch = base_branch or get_git_branch()
impacted_modules = get_impacted_modules(base_branch) or set()
all_is_changed = not(impacted_modules)
impacted_modules_paths = ['/{}/'.format(m) for m in impacted_modules]
print()
if not impacted_modules:
print('All modules impacted')
else:
print('Run tests only in these changed modules:', ', '.join(sorted(impacted_modules)))

for item in items:
is_validate = bool(item.get_closest_marker(VALIDATION_TEST))
is_slow = bool(item.get_closest_marker(SLOW_TEST))
Expand All @@ -139,162 +103,10 @@ def pytest_collection_modifyitems(config, items):
tests_to_skip.append(item)
continue

if changed_only and not all_is_changed:
if not is_changed(item.fspath, impacted_modules_paths):
tests_to_skip.append(item)
continue

tests_to_run.append(item)

print()
print('{} tests selected, {} tests skipped.'.format(len(tests_to_run), len(tests_to_skip)))

if dry_run:
if config.getvalue('verbose'):
print()
print('The following tests will run: ')
for test in tests_to_run:
print(test.nodeid)

print('The following tests are skipped: ')
for test in tests_to_skip:
print(test.nodeid)

tests = items[:]
items[:] = []
config.hook.pytest_deselected(items=tests)
return


items[:] = tests_to_run
config.hook.pytest_deselected(items=tests_to_skip)


################################################################################
# Retest only tests for changed modules
################################################################################


def is_changed(path_string, impacted_module_paths, _cache={}):
"""
Return True if a `path_string` is for a path that has changed.
"""
path_string = str(path_string).replace('\\', '/')
cached = _cache.get(path_string)
if cached is not None:
return cached

if path_string.endswith(('setup.py', 'conftest.py')):
return False
changed = any(p in path_string for p in impacted_module_paths)
if TRACE and changed:
print('is_changed:', path_string, changed)
_cache[path_string] = changed
return changed


def get_all_modules():
"""
Return a set of top level modules.
"""
all_modules = set([p for p in os.listdir('src') if p.endswith('code')])
if TRACE:
print()
print('get_all_modules:', all_modules)
return all_modules


def get_impacted_modules(base_branch=None):
"""
Return a set of impacted top level modules under tests or src.
Return None if all modules are impacted and should be re-tested.
"""
try:
base_branch = base_branch or get_git_branch()
changed_files = get_changed_files(base_branch)
locally_changed_files = get_changed_files(None)
changed_files.extend(locally_changed_files)
except Exception as e:
# we test it all if we cannot get proper git information
print(e)
return

changed_modules = set()
for changed_file in changed_files:
segments = [s for s in changed_file.split('/') if s]

if segments[0] == 'thirdparty':
# test it all when changing thirdparty deps
return

if segments[0] not in ('src', 'tests'):
# test none on changes to other files
continue

module = segments[1]
changed_modules.add(module)

force_full_test = [
'scancode',
'commoncode',
'typecode',
'textcode',
'plugincode',
]

if any(m in changed_modules for m in force_full_test):
# test it all when certain widely dependended modules
return

# add dependencies
if 'licensedcode' in changed_modules:
changed_modules.add('packagedcode')
changed_modules.add('summarycode')
changed_modules.add('formattedcode')
changed_modules.add('scancode')

if 'cluecode' in changed_modules:
changed_modules.add('summarycode')
changed_modules.add('formattedcode')
changed_modules.add('scancode')

if TRACE:
print()
print('get_impacted_modules:', changed_modules)
return changed_modules


def get_changed_files(base_branch='develop'):
"""
Return a list of changed file paths against the `base_branch`.
Or locally only if `base_branch` is None.
Raise an exception on errors.
"""
# this may fail with exceptions
cmd = 'git', 'diff', '--name-only',
if base_branch:
cmd += base_branch + '...',
changed_files = check_output(cmd, stderr=STDOUT)
changed_files = changed_files.replace('\\', '/')
changed_files = changed_files.splitlines(False)
changed_files = [cf for cf in changed_files if cf.strip()]
if TRACE:
print()
print('get_changed_files:', changed_files)
return changed_files


def get_git_branch():
"""
Return the current branch or raise an exception.
"""
from subprocess import check_output, STDOUT
# this may fail with exceptions
cmd = 'git', 'status',
branch = check_output(cmd, stderr=STDOUT).splitlines(False)[0]
_, _, branch = branch.partition('On branch')
branch = branch.strip()
if TRACE:
print()
print('get_git_branch:', branch)
return branch
Loading