Are pysa users expected to copy configuration files?

240 Views Asked by At

Facebook's Pysa tool looks useful, in the Pysa tutorial exercises they refer to files that are provided in the pyre-check repository using a relative path to include a path outside of the exercise directory.

https://github.com/facebook/pyre-check/blob/master/pysa_tutorial/exercise1/.pyre_configuration

{
    "source_directories": ["."],
    "taint_models_path": ["."],
    "search_path": [
        "../../stubs/"
    ],
    "exclude": [
        ".*/integration_test/.*"
    ]
}

There are stubs provided for Django in the pyre-check repository which if I know the path where pyre check is installed I can hard-code in my .pyre_configuration and get something working but another developer may install pyre-check differently.

Is there a better way to refer to these provided stubs or should I copy them to the repository I'm working on?

2

There are 2 best solutions below

0
GBleaney On

Many projects have a standard development environment, allowing for hard coded paths in the .pyre_configuration file. These will usually point into the venv, or some other standard install location for dependencies.

For projects without a standard development environment, you could trying incorporating pyre init into your setup scripts. pyre init will setup a fresh .pyre_configuration file with paths that correspond to the current install of pyre. For additional configuration you want to add on top of the generated .pyre_configuration file (such as a pointer to local taint models), you can hand write a .pyre_configuration.local, which will act as an overlay and overwrite/add to the content of .pyre_configuration.

0
Maxim Masiutin On

Pyre-check looks for the stubs in the directory specified by the typeshed directive in the configuration file.

The easiest way is to move stubs provided for Django in the pyre-check repository to the typeshed directory that is in the pyre-check directory.

For example, if you have installed pyre-check to the ~/.local/lib directory, move the django directory from ~/.local/lib/pyre_check/stubs to ~/.local/lib/pyre_check/typeshed/third_party/2and3/ and make sure your .pyre_configuration file will look like this:

{
  "source_directories": ["~/myproject"],
  "taint_models_path": "~/myproject/taint",
  "typeshed": "~/.local/lib/pyre_check/typeshed"
}

In this case, your Django stubs directory will be ~/.local/lib/pyre_check/typeshed/third_parth/2and3/django

Pyre-check uses the following algorithm to traverse across the typeshed directory:

  1. If it contains the third_party subdirectory, it uses a legacy method: enters just the two subdirectories: stdlib and third_party and there looks for any subdirectory except those with names starting with 2 but not 2and3, and looks for the modules in those subdirectories like 2and3, e.g. in third_party/2and3/
  2. Otherwise, it enters the subdirectories stubs and stdlib, and looks for modules there, e.g. in stubs/, but not in stubs/2and3/.

That's why specifying multiple paths may be perplexing and confusing, and the easiest way is to setup the typeshed directory to ~/.local/lib/pyre_check/typeshed/ and move django to third_parth/2and3, so it will be ~/.local/lib/pyre_check/typeshed/third_parth/2and3/django.

Also don't forget to copy the .pysa files that you need to the taint_models_path directory. Don't set it up to the directory of the Pyre-check, create your own new directory and copy only those files that are relevant to you.