question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to specify in the settings to run with a `-p` flag?

See original GitHub issue

Error:

error: Source file found twice under different module names:

A working solution for a command line Mypy usage:

https://github.com/python/mypy/issues/8944#issuecomment-678725333

Question:

The solution works when I run Mypy from a command line. E.g.:

python -m mypy -p src -p tests

How to pass the -p flag in the β€œargs” settings section?

args: [--no-strict-optional, --ignore-missing-imports, --package] <-- does not work:

Package name β€˜src/foobar/spameggs.py’ cannot have a slash in it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
AIGeneratedUsernamecommented, Feb 24, 2021

Thank you. I’ve tried your code above but still had issues: src/utils/foobar.py: error: Source file found twice under different module names: 'backend_data.src.common' and 'src.common'

I investigated further and here is my working solution:

-   repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.812
    hooks:
    -   id: mypy
        args: [
                '--namespace-packages',
                '--explicit-package-bases'
        ]
1reaction
yehoshuadimarskycommented, Jan 19, 2022

Having the same issue, using namespace packages. Per Guido’s comment here https://github.com/python/mypy/issues/8944#issuecomment-678725333 if we want to use mypy on namespace packages it ONLY works with -p companyname.package_name. But the problem is that pre-commit by default passes in a list of files to be checked, and that results in this error for me:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 2

usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: May only specify one of: module/package, files, or command.

Is there a way to use the -p option?

Files layout:

.
β”œβ”€β”€ common-utils
β”‚   β”œβ”€β”€ companyname
β”‚   β”‚   └── utils
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       β”œβ”€β”€ logging.py
β”‚   β”‚       β”œβ”€β”€ loguru_models.py
β”‚   β”‚       β”œβ”€β”€ parallelize.py
β”‚   β”‚       β”œβ”€β”€ py.typed
β”‚   β”‚       └── scheduling.py
β”‚   β”œβ”€β”€ tests
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── test_scheduler.py
β”‚   └── setup.py
β”œβ”€β”€ config
β”‚   β”œβ”€β”€ predictapi.yaml
β”‚   └── secret.yaml
β”œβ”€β”€ predictapi
β”‚   β”œβ”€β”€ companyname
β”‚   β”‚   └── predictapi
β”‚   β”‚       β”œβ”€β”€ demo_model
β”‚   β”‚       β”‚   β”œβ”€β”€ config.yaml
β”‚   β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚       β”‚   β”œβ”€β”€ model.py
β”‚   β”‚       β”‚   └── test_model.py
β”‚   β”‚       β”œβ”€β”€ api.py
β”‚   β”‚       β”œβ”€β”€ constants.py
β”‚   β”‚       β”œβ”€β”€ data_utils.py
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       β”œβ”€β”€ log_utils.py
β”‚   β”‚       β”œβ”€β”€ main.py
β”‚   β”‚       β”œβ”€β”€ object_schemas.py
β”‚   β”‚       β”œβ”€β”€ pandas_schemas.py
β”‚   β”‚       β”œβ”€β”€ py.typed
β”‚   β”‚       └── settings.py
β”‚   β”œβ”€β”€ tests
β”‚   β”‚   β”œβ”€β”€ conftest.py
β”‚   β”‚   └── __init__.py
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ env.yml
β”‚   β”œβ”€β”€ README.md
β”‚   └── setup.py
β”œβ”€β”€ env-dev.yml
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ README.md
└── setup.cfg

setup.cfg

[mypy]
exclude=(/build|tests/)|(setup|_pb2\.py$)
ignore_missing_imports=True
namespace_packages=True
explicit_package_bases=False
show_error_codes=True

.pre-commit-config.yaml

# yaml-language-server: $schema=https://json.schemastore.org/pre-commit-config.json

minimum_pre_commit_version: 2.9.3
exclude: (\.(/build/)|(\.proto$)|(_pb2)\.py$)|ml-utils/.*
repos:
  - repo: meta
    hooks:
      - id: identity
      - id: check-hooks-apply
  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: "v0.931"
    hooks:
      - id: mypy
        additional_dependencies:
          [types-pytz==2021.1.2, types-protobuf, types-PyYAML, types-requests]
        exclude: (/tests/)|(setup\.py$)
        args:
          - "--namespace-packages"
          - "--explicit-package-bases"
          - "-p companyname.predictapi"
          - "-p companyname.utils"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial for using feature flags in a .NET Core app
Integrate with App Configuration when you're using it to manage feature flags. Set up feature management. To access the .NET Core featureΒ ...
Read more >
AP with Flag ID | Wireless Access - Airheads Community
The I flag can be caused by a number of things, but most of them show up under profile-errors. Check to make sure...
Read more >
Using AWS AppConfig Feature Flags
Click Create environment and you should be taken back to the Start deployment screen where your new Environment will be pre-selected. Here, forΒ ......
Read more >
port flag settings sometimes don't seem to work on VMAX with ...
When I ran a "symaccess -sid xxx show clustername -type init -detail" I can see that the override flags are set as they...
Read more >
Flag - Atlassian Developer
Flags are the primary method for providing system feedback in the product user interface. Messages include notifications of various kinds: alerts,Β ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found