Skip to content

Commit

Permalink
Merge branch 'dev' of git.nju.edu.cn:Stardust/aexpy into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Jan 29, 2024
2 parents efd2542 + 1614c0e commit a89e21b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ docker pull stardustdl/aexpy:main

## Usage

> All results produced by AexPy are in JSON format, so you could modify it in any text editor.
### Preprocess

Preprocess a distribution for a package release.
Expand All @@ -107,13 +109,17 @@ AexPy provide four preprocessing mode:
- `-d`, `--dist`: Automatically load from unpacked wheel, and its dist-info
- `-s`, `--src`: (default) Use given distribution information (path to code, package name, modules)

AexPy will automatically load package name, version, top-level modules, and dependencies from dist-info.

There are also options to specify fields in the distribution:

- `-p`, `--project`: Package name and its version, e.g. `project@version`.
- `-m`, `--module`: (multiple) Top-level module names.
- `-D`, `--depends`: (multiple) Package dependencies.
- `-R`, `--requirements`: Package `requirements.txt` file path, to load dependencies.

> You could also modify the generated distribution file in a text editor to change field values.
```sh
# download the package wheel and unpack into ./cache
# output the distribution file to ./cache/distribution.json
Expand All @@ -136,7 +142,8 @@ aexpy preprocess ./cache/generator_oj_problem-0.0.1-py3-none-any ./cache/distrib
Extract the API description from a distribution.

> AexPy would dynamically import the target module to detect all available APIs,
> so please ensure all dependencies have been installed in the current Python environment.
> so please ensure all dependencies have been installed in the current Python environment,
> or specify the `dependencies` field in the distribution, and AexPy will install them into current Python environment
```sh
aexpy extract ./cache/distribution.json ./cache/api.json
Expand All @@ -147,19 +154,25 @@ aexpy extract - ./cache/api.json
aexpy extract ./cache/distribution.json -
```

3. Diff two API descriptions and detect changes
### Diff

Diff two API descriptions and detect changes.

```sh
aexpy diff ./cache/api1.json ./cache/api2.json ./cache/diff.json
```

4. Generate report from detect changes
### Report

Generate report from detect changes.

```sh
aexpy report ./cache/diff.json ./cache/report.json
```

5. View produced data
### View

View produced data.

```sh
aexpy view ./cache/distribution1.json
Expand All @@ -170,12 +183,13 @@ aexpy view ./cache/diff.json
aexpy view ./cache/report.json
```

> The docker image keeps the same command-line interface,
> only need a volume mapping to `/data` for file access.
>
> ```sh
> docker run -v $pwd/cache:/data aexpy/aexpy extract /data/distribution.json /data/api.json
> ```
### Docker Image

The docker image keeps the same command-line interface, only need a volume mapping to `/data` for file access.

```sh
docker run -v $pwd/cache:/data aexpy/aexpy extract /data/distribution.json /data/api.json
```

## Advanced Tools

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ classifiers = [
]
requires-python = ">=3.12"
dependencies = [
"mypy==1.6.1",
"click==8.1.7",
"pydantic==2.5.3",
"mypy<=1.6.1",
"click>=8.0.0",
"pydantic>=2.0.2",
]

[project.urls]
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mypy==1.6.1
click==8.1.7
pydantic==2.5.3
mypy<=1.6.1
click>=8.0.0
pydantic>=2.0.2
3 changes: 2 additions & 1 deletion src/aexpy/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def overview(self):
📦 {self.wheelFile}
📁 {self.rootPath} ({self.fileCount} files, {self.fileSize} bytes, {self.locCount} LOC)
🔖 {self.pyversion}
📚 {', '.join(self.topModules)}"""
📚 {', '.join(self.topModules)}
🔩 {'\n '.join(self.dependencies)}"""
)

@override
Expand Down
5 changes: 5 additions & 0 deletions src/aexpy/preprocessing/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def name(self):
@property
def version(self):
return str(self.metadata.get("version"))

@property
def dependencies(self):
return [str(t) for t in self.metadata.get_all("requires-dist")]

@property
def pyversion(self) -> str | None:
Expand Down Expand Up @@ -165,6 +169,7 @@ def preprocess(self, product):
else:
product.release.version = distInfo.version
product.topModules.extend(distInfo.topLevel)
product.dependencies.extend(distInfo.dependencies)
if distInfo.metadata:
product.description = str(distInfo.metadata.get_payload())
product.metadata = [(x, str(y)) for x, y in distInfo.metadata.items()]

0 comments on commit a89e21b

Please sign in to comment.