-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from mtshiba/download-deps-v2
feat: auto-copy missing dependencies
- Loading branch information
Showing
7 changed files
with
137 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,2 @@ | ||
[build-system] | ||
requires = ["maturin>=0.12"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "pylyzer" | ||
description = "A fast static code analyzer & language server for Python" | ||
requires-python = ">=3.7" | ||
classifiers = [ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Rust", | ||
"Topic :: Software Development :: Quality Assurance", | ||
] | ||
requires = ["setuptools", "setuptools-rust", "wheel"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from pathlib import Path | ||
import os | ||
import shlex | ||
from glob import glob | ||
import tomllib | ||
import shutil | ||
|
||
from setuptools import setup, Command | ||
from setuptools_rust import RustBin | ||
|
||
class Clean(Command): | ||
user_options = [] | ||
def initialize_options(self): | ||
pass | ||
def finalize_options(self): | ||
pass | ||
def run(self): | ||
# super().run() | ||
for d in ["build", "dist", "src/pylyzer.egg-info"]: | ||
shutil.rmtree(d, ignore_errors=True) | ||
|
||
with open("README.md", encoding="utf-8", errors="ignore") as fp: | ||
long_description = fp.read() | ||
|
||
with open("Cargo.toml", "rb") as fp: | ||
toml = tomllib.load(fp) | ||
name = toml["package"]["name"] | ||
description = toml["package"]["description"] | ||
version = toml["workspace"]["package"]["version"] | ||
license = toml["workspace"]["package"]["license"] | ||
url = toml["workspace"]["package"]["repository"] | ||
|
||
cargo_args = ["--no-default-features"] | ||
|
||
home = os.path.expanduser("~") | ||
file_and_dirs = glob(".erg/lib/**", recursive=True, root_dir=home) | ||
paths = [Path(home + "/" + path) for path in file_and_dirs if os.path.isfile(home + "/" + path)] | ||
files = [(str(path).removesuffix("/" + path.name).removeprefix(home), str(path)) for path in paths] | ||
data_files = {} | ||
for key, value in files: | ||
if key in data_files: | ||
data_files[key].append(value) | ||
else: | ||
data_files[key] = [value] | ||
data_files = list(data_files.items()) | ||
|
||
setup( | ||
name=name, | ||
author="mtshiba", | ||
author_email="sbym1346@gmail.com", | ||
url=url, | ||
description=description, | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
version=version, | ||
license=license, | ||
python_requires=">=3", | ||
rust_extensions=[ | ||
RustBin("pylyzer", args=cargo_args, cargo_manifest_args=["--locked"]) | ||
], | ||
cmdclass={ | ||
"clean": Clean, | ||
}, | ||
classifiers=[ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Rust", | ||
"Topic :: Software Development :: Quality Assurance", | ||
], | ||
data_files=data_files, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::path::Path; | ||
use std::fs::{copy, read_dir, create_dir_all}; | ||
|
||
use erg_common::env::{erg_path, python_site_packages}; | ||
|
||
fn copy_dir(from: impl AsRef<Path>, to: impl AsRef<Path>) -> std::io::Result<()> { | ||
let from = from.as_ref(); | ||
let to = to.as_ref(); | ||
if !from.exists() { | ||
return Ok(()); | ||
} | ||
if !to.exists() { | ||
create_dir_all(to)?; | ||
} | ||
for entry in read_dir(from)? { | ||
let entry = entry?; | ||
if entry.file_type()?.is_dir() { | ||
copy_dir(entry.path(), to.join(entry.file_name()))?; | ||
} else { | ||
copy(entry.path(), to.join(entry.file_name()))?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[allow(unused)] | ||
pub(crate) fn copy_dot_erg() { | ||
if erg_path().exists() { | ||
return; | ||
} | ||
for site_packages in python_site_packages() { | ||
if site_packages.join(".erg").exists() { | ||
println!("Copying site-package/.erg to {}", erg_path().display()); | ||
copy_dir(site_packages.join(".erg"), erg_path()) | ||
.expect("Failed to copy .erg"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod analyze; | ||
mod config; | ||
mod handle_err; | ||
mod copy; | ||
|
||
pub use analyze::PythonAnalyzer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters