Skip to content

TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper. Why extra " -" is being added after flake8 --format default? #127

@edvard-munch

Description

@edvard-munch

Flake8 works great when using it manually in command line. Doesn't work in Sublime. It seems like this command is wrong "cat src/app/conf/db.py | /home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8 --format default -"

Ubuntu 22.04
Sublime Text Build 4126
Python 3.10.4
Venv

Console output:

SublimeLinter: linter.py:1127         flake8: Checking lint mode 'background' vs lint reason 'on_modified'.  Ok.
SublimeLinter: sublime_linter.py:345  Delay linting 'db.py' for 0.0s
SublimeLinter: linter.py:1127         flake8: Checking lint mode 'background' vs lint reason 'on_save'.  Ok.
SublimeLinter: #3 linter.py:1144      flake8: linting 'db.py'
SublimeLinter: #3 linter.py:922       flake8: wanted executable is '/home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8'
SublimeLinter: #3 linter.py:1704      Running ...

  /home/edvard_munch/programming/python/education-backend-master  (working dir)
  $ cat src/app/conf/db.py | /home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8 --format default  -

SublimeLinter: #3 linter.py:62        ERROR: Traceback (most recent call last):
  File "/home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/main/application.py", line 363, in run
    self._run(argv)
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/main/application.py", line 351, in _run
    self.run_checks()
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/main/application.py", line 264, in run_checks
    self.file_checker_manager.run()
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/checker.py", line 323, in run
    self.run_serial()
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/checker.py", line 307, in run_serial
    checker.run_checks()
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/checker.py", line 589, in run_checks
    self.run_ast_checks()
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8/checker.py", line 494, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "/home/edvard_munch/programming/python/education-backend-master/venv/lib/python3.10/site-packages/flake8_mock.py", line 43, in run
    with open(self.filename, 'r') as file_to_check:
TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper

SublimeLinter: #3 linter.py:1231      flake8: output:
  -------------------
  <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>
  -------------------
SublimeLinter: #3 linter.py:1271      flake8: No matches for regex: ^.+?:(?P<line>\d+):(?P<col>\d+): (?:(?P<error>(?:F(?:40[24]|8(?:12|2[123]|31))|E(?:11[23]|90[12]|999)))|(?P<warning>\w+\d+):?) (?P<message>.*)
SublimeLinter: sublime_linter.py:593  Linting 'db.py' took 0.32s

Settings:

{
	"debug": true,

	"linters": {
        // The name of the linter you installed
        "flake8": {
            // Disables the linter. The default here is 'not set'
            "disable": false,

            // Additional arguments for the command line. Either a string
            // or an array. If set to a string, we 'shlex.split' it*.
            // E.g. '--ignore D112' or ['--config', './.config/foo.ini']
            //
            // * Note: Use proper quoting around paths esp. on Windows!
            "args": [""],

            // Path to the executable to be used. Either a string or an
            // array. E.g. ['nvm', 'exec', '8.6', 'eslint']
            "executable": "/home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8",

            // A modified runtime environment for the lint job. Settings here
            // override the default, inherited ENV.
            "env": {},

            // Exclude files that match the given pattern(s).
            "excludes": [],

            // Suppress errors that match the the given pattern(s).
            // Either a 'string' or an 'array'. Each input string is handled as
            // a case-insensitive regex pattern and matched against the
            // error_type, code, and message. If it matches, the error will be
            // thrown away.
            // E.g. ["warning: ", "W3\d\d: ", "missing <!DOCTYPE> declaration"]
            "filter_errors": [],

            // Lint mode determines when the linter is run. The linter setting
            // will take precedence over the global setting.
            "lint_mode": "background",

            // Determines for which views this linter will run.
            "selector": "",

            // A list of additional style definition blocks.
            "styles": [
                {
                    // Instead of 'types' you can specify error 'codes' for
                    // a style definition block
                    "codes": [""]
                }
            ],

            // The current working dir the lint job will run in.
            "working_dir": "$folder",

            // **Only valid for PythonLinter**
            // Specify which python to use. Either a number or full path
            // to a python binary. SL will then basically use 'python -m'
            // to run the linter.
            "python": 3,

            // **Only valid for NodeLinter**
            // If true, will *not* use a globally installed binary
            "disable_if_not_dependency": false
        }
    },
	
}

I've noticed the line cmd = ('flake8', '--format', 'default', '${args}', '-'). Didn't dig deep enough to know why '-' is needed here. When I've tried to remove '-', thinking it will make sublime linter construct the command without extra '-' being added. No, it's not not that simple. Though it looks like the flake8 command is ok in this case.

SublimeLinter: linter.py:1127         flake8: Checking lint mode 'background' vs lint reason 'on_modified'.  Ok.
SublimeLinter: sublime_linter.py:345  Delay linting 'db.py' for 0.0s
SublimeLinter: linter.py:1127         flake8: Checking lint mode 'background' vs lint reason 'on_save'.  Ok.
SublimeLinter: #17 linter.py:1144     flake8: linting 'db.py'
SublimeLinter: #17 linter.py:922      flake8: wanted executable is '/home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8'
SublimeLinter: #17 linter.py:1704     Running ...

  /home/edvard_munch/programming/python/education-backend-master  (working dir)
  $ cat src/app/conf/db.py | /home/edvard_munch/programming/python/education-backend-master/venv/bin/flake8 --format default 

SublimeLinter: #17 linter.py:1231     flake8: output:
  :0:1: E902 FileNotFoundError: [Errno 2] No such file or directory: ''
SublimeLinter: #17 linter.py:1271     flake8: No matches for regex: ^.+?:(?P<line>\d+):(?P<col>\d+): (?:(?P<error>(?:F(?:40[24]|8(?:12|2[123]|31))|E(?:11[23]|90[12]|999)))|(?P<warning>\w+\d+):?) (?P<message>.*)
SublimeLinter: sublime_linter.py:593  Linting 'db.py' took 0.29s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions