Skip to content

Commit

Permalink
Pypi fix (#109)
Browse files Browse the repository at this point in the history
* Dependencies from git sources moved from `setup.py` to `requirements-dev.txt`.
- README.md updated.

* Package source added to requirement message helper function, so that packages available from git source can now be inherently added.

* CI updated with requirements-dev.txt.

* Pip installations orders changed.
- Typo fix in utils.py

* Package `click` is fixed at version 8.0.4.
  • Loading branch information
devrimcavusoglu authored Mar 28, 2022
1 parent d777e41 commit a88a198
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
- name: Install dependencies
run: >
pip install -e .[dev]
pip install -r requirements-dev.txt
- name: Lint with flake8 and black
run: |
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ or build from source,
cd jury
python setup.py install

**NOTE:** There may be malfunctions of some metrics depending on `sacrebleu` package on Windows machines which is
mainly due to the package `pywin32`. For this, we fixed pywin32 version on our setup config for Windows platforms.
However, if pywin32 causes trouble in your environment we strongly recommend using `conda` manager install the package
as `conda install pywin32`.

## <div align="center"> Usage </div>

### API Usage
Expand Down Expand Up @@ -227,6 +232,14 @@ PRs are welcomed as always :)
cd jury
pip install -e .[dev]

Also, you need to install the packages which are available through a git source separately with the following command.
For the folks who are curious about "why?"; a short explaination is that PYPI does not allow indexing a package which
are directly dependent on non-pypi packages due to security reasons. The file `requirements-dev.txt` includes packages
which are currently only available through a git source, or they are PYPI packages with no recent release or
incompatible with Jury, so that they are added as git sources or pointing to specific commits.

pip install -r requirements-dev.txt

### Tests

To tests simply run.
Expand Down
7 changes: 4 additions & 3 deletions jury/metrics/_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ def __init__(self, path: str, task: str):
super(TaskNotAvailable, self).__init__(message)


def requirement_message(path: str, package_name: str) -> str:
def requirement_message(path: str, package_name: str, package_source: str = None) -> str:
package_source = package_source or package_name
return (
f"In order to use metric '{path}', '{package_name}' is required. "
f"You can install the package by `pip install {package_name}`."
f"You can install the package by `pip install {package_source}`."
)


def download(source: str, destination: str, overwrite: bool = False, warn: bool = False) -> None:
if os.path.exists(destination) and not overwrite:
if warn:
warnings.warn(
f"Path {destination} already exists, not overwriting. To overwrite, speficy " f"'overwrite' parameter."
f"Path {destination} already exists, not overwriting. To overwrite, speficy 'overwrite' parameter."
)
return
r = requests.get(source, allow_redirects=True)
Expand Down
9 changes: 6 additions & 3 deletions jury/metrics/bleurt/bleurt_for_language_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import datasets

from jury.metrics import LanguageGenerationInstance, MetricForLanguageGeneration
from jury.metrics._core.utils import PackagePlaceholder
from jury.metrics._core.utils import PackagePlaceholder, requirement_message

# `import bleurt` placeholder
bleurt = PackagePlaceholder(version="1.2.2")
Expand Down Expand Up @@ -122,8 +122,11 @@ def _download_and_prepare(self, dl_manager):
from bleurt import score
except ModuleNotFoundError:
raise ModuleNotFoundError(
f"In order to use metric BLEURT, 'bleurt' is required. "
f"You can install the package by `bleurt @ pip install git+https://github.com/google-research/bleurt.git`."
requirement_message(
path="bleurt",
package_name="bleurt",
package_source="git+https://github.com/devrimcavusoglu/bleurt.git",
)
)

# check that config name specifies a valid BLEURT model
Expand Down
7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Jury metrics
# Falling back to fork for Windows related issue: https://github.com/google-research/bleurt/issues/49
bleurt @ git+https://github.com/devrimcavusoglu/bleurt.git
unbabel-comet @ git+https://github.com/Unbabel/COMET.git@c772b679e20725e6cc79b2107d50594f9ea7a4ae

# for datasets metric test
math_equivalence @ git+https://github.com/hendrycks/math.git
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
click==8.0.4
datasets>=2.0.0
fire>=0.4.0
nltk>=3.6.6,<3.7.1
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_version():
def add_pywin(reqs: List[str]) -> None:
if platform.system() == "Windows":
# Latest PyWin32 build (301) fails, required for sacrebleu
ext_package = ["pywin32==228"]
ext_package = ["pywin32==302"]
else:
ext_package = []
reqs.extend(ext_package)
Expand All @@ -42,20 +42,18 @@ def add_pywin(reqs: List[str]) -> None:
"pytest>=7.0.1",
"pytest-cov>=3.0.0",
"pytest-timeout>=2.1.0",
"math_equivalence @ git+https://github.com/hendrycks/math.git", # for datasets test metric
]

_PRISM_REQUIREMENTS = ["fairseq==0.9.0", "validators"]

_METRIC_REQUIREMENTS = [
"sacrebleu>=2.0.0",
"bert_score==0.3.11",
"bleurt @ git+https://github.com/google-research/bleurt.git",
"jiwer>=2.3.0",
"seqeval==1.2.2",
"sentencepiece==0.1.96",
"unbabel-comet @ git+https://github.com/Unbabel/COMET.git@c772b679e20725e6cc79b2107d50594f9ea7a4ae",
]

_METRIC_REQUIREMENTS.extend(_PRISM_REQUIREMENTS)
add_pywin(_METRIC_REQUIREMENTS)

Expand Down

0 comments on commit a88a198

Please sign in to comment.