Skip to content

Commit

Permalink
Make Pyright configuration file paths absolute
Browse files Browse the repository at this point in the history
To resolve issues with configuration files placed in non-standard locations outside the working tree, make these paths absolute relative to the arcanist project root.

This was the implicit behavior previously, so this should not be a breaking change.

Also change the format of command flags from `'--project /path/to/foo.json'` to `'--project=/path/to/foo.json'` to resolve issues with pyright's interpretation of them.
  • Loading branch information
steverice committed Apr 21, 2022
1 parent 59a869a commit 3ab336a
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/PyrightLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class PyrightLinter extends NodeExternalLinter {

private $projectDirectory = null;
private $projectPath = null;
private $typeshedPath = null;
private $venvPath = null;

Expand Down Expand Up @@ -55,15 +55,15 @@ public function getLinterConfigurationOptions() {
$options = array(
'pyright.project' => array(
'type' => 'optional string',
'help' => pht('Use the configuration file at this location (%s)', 'https://github.com/microsoft/pyright/blob/master/docs/configuration.md'),
'help' => pht('Use the configuration file at this location relative to project root (%s)', 'https://github.com/microsoft/pyright/blob/master/docs/configuration.md'),
),
'pyright.typeshed-path' => array(
'type' => 'optional string',
'help' => pht('Use typeshed type stubs at this location'),
'help' => pht('Use typeshed type stubs at this location, relative to project root'),
),
'pyright.venv-path' => array(
'type' => 'optional string',
'help' => pht('Directory that contains virtual environments'),
'help' => pht('Directory that contains virtual environments, relative to project root'),
),
);
return $options + parent::getLinterConfigurationOptions();
Expand All @@ -72,7 +72,7 @@ public function getLinterConfigurationOptions() {
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'pyright.project':
$this->projectDirectory = $value;
$this->projectPath = $value;
return;
case 'pyright.typeshed-path':
$this->typeshedPath = $value;
Expand All @@ -84,6 +84,18 @@ public function setLinterConfigurationValue($key, $value) {
return parent::setLinterConfigurationValue($key, $value);
}

public function getProjectPath() {
return $this->projectPath ? $this->getEngine()->getFilePathOnDisk($this->projectPath) : null;
}

public function getTypeshedPath() {
return $this->typeshedPath ? $this->getEngine()->getFilePathOnDisk($this->typeshedPath) : null;
}

public function getVenvPath() {
return $this->venvPath ? $this->getEngine()->getFilePathOnDisk($this->venvPath) : null;
}

public function getNodeBinary() {
return 'pyright';
}
Expand All @@ -95,14 +107,14 @@ protected function getMandatoryFlags() {
protected function getDefaultFlags() {
$flags = array();

if ($this->projectDirectory) {
$flags[] = '--project '.$this->projectDirectory;
if ($this->getProjectPath()) {
$flags[] = '--project='.$this->getProjectPath();
}
if ($this->typeshedPath) {
$flags[] = '--typeshed-path '.$this->typeshedPath;
if ($this->getTypeshedPath()) {
$flags[] = '--typeshed-path='.$this->getTypeshedPath();
}
if ($this->venvPath) {
$flags[] = '--venv-path '.$this->venvPath;
if ($this->getVenvPath()) {
$flags[] = '--venv-path='.$this->getVenvPath();
}

return $flags;
Expand Down Expand Up @@ -170,7 +182,7 @@ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
case 2: // Fatal error occurred with no errors or warnings reported
throw new Exception(pht("Fatal error while linting %s:\n%s", $path, $stderr));
case 3: // Config file could not be read or parsed
throw new Exception(pht("Could not read config file at %s", $this->projectDirectory));
throw new Exception(pht("Could not read config file at %s", $this->getProjectPath()));
default:
break;
}
Expand Down

0 comments on commit 3ab336a

Please sign in to comment.