Skip to content

Commit

Permalink
setup release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mohayemin committed Aug 3, 2024
1 parent ba1357f commit 80b77cb
Show file tree
Hide file tree
Showing 37 changed files with 175 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
secrets.json
dist/
*.egg-info/
.venv/
File renamed without changes.
22 changes: 22 additions & 0 deletions .idea/PyMigBench.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/.idea/modules.xml → .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/.idea/vcs.xml → .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude pymigbench_tests/*
exclude data/*
include version
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
PyMigBench is a benchmark of Python Library Migrations.
This repository contains the data and the code the library that can be used to access the dataset.

## The library
The library documentation can be found [here](/api).

## PyMigBench v2
## Dataset
### PyMigBench v2
The current version, PyMigBench-2.0, includes 3,096 migration-related code changes from 335 migrations between 141 analogous library pairs.
This includes all migrations from [PyMigBench v1](#pymigbench-v1) and additional migrations borrowed from the [SALM dataset](https://ieeexplore.ieee.org/document/10123560).
The data also includes additional information per migration-related code change compared to v1.
Expand All @@ -18,7 +16,7 @@ Use either of these links to reproduce the paper.
We may update this repository to correct any mistakes or add more data and it may not synch with the paper.
For, the latest data, use the [latest release](https://github.com/ualberta-smr/PyMigBench/releases/latest) in this repository.

## PyMigBench v1
### PyMigBench v1
We recommend using PyMigBench v2 for any new research.
However, you want to use the v1 dataset, you should look at [Release 1.0.3](https://github.com/ualberta-smr/PyMigBench/releases/v1.0.3).
Cite the paper below if you use the v1 dataset.
Expand All @@ -37,6 +35,50 @@ Cite the paper below if you use the v1 dataset.
```


## Library

### Installation
The library and the dataset should be at the same version to be compatible.
To install the library, run:
```bash
pip install pymigbench==<version>
```

### Basic usage
To use the library, you need to have the dataset downloaded.
You can download the dataset from the [GitHub repository](https://github.com/ualberta-smr/pymigbench).

```python
from pymigbench.database import Database
from pathlib import Path

yaml_root = Path('repo-root/migration/')

db = Database.load_from_dir(yaml_root) # Load the dataset from the directory
migs = db.migs() # Get all the migrations
```

### The constants
There are several enums to help you work with the dataset:
They are all in the `pymigbench.constants` module. Example:
```python
from pymigbench.constants import ProgramElement
```

### The migration-related objects
There are three main classes to encapsulate the data: `Migration`, `MigrationFile`, and `CodeChange`.

`Migration` is the top level class representing one single migration, ie, one yaml file.
`Migration` has a list of `MigrationFile` objects, which represent the files that were changed in the migration.
`MigrationFile` has a list of `CodeChange` objects, which represent a single migration-related code change.
Each of these model classes has an `id()` method that returns a unique identifier for the object across the full dataset.
`CodeChange` object additionally has an `index` property and a `id_in_file()` method, which are unique within container file.
Each of the classes has some additional helper methods.





## Contributors
- [Mohayeminul Islam](https://mohayemin.github.io/)
- [Ajay Kumar Jha](https://hifromajay.github.io/)
Expand Down
4 changes: 0 additions & 4 deletions api/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion api/.idea/.name

This file was deleted.

10 changes: 0 additions & 10 deletions api/.idea/misc.xml

This file was deleted.

11 changes: 0 additions & 11 deletions api/.idea/pymigbench.api.iml

This file was deleted.

3 changes: 0 additions & 3 deletions api/MANIFEST.in

This file was deleted.

44 changes: 0 additions & 44 deletions api/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions api/build.sh

This file was deleted.

1 change: 0 additions & 1 deletion api/publish.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
This file is not part of the library itself, rather is a script to build the library.
This should have minimal third-party dependencies so that it can be run in any environment.
Third-party dependencies that should be globally installed:
- requests
"""
import json
import shutil
import subprocess
import sys

import requests


class Release:
def __init__(self, non_interactive: bool):
self.non_interactive = non_interactive
self.version = open("./version").read().strip()
self.secrets = json.load(open("./secrets.json"))
self.pypi_release_url = f"https://pypi.org/project/pymigbench/{self.version}/"
self.github_repo = "ualberta-smr/pymigbench"
self.github_url = f"https://github.com/{self.github_repo}"

def validate(self):
gh_tag = f"v{self.version}"

try:
current_tag = run_command(["git", "describe", "--tags", "--exact-match"])
if current_tag.strip() != gh_tag:
raise ValueError(f"Current tag {current_tag} does not match the expected tag {gh_tag}.")
except Exception as e:
raise ValueError(f"Current head is not tagged with the expected version: {gh_tag}") from e

response = requests.head(self.pypi_release_url)
if response.status_code == 200:
raise ValueError(f"Version {self.version} already released on PyPI.")

print("Validated")
print(f" Version: {self.version}")
return self

def build(self):
print("Building...")
run_command(["python", "-m", "build"])
print("Built successfully.")
return self

def publish_pypi(self):
if self.non_interactive:
return self
if not self.non_interactive:
confirm = input("Do you want to publish to PyPI? Note that this is an irreversible process. (y/n): ")
if confirm.lower() != 'y':
print("Not publishing to PyPI.")
return self
print("Publishing to PyPI...")
run_command(["twine", "upload", "dist/*", "-u", "__token__", "-p", self.secrets['pypi']])
print("Published to PyPI.")
return self


def run_command(commands: list[any]):
process = subprocess.Popen(commands, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

lines = []
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
lines.append(output.strip())
print(output.strip())

return "\n".join(lines)


def main():
non_interactive = "--non-interactive" in sys.argv
Release(non_interactive).build().validate().publish_pypi()


if __name__ == "__main__":
main()
5 changes: 2 additions & 3 deletions api/setup.py → setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from setuptools import setup

version = open('./.publish/version').read().strip()
setup(
name='pymigbench',
description='APIs to access the PyMigBench dataset',
long_description=open('./README.md').read(),
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
version=version,
version="2.2.4",
packages=['pymigbench'],
author='PyMigBench Team',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.2.4

0 comments on commit 80b77cb

Please sign in to comment.