-
-
Notifications
You must be signed in to change notification settings - Fork 533
passenv: include TERM by default #1441
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
Comments
Some tests will use the presence of TERM to detect that they're talking to a terminal and adapt their output to the terminal width, breaking doctests. |
@aarchiba |
I think usually |
Having it unset shouldn't be a problem - that should probably be the default. If you are needing it set, then you may need to have different environments with it set to different values ( FYI - I usually keep mine set to |
It is a problem when e.g. using pdb/pdb++ or anything else that might want to interact with the terminal. Even simple things like escape codes for cursor keys differ across terminals, and TERM is meant to provide the information to get the correct codes. My point is that it shouldn't be a problem if it is set / passed through (usually).
That would be the case when explicitly testing terminal apps, but then you would usually set this via pytest params etc for different scenarios anyway.
When you care about it you are setting / handling it already.
? |
@blueyed I wouldn't expect to be running a If you are testing something that does require it then you would want to control it, not be user environment dependent. There are many applications (APIs) that And in fact you cannot guarantee it would be set on any CI system either ( neither Travis-CI https://docs.travis-ci.com/user/environment-variables/, and Circle-CI https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables list is as a provided default environment variable; I'm sure you'll find similarly with other CI systems). Point being, by having it unset by default you match what your CI system will be like. So if you are testing
|
@BenjamenMeyer: Unless
|
That's for a local use case, where you add the
Only @aarchiba said this, and it sounded like it was confusing being connected to a terminal with having TERM set. I have not checked, but I would guess that Travis (and at least most Linux CIs) actually will have "$TERM" set. Otherwise apparently mypy would not display colors there. |
For me it feels that TERM is use case dependent if useful. If someone hits such a use case (e.g. mypy) just pass it through by specifying TERM within passenv. |
@blueyed @Alexander255 there's nothing stopping you from using the
@Alexander255 I linked to Travis-CI's and Circle CI's list of environment variables. They don't set TERM at all, or at least they don't specify that TERM is set so you cannot guarantee it will be set or set to anything sane. For consistency purposes it makes sense for them to not set it. |
Sure, I know about setenv, and added it to 2+ projects already. @BenjamenMeyer Travis outputs terminal escape sequences all over (for colors etc) - it certainly has TERM set also. |
@gaborbernat: Why should every person wanting colored output from @BenjamenMeyer: If Travis, Circle and however doesn't set the As such hard-coding *Starting with some release of Windows 10 the opt-in facility of having the Windows Prompt interpret vt100-compatible escape codes has been added. |
@Alexander255 perhaps the best solution to your issue is documentation - either here or in mypy. Not everyone needs TERM set or wants it set, and there's plenty of use-cases requiring it to be as it currently is. If it was really necessary then it would have gotten set a long time ago. $0.02 FWIW. |
Can you name one then, please? (This is what I've asked for 12 days ago basically.)
It's not really necessary (nobody said that), since there is a workaround - and usually things that are not good terminal citizens (or do not need to be, i.e. they do not use info from TERM, but just basic colors etc (vt100)) are fine. I clearly see the benefit of having setenv/passenv. Anyway, at least I've learnt from this that you can have |
@blueyed there was an example given very early in this discussion - #1441 (comment). I've never seen any kind of issue with tools under tox generating output that is user visible using the current default behavior (nose, nose2, pytest, pep8, pycodestyle, sphinx, bandit, flake8, black) as related to TERM. Out of all the projects I've worked on and interacted with, I'd say a project that is dependent on the value of TERM - the use-case this was opened for - is the exception, not the rule. Typically in shell scripts (Bash, Batch, etc) you unset by setting the value equal to nothing; don't know if that would work with tox or not. |
#1441 (comment) is not a concrete example, and I got the feeling that there is a misunderstanding - "talking to a terminal" means that fd 0, 1, or 2 are connected to a tty. Checking if "TERM" is set means knowing what terminal you are talking to. That's what I've said back then already.
Your examples are all "bad citizens" with regard to using terminal escape sequences: if they use colors they are just assuming the escape codes are being understood. And as far as I can see it's just missing knowledge/laziness that e.g. pytest does not use curses, but hard-coded escape sequences.
Nope. Only Windows has this speciality (depending on the API you are using). % env -u TERM sh -c 'echo $TERM'
dumb
% env TERM= bash -c 'echo $TERM'
(you can see here that bash defaults to TERM=dumb if unset, same for dash (more POSIX)) Given this example, what about tox using % TERM=dumb infocmp
# Reconstructed via infocmp from file: /usr/share/terminfo/d/dumb
dumb|80-column dumb tty,
am,
cols#80,
bel=^G, cr=\r, cud1=\n, ind=\n,
Yeah, the question was if this could easily be unset in tox. |
Just for completeness: this is how mypy initializes colors: https://github.com/python/mypy/blob/95a41fa1a92576f94ae36ee658fbe4dd36a00ef7/mypy/util.py#L525-L551 Note that it will also not use colors for TERM=dumb, but not because it uses the actual terminfo DB, but has the name hardcoded (as with the color codes)! So if you copy "dumb" to "dumb2" it will use (hardcoded) colors with "TERM=dumb2", making it a "bad citizen" (had a longer comment here, but the bot killed it by changing my comment).
|
@BenjamenMeyer |
@blueyed I would leave it as it is - default it to not set TERM at all. Whether or not pytest has colors doesn't bother me. If you take into account folks that are color-blind - which varies all over from not seeing some colors to any color - using coloration could actually be problematic for some. Per tox, I would simply state in the docs/FAQ what the default is. Tools like pytest, mypy, etc if they need a specific setting to get something working then they should be responsible for documenting that in their docs/FAQ. |
Ok, well - I'm still curious about a concrete example where this makes a difference for the worse.
They are documented.
The point here is that it is common sense that "TERM" is set within terminals (and tox runs in a terminal). btw: tox passes through LANG/LANGUAGE, which actually makes a difference often - so much that you often use tox/src/tox/config/__init__.py Lines 665 to 674 in e7136f5
|
@blueyed said:
If you change it, you'll find out since the cases where it makes a difference will then break since it would be a breaking change from historic behavior. Though as you noted the That said, it was earlier said:
No, tox is not preventing it. It's just making it an explicit requirement to specify it if needed or desired. Per the analysis of mypy vs pytest in #1441 (comment) - interesting analysis. I wouldn't necessarily call pytest a bad citizen since they're not using curses and provide a configuration for it to turn it on/off. Perhaps their default should be different. Not all platforms use |
@BenjamenMeyer
Well, if the terminfo says "I can not do colors", a tool should not send "weird characters" (escape codes to use colors, not understood by the terminal) - don't you think? "good citizens" in that sense are those that go the extra mile to use the terminfo, not just assume something. It is like using Also note that While I would still suggest to pass through TERM (since it helps with getting the expected behavior, especially when not using TERM=dumb (which would be my less preferred suggestion)), I've put enough time into this for now I think.. :D |
Apropos handling TERM=dumb: #1290 ;) (only came across it when searching for this issue here) |
@blueyed #1290 I believe would be a different issue as that is regarding |
My point was more that there are plenty of use-cases out there you won't necessarily know about until changing the default behavior and have them come out of the woodworks complaining. Some may just fix stuff (if it's easy enough to do), others may complain. Hopefully the community as a whole would be as pleasant as this discussion has been if such a change does happen.
If terminfo is available - again not all platforms or shells support terminfo - and the tool understands terminfo, then yes. I think most devs don't really understand terminfo and just do what works for them until someone comes along and tells them otherwise, or contributes such functionality. NOTE: MS dropped support for ANSI term info, and are really only adding it back now due to the whole Windows Subsystem For Linux thing (see https://en.wikipedia.org/wiki/ANSI_escape_code). DOS and Command shell (command.com, cmd.exe, PowerShell) were never really TTY device backed. The default of not having TERM provides the most flexibility since users can specify it if desired.
Likewise. Also, thanks for the civil discussion! |
TERM was rejected upstream in tox-dev#1441.
For reference: Sphinx is also affected by this: sphinx-doc/sphinx#7248 |
..which means basically any Python project using Sphinx with a "docs" testenv (in case that was not clear). |
tox is stupid to not include TERM by default (tox-dev/tox#1441). This makes `tox -e docs` use proper progress indicators. It splits `passenv` into a list to make diffs easier in the future. Output from `tox -e docs` before: ``` Running Sphinx v4.0.0+/4633ab906 loading pickled environment... failed failed: build environment version not current building [mo]: targets for 0 po files that are out of date building [html]: targets for 77 source files that are out of date updating environment: [new config] 77 added, 0 changed, 0 removed reading sources... [ 1%] authors reading sources... [ 2%] changes reading sources... [ 3%] code_of_conduct reading sources... [ 5%] contents reading sources... [ 6%] develop reading sources... [ 7%] development/tutorials/examples/README reading sources... [ 9%] development/tutorials/helloworld reading sources... [ 10%] development/tutorials/index reading sources... [ 11%] development/tutorials/recipe reading sources... [ 12%] development/tutorials/todo reading sources... [ 14%] devguide reading sources... [ 15%] examples reading sources... [ 16%] extdev/appapi reading sources... [ 18%] extdev/builderapi reading sources... [ 19%] extdev/collectorapi reading sources... [ 20%] extdev/deprecated reading sources... [ 22%] extdev/domainapi reading sources... [ 23%] extdev/envapi reading sources... [ 24%] extdev/i18n reading sources... [ 25%] extdev/index reading sources... [ 27%] extdev/logging reading sources... [ 28%] extdev/markupapi reading sources... [ 29%] extdev/nodes reading sources... [ 31%] extdev/parserapi reading sources... [ 32%] extdev/projectapi reading sources... [ 33%] extdev/utils reading sources... [ 35%] faq reading sources... [ 36%] glossary reading sources... [ 37%] intro reading sources... [ 38%] latex reading sources... [ 40%] man/index reading sources... [ 41%] man/sphinx-apidoc reading sources... [ 42%] man/sphinx-autogen reading sources... [ 44%] man/sphinx-build reading sources... [ 45%] man/sphinx-quickstart reading sources... [ 46%] templating reading sources... [ 48%] theming reading sources... [ 49%] usage/advanced/intl reading sources... [ 50%] usage/advanced/setuptools reading sources... [ 51%] usage/advanced/websupport/api /tmp/tox/home/daniel/Vcs/sphinx/docs/lib/python3.8/site-packages/sphinxcontrib/websupport/__init__.py:18: RemovedInSphinx40Warning: sphinx.util.pycompat.htmlescape is deprecated. Check CHANGES for Sphinx API modifications. from sphinxcontrib.websupport.core import WebSupport # NOQA reading sources... [ 53%] usage/advanced/websupport/index reading sources... [ 54%] usage/advanced/websupport/quickstart reading sources... [ 55%] usage/advanced/websupport/searchadapters reading sources... [ 57%] usage/advanced/websupport/storagebackends reading sources... [ 58%] usage/builders/index reading sources... [ 59%] usage/configuration reading sources... [ 61%] usage/extensions/autodoc reading sources... [ 62%] usage/extensions/autosectionlabel reading sources... [ 63%] usage/extensions/autosummary reading sources... [ 64%] usage/extensions/coverage reading sources... [ 66%] usage/extensions/doctest reading sources... [ 67%] usage/extensions/duration reading sources... [ 68%] usage/extensions/example_google reading sources... [ 70%] usage/extensions/example_numpy reading sources... [ 71%] usage/extensions/extlinks reading sources... [ 72%] usage/extensions/githubpages reading sources... [ 74%] usage/extensions/graphviz reading sources... [ 75%] usage/extensions/ifconfig reading sources... [ 76%] usage/extensions/imgconverter reading sources... [ 77%] usage/extensions/index reading sources... [ 79%] usage/extensions/inheritance reading sources... [ 80%] usage/extensions/intersphinx reading sources... [ 81%] usage/extensions/linkcode reading sources... [ 83%] usage/extensions/math reading sources... [ 84%] usage/extensions/napoleon reading sources... [ 85%] usage/extensions/todo reading sources... [ 87%] usage/extensions/viewcode reading sources... [ 88%] usage/installation reading sources... [ 89%] usage/markdown reading sources... [ 90%] usage/quickstart reading sources... [ 92%] usage/restructuredtext/basics reading sources... [ 93%] usage/restructuredtext/directives reading sources... [ 94%] usage/restructuredtext/domains reading sources... [ 96%] usage/restructuredtext/field-lists reading sources... [ 97%] usage/restructuredtext/index reading sources... [ 98%] usage/restructuredtext/roles reading sources... [100%] usage/theming looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [ 1%] authors writing output... [ 2%] changes writing output... [ 3%] code_of_conduct writing output... [ 5%] contents writing output... [ 6%] develop writing output... [ 7%] development/tutorials/examples/README writing output... [ 9%] development/tutorials/helloworld writing output... [ 10%] development/tutorials/index writing output... [ 11%] development/tutorials/recipe writing output... [ 12%] development/tutorials/todo writing output... [ 14%] devguide writing output... [ 15%] examples writing output... [ 16%] extdev/appapi writing output... [ 18%] extdev/builderapi writing output... [ 19%] extdev/collectorapi writing output... [ 20%] extdev/deprecated writing output... [ 22%] extdev/domainapi writing output... [ 23%] extdev/envapi writing output... [ 24%] extdev/i18n writing output... [ 25%] extdev/index writing output... [ 27%] extdev/logging writing output... [ 28%] extdev/markupapi writing output... [ 29%] extdev/nodes writing output... [ 31%] extdev/parserapi writing output... [ 32%] extdev/projectapi writing output... [ 33%] extdev/utils writing output... [ 35%] faq writing output... [ 36%] glossary writing output... [ 37%] intro writing output... [ 38%] latex writing output... [ 40%] man/index writing output... [ 41%] man/sphinx-apidoc writing output... [ 42%] man/sphinx-autogen writing output... [ 44%] man/sphinx-build writing output... [ 45%] man/sphinx-quickstart writing output... [ 46%] templating writing output... [ 48%] theming writing output... [ 49%] usage/advanced/intl writing output... [ 50%] usage/advanced/setuptools writing output... [ 51%] usage/advanced/websupport/api writing output... [ 53%] usage/advanced/websupport/index writing output... [ 54%] usage/advanced/websupport/quickstart writing output... [ 55%] usage/advanced/websupport/searchadapters writing output... [ 57%] usage/advanced/websupport/storagebackends writing output... [ 58%] usage/builders/index writing output... [ 59%] usage/configuration writing output... [ 61%] usage/extensions/autodoc writing output... [ 62%] usage/extensions/autosectionlabel writing output... [ 63%] usage/extensions/autosummary writing output... [ 64%] usage/extensions/coverage writing output... [ 66%] usage/extensions/doctest writing output... [ 67%] usage/extensions/duration writing output... [ 68%] usage/extensions/example_google writing output... [ 70%] usage/extensions/example_numpy writing output... [ 71%] usage/extensions/extlinks writing output... [ 72%] usage/extensions/githubpages writing output... [ 74%] usage/extensions/graphviz writing output... [ 75%] usage/extensions/ifconfig writing output... [ 76%] usage/extensions/imgconverter writing output... [ 77%] usage/extensions/index writing output... [ 79%] usage/extensions/inheritance writing output... [ 80%] usage/extensions/intersphinx writing output... [ 81%] usage/extensions/linkcode writing output... [ 83%] usage/extensions/math writing output... [ 84%] usage/extensions/napoleon writing output... [ 85%] usage/extensions/todo writing output... [ 87%] usage/extensions/viewcode writing output... [ 88%] usage/installation writing output... [ 89%] usage/markdown writing output... [ 90%] usage/quickstart writing output... [ 92%] usage/restructuredtext/basics writing output... [ 93%] usage/restructuredtext/directives writing output... [ 94%] usage/restructuredtext/domains writing output... [ 96%] usage/restructuredtext/field-lists writing output... [ 97%] usage/restructuredtext/index writing output... [ 98%] usage/restructuredtext/roles writing output... [100%] usage/theming generating indices... genindex py-modindexdone highlighting module code... [ 2%] docutils.parsers.rst highlighting module code... [ 4%] logging highlighting module code... [ 7%] sphinx.addnodes highlighting module code... [ 9%] sphinx.application highlighting module code... [ 11%] sphinx.builders highlighting module code... [ 14%] sphinx.builders.changes highlighting module code... [ 16%] sphinx.builders.dirhtml highlighting module code... [ 19%] sphinx.builders.dummy highlighting module code... [ 21%] sphinx.builders.epub3 highlighting module code... [ 23%] sphinx.builders.gettext highlighting module code... [ 26%] sphinx.builders.html highlighting module code... [ 28%] sphinx.builders.latex highlighting module code... [ 30%] sphinx.builders.linkcheck highlighting module code... [ 33%] sphinx.builders.manpage highlighting module code... [ 35%] sphinx.builders.singlehtml highlighting module code... [ 38%] sphinx.builders.texinfo highlighting module code... [ 40%] sphinx.builders.text highlighting module code... [ 42%] sphinx.builders.xml highlighting module code... [ 45%] sphinx.config highlighting module code... [ 47%] sphinx.domains highlighting module code... [ 50%] sphinx.environment highlighting module code... [ 52%] sphinx.environment.collectors highlighting module code... [ 54%] sphinx.errors highlighting module code... [ 57%] sphinx.events highlighting module code... [ 59%] sphinx.ext.autodoc highlighting module code... [ 61%] sphinx.ext.coverage highlighting module code... [ 64%] sphinx.locale highlighting module code... [ 66%] sphinx.parsers highlighting module code... [ 69%] sphinx.project highlighting module code... [ 71%] sphinx.transforms highlighting module code... [ 73%] sphinx.transforms.post_transforms highlighting module code... [ 76%] sphinx.transforms.post_transforms.images highlighting module code... [ 78%] sphinx.util.docutils highlighting module code... [ 80%] sphinx.util.logging highlighting module code... [ 83%] sphinxcontrib.applehelp highlighting module code... [ 85%] sphinxcontrib.devhelp highlighting module code... [ 88%] sphinxcontrib.htmlhelp highlighting module code... [ 90%] sphinxcontrib.qthelp highlighting module code... [ 92%] sphinxcontrib.serializinghtml highlighting module code... [ 95%] sphinxcontrib.websupport.core highlighting module code... [ 97%] sphinxcontrib.websupport.search highlighting module code... [100%] sphinxcontrib.websupport.storage writing additional pages... index search opensearchdone copying images... [ 7%] _static/translation.png copying images... [ 15%] _static/more.png copying images... [ 23%] _static/themes/alabaster.png copying images... [ 30%] _static/themes/classic.png copying images... [ 38%] _static/themes/sphinxdoc.png copying images... [ 46%] _static/themes/scrolls.png copying images... [ 53%] _static/themes/agogo.png copying images... [ 61%] _static/themes/traditional.png copying images... [ 69%] _static/themes/nature.png copying images... [ 76%] _static/themes/haiku.png copying images... [ 84%] _static/themes/pyramid.png copying images... [ 92%] _static/themes/bizstyle.png copying images... [100%] _static/themes/sphinx_rtd_theme.png copying downloadable files... [ 50%] usage/extensions/example_google.py copying downloadable files... [100%] usage/extensions/example_numpy.py copying static files... ... done copying extra files... done dumping search index in English (code: en)... done dumping object inventory... done build succeeded. ``` After: ``` Running Sphinx v2.4.3 loading pickled environment... done building [mo]: targets for 0 po files that are out of date building [html]: targets for 0 source files that are out of date updating environment: 0 added, 5 changed, 0 removed /tmp/tox/home/daniel/Vcs/sphinx/docs/lib/python3.8/site-packages/sphinxcontrib/websupport/__init__.py:18: RemovedInSphinx40Warning: sphinx.util.pycompat.htmlescape is deprecated. Check CHANGES for Sphinx API modifications. from sphinxcontrib.websupport.core import WebSupport # NOQA reading sources... [100%] usage/builders/index looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [100%] usage/builders/index generating indices... genindex py-modindexdone highlighting module code... [100%] sphinxcontrib.websupport.storage writing additional pages... index search opensearchdone copying downloadable files... [100%] usage/extensions/example_numpy.py copying static files... ... done copying extra files... done dumping search index in English (code: en)... done dumping object inventory... done build succeeded. The HTML pages are in build/sphinx/html. ```
Uh oh!
There was an error while loading. Please reload this page.
I think it would be good to include
TERM
inpassenv
by default, since it gets used with readline(-alike) programs, e.g. pdbpp (via pyrepl), wheresetupterm()
then would fail without it being known.Adding
TERM
topassenv
explicitly works, but should not really be required, since there is usually no harm being done by passing this through, except for providing information about the used terminal.doc ref: https://github.com/tox-dev/tox/blame/1883946bd3f233f58928864700eb0e6007332ffd/docs/config.rst#L388-L392
Related issue: #250
Affected programs:
The text was updated successfully, but these errors were encountered: