Skip to content

Commit f83a781

Browse files
committed
WIP
1 parent da80481 commit f83a781

File tree

22 files changed

+1575
-615
lines changed

22 files changed

+1575
-615
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
77
lerna-debug.log*
8+
.venv
9+
.idea
810

911
# Diagnostic reports (https://nodejs.org/api/report.html)
1012
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
5+
{
6+
"name": "Attach by Process ID",
7+
"processId": "${command:PickProcess}",
8+
"request": "attach",
9+
"skipFiles": [
10+
"<node_internals>/**"
11+
],
12+
"type": "node"
13+
},
414
{
515
"name": "Pyright CLI",
616
"type": "node",

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"editor.formatOnSave": true
99
},
1010
"editor.codeActionsOnSave": {
11-
"source.fixAll.eslint": true
11+
"source.fixAll.eslint": "explicit"
1212
},
1313
"typescript.tsdk": "node_modules/typescript/lib"
1414
}

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Start from a Node.js base image
2+
FROM node:16-alpine
3+
4+
# Install necessary dependencies for building Python
5+
RUN apk add --no-cache \
6+
git \
7+
build-base \
8+
openssl-dev \
9+
zlib-dev \
10+
bzip2-dev \
11+
readline-dev \
12+
sqlite-dev \
13+
xz-dev \
14+
tk-dev \
15+
libffi-dev \
16+
ncurses-dev \
17+
linux-headers
18+
19+
# Download, extract, and install Python 3.12
20+
RUN wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tar.xz && \
21+
tar -xf Python-3.12.0.tar.xz && \
22+
cd Python-3.12.0 && \
23+
./configure --enable-optimizations && \
24+
make -j$(nproc) && \
25+
make install && \
26+
cd .. && \
27+
rm -rf Python-3.12.0 Python-3.12.0.tar.xz && \
28+
ln -sf /usr/local/bin/python3.12 /usr/local/bin/python && \
29+
ln -sf /usr/local/bin/pip3.12 /usr/local/bin/pip
30+
31+
# Upgrade pip
32+
RUN pip3.12 install --upgrade pip
33+
34+
# Add your required files
35+
ADD packages/pyright-scip/sourcegraph-scip-python-0.6.0.tgz /
36+
37+
RUN npm --prefix /package install
38+
COPY index.py /
39+
40+
WORKDIR /projects/data
41+
42+
# Set entrypoint
43+
ENTRYPOINT ["python", "/index.py"]

Dockerfile.autoindex

Lines changed: 0 additions & 6 deletions
This file was deleted.

index-old.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import argparse
2+
import subprocess
3+
from pathlib import Path
4+
import tomllib # Use tomllib for Python 3.11+, or install toml for older versions
5+
6+
7+
def matches_pattern(package, patterns):
8+
"""Check if a package matches any of the specified patterns."""
9+
return any(pattern.lower() in package.lower() for pattern in patterns)
10+
11+
12+
def install_package(package_with_constraints):
13+
"""Attempt to install a package with constraints using pip."""
14+
print(f"Installing package: {package_with_constraints}")
15+
try:
16+
subprocess.run(["pip", "install", package_with_constraints], check=True)
17+
except subprocess.CalledProcessError:
18+
print(f"Failed to install {package_with_constraints}, continuing...")
19+
20+
21+
def extract_dependencies(data, patterns):
22+
"""Recursively search for dependencies in nested data structures."""
23+
if isinstance(data, list):
24+
for item in data:
25+
# Match package names in a list
26+
if isinstance(item, str):
27+
package_name = item.split(" ", 1)[0]
28+
if matches_pattern(package_name, patterns):
29+
yield item
30+
elif isinstance(data, dict):
31+
for key, value in data.items():
32+
# Recurse into dictionaries
33+
yield from extract_dependencies(value, patterns)
34+
35+
36+
def process_pyproject_file(pyproject_file, patterns):
37+
"""Process a pyproject.toml file and install matching packages."""
38+
print(f"Processing pyproject.toml: {pyproject_file}")
39+
with open(pyproject_file, "rb") as file:
40+
pyproject_data = tomllib.load(file)
41+
42+
# Extract all dependencies recursively
43+
for dependency in extract_dependencies(pyproject_data, patterns):
44+
install_package(dependency)
45+
46+
47+
def process_requirements_file(req_file, patterns):
48+
"""Process a requirements file and install matching packages."""
49+
print(f"Processing file: {req_file}")
50+
with open(req_file, "r") as file:
51+
for line in file:
52+
package = line.strip()
53+
# Ignore comments and empty lines
54+
if not package or package.startswith("#"):
55+
continue
56+
# Install only if package matches any of the patterns
57+
if matches_pattern(package, patterns):
58+
install_package(package)
59+
60+
61+
def main(index_name, patterns):
62+
"""Main function to process files and run SCIP indexing command."""
63+
# Process requirements-like files
64+
for req_file in Path(".").rglob("requirements*.txt"):
65+
process_requirements_file(req_file, patterns)
66+
67+
# Process pyproject.toml files
68+
for pyproject_file in Path(".").rglob("pyproject.toml"):
69+
process_pyproject_file(pyproject_file, patterns)
70+
71+
# Run the SCIP indexing command
72+
print("Running SCIP indexing command...")
73+
subprocess.run(["node", "/package/index.js", "index", ".",
74+
"--project-version=0.1.0", f"--output={index_name}"], check=True)
75+
76+
77+
if __name__ == "__main__":
78+
parser = argparse.ArgumentParser(description="Install specific packages from requirements and pyproject.toml files")
79+
parser.add_argument("index_name", help="The index name for SCIP indexing command")
80+
parser.add_argument("patterns", nargs="+", help="Patterns to match package names (e.g., 'flask')")
81+
args = parser.parse_args()
82+
83+
# Run main with index name and patterns
84+
main(args.index_name, args.patterns)

index.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import argparse
2+
import subprocess
3+
import os
4+
import venv
5+
from pathlib import Path
6+
import tomllib # Use tomllib for Python 3.11+, or install toml for older versions
7+
8+
9+
def matches_pattern(package, patterns):
10+
"""Check if a package matches any of the specified patterns."""
11+
return any(pattern.lower() in package.lower() for pattern in patterns)
12+
13+
14+
15+
def setup_virtual_environment(project_path):
16+
"""Create a virtual environment in the specified directory."""
17+
venv_path = project_path / '.venv'
18+
print(f"Creating virtual environment at: {venv_path}")
19+
venv.create(venv_path, with_pip=True)
20+
# subprocess.run([sys.executable, '-m', 'venv', str(venv_path)], check=True)
21+
return venv_path
22+
23+
def activate_virtual_environment(venv_path):
24+
"""Activate the virtual environment by adjusting the environment variables."""
25+
venv_bin = venv_path / 'bin'
26+
os.environ['VIRTUAL_ENV'] = str(venv_path)
27+
os.environ['PATH'] = f"{venv_bin}:{os.environ['PATH']}"
28+
print(f"Virtual environment activated: {os.environ['VIRTUAL_ENV']}")
29+
print(f"Updated PATH: {os.environ['PATH']}")
30+
return venv_bin / 'python'
31+
32+
def install_package(package_with_constraints, venv_python):
33+
"""Attempt to install a package with constraints using pip within the virtual environment."""
34+
print(f"Installing package: {package_with_constraints}")
35+
try:
36+
result = subprocess.run(
37+
[venv_python, "-m", "pip", "install", package_with_constraints],
38+
check=True,
39+
capture_output=True,
40+
text=True,
41+
)
42+
print(result.stdout)
43+
print(result.stderr)
44+
except subprocess.CalledProcessError as e:
45+
print(f"Failed to install {package_with_constraints}. Error: {e.stderr}")
46+
47+
48+
def extract_dependencies(data, patterns):
49+
"""Recursively search for dependencies in nested data structures."""
50+
if isinstance(data, list):
51+
for item in data:
52+
# Match package names in a list
53+
if isinstance(item, str):
54+
if matches_pattern(item, patterns):
55+
yield item
56+
elif isinstance(data, dict):
57+
for key, value in data.items():
58+
yield from extract_dependencies(key, patterns)
59+
# Recurse into dictionaries
60+
yield from extract_dependencies(value, patterns)
61+
elif isinstance(data, str):
62+
if matches_pattern(data, patterns):
63+
yield data
64+
65+
66+
def process_pyproject_file(pyproject_file, patterns, venv_python):
67+
"""Process a pyproject.toml file and install matching packages."""
68+
print(f"Processing pyproject.toml: {pyproject_file}")
69+
with open(pyproject_file, "rb") as file:
70+
pyproject_data = tomllib.load(file)
71+
72+
# Extract all dependencies recursively
73+
for dependency in extract_dependencies(pyproject_data, patterns):
74+
install_package(dependency, venv_python)
75+
76+
77+
def process_requirements_file(req_file, patterns, venv_python):
78+
"""Process a requirements file and install matching packages."""
79+
print(f"Processing file: {req_file}")
80+
with open(req_file, "r") as file:
81+
for line in file:
82+
package = line.strip()
83+
# Ignore comments and empty lines
84+
if not package or package.startswith("#"):
85+
continue
86+
# Install only if package matches any of the patterns
87+
if matches_pattern(package, patterns):
88+
install_package(package, venv_python)
89+
90+
91+
def process_project(path, patterns):
92+
"""Process the project: set up venv, install packages, and run Node.js script."""
93+
project_path = Path(path).resolve()
94+
venv_path = setup_virtual_environment(project_path)
95+
venv_python = activate_virtual_environment(venv_path)
96+
97+
# Copy the current environment and update it for the virtual environment
98+
env = os.environ.copy()
99+
100+
try:
101+
# Install a test package or requirement to verify pip functionality
102+
print("Verifying pip functionality in the virtual environment...")
103+
subprocess.run(
104+
[venv_python, "-m", "pip", "--version"],
105+
check=True,
106+
capture_output=True,
107+
env=env,
108+
)
109+
110+
# Process requirements-like files
111+
for req_file in Path(path).rglob("requirements*.txt"):
112+
process_requirements_file(req_file, patterns, venv_python)
113+
114+
# Process pyproject.toml files
115+
for pyproject_file in Path(path).rglob("pyproject.toml"):
116+
process_pyproject_file(pyproject_file, patterns, venv_python)
117+
118+
# Run the indexer
119+
print("Running SCIP indexing command...")
120+
result = subprocess.run(
121+
["node", "/package/index.js", "index", ".", "--project-version=0.1.0", "--output=python.scip"],
122+
cwd=path,
123+
env=env,
124+
check=True,
125+
capture_output=True,
126+
text=True,
127+
)
128+
print("Indexer output:")
129+
print(result.stdout)
130+
print(result.stderr)
131+
132+
except Exception as e:
133+
print(f"An error occurred: {e}")
134+
finally:
135+
print("Deactivating virtual environment.")
136+
os.environ.pop('VIRTUAL_ENV', None)
137+
os.environ['PATH'] = os.environ['PATH'].split(":", 1)[1]
138+
139+
140+
if __name__ == "__main__":
141+
parser = argparse.ArgumentParser(description="Install specific packages from requirements and pyproject.toml files")
142+
parser.add_argument("path", help="Relative path to project")
143+
parser.add_argument("patterns", nargs="+", help="Patterns to match package names (e.g., 'flask')")
144+
args = parser.parse_args()
145+
146+
# Run main with index name and patterns
147+
process_project(args.path, args.patterns)

index.scip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
C
3+
scip-python0.6.0)file:///Users/oinger/Projects/scip-python 

packages/pyright-internal/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pyright-internal/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "tsc",
1313
"clean": "shx rm -rf ./dist ./out",
1414
"test": "jest --forceExit",
15+
"typecheck": "tsc --noEmit",
1516
"test:coverage": "jest --forceExit --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html --coverageReporters=json"
1617
},
1718
"dependencies": {

packages/pyright-scip/LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Pyright - A static type checker for the Python language
4+
Copyright (c) Microsoft Corporation. All rights reserved.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE

0 commit comments

Comments
 (0)