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

Rebrand #52

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 0 additions & 28 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

17 changes: 0 additions & 17 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# basedpyright

basedpyright is a work-in-progress fork of pyright.
Basedpyright is a static type checker for Python that is built on top of the work done by the [pyright project](https://github.com/Microsoft/pyright).

## why?

pyright has several serious issues which prevent it from being a valid competitor to mypy, which i aim to fix in basedpyright
pyright has several serious limitations which were the main motivation behind this fork.

### pyright has no way to pin the version used by vscode

Expand Down Expand Up @@ -43,7 +43,7 @@ basedpyright differs from pyright by publishing the command line tool as a pypi

```shell
> basedpyright --help
Usage: pyright [options] files...
Usage: basedpyright [options] files...
Options:
--createstub <IMPORT> Create type stub file(s) for import
--dependencies Emit import dependency information
Expand Down Expand Up @@ -98,7 +98,7 @@ below are the changes i recommend making to your project when adding basedpyrigh

## `.vscode/settings.json`

remove any settings starting with `python.analysis`, as they can interfere with the vscode extension and cause it to behave differently to the CLI. these settings can be specified using the `tool.pyright` section in `pyroject.toml` instead (see below)
remove any settings starting with `python.analysis`, as they can interfere with the vscode extension and cause it to behave differently to the CLI. these settings can be specified using the `tool.basedpyright` (or `tool.pyright`) section in `pyroject.toml` instead (see below)

## `pyproject.toml`

Expand All @@ -110,7 +110,7 @@ dev = [
"basedpyright", # you can pin the version here if you want, or just rely on the lockfile
]

[tool.pyright]
[tool.basedpyright]
typeCheckingMode = "strict" # many settings are not enabled even in strict mode, which is why basedpyright will soon support an "all" option
```

Expand Down
10 changes: 1 addition & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
![Pyright](img/PyrightLarge.png)

# Static type checker for Python

Pyright is a full-featured, [standards-compliant](https://htmlpreview.github.io/?https://github.com/python/typing/blob/main/conformance/results/results.html) static type checker for Python. It is designed for high performance and can be used with large Python source bases.

Pyright includes a [command-line tool](command-line.md), a language server, and an [extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright).


[filename](../README.md ':include')
2 changes: 1 addition & 1 deletion docs/_navbar.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[Github Site](https://github.com/Microsoft/pyright)
[Github Site](https://github.com/detachhead/basedpyright)
130 changes: 2 additions & 128 deletions docs/ci-integration.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,3 @@
## Integrating Pyright into Continuous Integration
# Integrating Pyright into Continuous Integration

### Adding Pyright badge to README.md

[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)

To add a “pyright: checked” SVG badge to your project’s README.md file, use the following:

```text
[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
```

### Running Pyright as a github action

You can configure pyright to run as a github action.

```yml
- uses: jakebailey/pyright-action@v1
with:
version: 1.1.xxx # Optional (if you want to pin the version)
```

Refer to the [pyright-action project](https://github.com/jakebailey/pyright-action) for more options.

### Running Pyright in gitlab (with code-quality review)

You can configure pyright to run in gitlab, and generate a compatible codequality report.

```yml
job_name:
before_script:
- npm i -g pyright
- npm i -g pyright-to-gitlab-ci
script:
- pyright <python source> --outputjson > report_raw.json
after_script:
- pyright-to-gitlab-ci --src report_raw.json --output report.json --base_path .
artifacts:
paths:
- report.json
reports:
codequality: report.json
```

Refer to the [pyright-to-gitlab-ci](https://www.npmjs.com/package/pyright-to-gitlab-ci) package for more details.

### Running Pyright as a pre-commit hook

You can run pyright as a pre-commit hook using the community-maintained [Python wrapper for pyright](https://github.com/RobertCraigie/pyright-python). For pre-commit configuration instructions, refer to [this documentation](https://github.com/RobertCraigie/pyright-python#pre-commit).

### Running Pyright from a CI script

You can run pyright from a bash script. Here's a sample script that installs the latest version of pyright and runs it.

```bash
#!/bin/bash
PATH_TO_PYRIGHT=`which pyright`

vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}

# Node version check
echo "Checking node version..."
NODE_VERSION=`node -v | cut -d'v' -f2`
MIN_NODE_VERSION="10.15.2"
vercomp $MIN_NODE_VERSION $NODE_VERSION
# 1 == gt
if [[ $? -eq 1 ]]; then
echo "Node version ${NODE_VERSION} too old, min expected is ${MIN_NODE_VERSION}, run:"
echo " npm -g upgrade node"
exit -1
fi

# Do we need to sudo?
echo "Checking node_modules dir..."
NODE_MODULES=`npm -g root`
SUDO="sudo"
if [ -w "$NODE_MODULES" ]; then
SUDO="" #nop
fi

# If we can't find pyright, install it.
echo "Checking pyright exists..."
if [ -z "$PATH_TO_PYRIGHT" ]; then
echo "...installing pyright"
${SUDO} npm install -g pyright
else
# already installed, upgrade to make sure it's current
# this avoids a sudo on launch if we're already current
echo "Checking pyright version..."
CURRENT=`pyright --version | cut -d' ' -f2`
REMOTE=`npm info pyright version`
if [ "$CURRENT" != "$REMOTE" ]; then
echo "...new version of pyright found, upgrading."
${SUDO} npm upgrade -g pyright
fi
fi

echo "done."
pyright -w
```
see [the readme](../README.md#githubworkflowscheckyaml)
4 changes: 2 additions & 2 deletions docs/command-line.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Pyright Command-Line Options

Usage: pyright [options] [files...] (1)
Usage: basedpyright [options] [files...] (1)

Pyright can be run as either a VS Code extension or as a node-based command-line tool. The command-line version allows for the following options:
Pyright can be run as either a VS Code extension or as a command-line tool. The command-line version allows for the following options:

| Flag | Description |
| :--------------------------------- | :--------------------------------------------------- |
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Pyright offers flexible configuration options specified in a JSON-formatted text configuration. By default, the file is called “pyrightconfig.json” and is located within the root directory of your project. Multi-root workspaces (“Add Folder to Workspace…”) are supported, and each workspace root can have its own “pyrightconfig.json” file. For a sample pyrightconfig.json file, see [below](configuration.md#sample-config-file).

Pyright settings can also be specified in a `[tool.pyright]` section of a “pyproject.toml” file. A “pyrightconfig.json” file always takes precedent over “pyproject.toml” if both are present. For a sample pyproject.toml file, see [below](configuration.md#sample-pyprojecttoml-file).
Pyright settings can also be specified in a `[tool.basedpyright]` section of a “pyproject.toml” file. A “pyrightconfig.json” file always takes precedent over “pyproject.toml” if both are present. For a sample pyproject.toml file, see [below](configuration.md#sample-pyprojecttoml-file).

Relative paths specified within the config file are relative to the config file’s location. Paths with shell variables (including `~`) are not supported. Paths within a config file should generally be relative paths so the config file can be shared by other developers who contribute to the project.

Expand Down Expand Up @@ -305,7 +305,7 @@ The following is an example of a pyright config file:

## Sample pyproject.toml File
```toml
[tool.pyright]
[tool.basedpyright]
include = ["src"]
exclude = ["**/node_modules",
"**/__pycache__",
Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Pyright</title>
<title>BasedPyright</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
Expand All @@ -18,8 +18,8 @@
</script>
<script>
window.$docsify = {
name: 'Pyright',
nameLink: 'https://microsoft.github.io/pyright',
name: 'BasedPyright',
nameLink: 'https://detachhead.github.io/basedpyright',
search: 'auto',
loadSidebar: true,
loadNavbar: true,
Expand Down
31 changes: 4 additions & 27 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## Installation

⚠ basedpyright has only been tested on vscode. i don't use any other editor, so if you have issues with any of these other plugins feel free to raise an issue

### Language Server

#### VS Code
For most VS Code users, we recommend using the Pylance extension rather than Pyright. Pylance incorporates the Pyright type checker but features additional capabilities such as semantic token highlighting and symbol indexing. You can install the latest-published version of the Pylance VS Code extension directly from VS Code. Simply open the extensions panel and search for “Pylance”.
see https://github.com/DetachHead/basedpyright#vscode-extension

#### Vim
Vim/neovim users can install [coc-pyright](https://github.com/fannheyward/coc-pyright), the Pyright extension for coc.nvim.
Expand All @@ -17,29 +19,4 @@ Sublime text users can install the [LSP-pyright](https://github.com/sublimelsp/L
Emacs users can install [eglot](https://github.com/joaotavora/eglot) or [lsp-mode](https://github.com/emacs-lsp/lsp-mode) with [lsp-pyright](https://github.com/emacs-lsp/lsp-pyright).

### Command-line

#### Python Package
A [community-maintained](https://github.com/RobertCraigie/pyright-python) Python package by the name of “pyright” is available on pypi and conda-forge. This package will automatically install node (which Pyright requires) and keep Pyright up to date.

`pip install pyright`

or

`conda install pyright`

Once installed, you can run the tool from the command line as follows:
`pyright <options>`


#### NPM Package
Alternatively, you can install the command-line version of Pyright directly from npm, which is part of node. If you don't have a recent version of node on your system, install that first from [nodejs.org](https://nodejs.org).

To install pyright globally:
`npm install -g pyright`

On MacOS or Linux, sudo may be required to install globally:
`sudo npm install -g pyright`

To update to the latest version:
`sudo npm update -g pyright`

see https://github.com/DetachHead/basedpyright#pypi-package
16 changes: 12 additions & 4 deletions packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { MaxAnalysisTime, Program } from './program';
import { findPythonSearchPaths } from './pythonPathUtils';
import { IPythonMode } from './sourceFile';
import { TypeEvaluator } from './typeEvaluatorTypes';
import { githubRepo } from '../constants';

export const configFileNames = ['pyrightconfig.json'];
export const pyprojectTomlName = 'pyproject.toml';
Expand Down Expand Up @@ -942,16 +943,23 @@ export class AnalyzerService {
return this._attemptParseFile(pyprojectPath, (fileContents, attemptCount) => {
try {
const configObj = TOML.parse(fileContents);
if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).pyright) {
return (configObj.tool as TOML.JsonMap).pyright as object;
if (configObj && configObj.tool) {
const toml = configObj.tool as TOML.JsonMap;
if (toml.basedpyright && toml.pyright) {
this._console.error(
'Pyproject file cannot have both `pyright` and `basedpyright` sections. pick one'
);
return undefined;
}
return (toml.basedpyright || toml.pyright) as object;
}
} catch (e: any) {
this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`);
throw e;
}

this._console.info(
`Pyproject file "${pyprojectPath.toUserVisibleString()}" has no "[tool.pyright]" section.`
`Pyproject file "${pyprojectPath.toUserVisibleString()}" has no "[tool.basedpyright]" section.`
);
return undefined;
});
Expand Down Expand Up @@ -1140,7 +1148,7 @@ export class AnalyzerService {
'To reduce this time, open a workspace directory with fewer files ' +
'or add a pyrightconfig.json configuration file with an "exclude" section to exclude ' +
'subdirectories from your workspace. For more details, refer to ' +
'https://github.com/microsoft/pyright/blob/main/docs/configuration.md.'
`${githubRepo}/blob/main/docs/configuration.md.`
);
loggedLongOperationError = true;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/pyright-internal/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const toolName = 'basedpyright';

export const githubRepo = `https://github.com/detachhead/${toolName}`;
3 changes: 2 additions & 1 deletion packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import { WorkspaceSymbolProvider } from './languageService/workspaceSymbolProvid
import { Localizer, setLocaleOverride } from './localization/localize';
import { ParseResults } from './parser/parser';
import { InitStatus, WellKnownWorkspaceKinds, Workspace, WorkspaceFactory } from './workspaceFactory';
import { githubRepo } from './constants';

export interface ServerSettings {
venvPath?: Uri | undefined;
Expand Down Expand Up @@ -1399,7 +1400,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
const rule = diag.getRule();
if (rule) {
// Configuration.md is configured to have a link for every rule name.
return `https://github.com/microsoft/pyright/blob/main/docs/configuration.md#${rule}`;
return `${githubRepo}/blob/main/docs/configuration.md#${rule}`;
}
return undefined;
}
Expand Down
Loading
Loading