Skip to content

Commit 0bfbd44

Browse files
committed
restore original tests
1 parent ced9a2a commit 0bfbd44

File tree

4 files changed

+71
-76
lines changed

4 files changed

+71
-76
lines changed

MANIFEST.in

-13
This file was deleted.

README.md

-7
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,7 @@ In this example we use `gpt_detector` pipeline and set some hyperparameters. In
6767
In addtion, the `SigLLM` object takes in a `decimal` argument to determine how many digits from the float value include. Here, we don't want to keep any decimal values, so we set it to zero.
6868

6969
```python3
70-
import os
7170
from sigllm import SigLLM
72-
from mlblocks.discovery import get_pipelines_paths
73-
74-
for path in get_pipelines_paths():
75-
print(path)
76-
if os.path.isdir(path):
77-
print(os.listdir(path))
7871

7972
hyperparameters = {
8073
"orion.primitives.timeseries_anomalies.find_anomalies#1": {

pyproject.toml

+15-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,21 @@ include = ['sigllm', 'sigllm.*']
102102
namespaces = false
103103

104104
[tool.setuptools.package-data]
105-
"*" = ["*.*"]
105+
'*' = [
106+
'CONTRIBUTING.rst',
107+
'HISTORY.md',
108+
'README.md',
109+
'*.md',
110+
'*.rst',
111+
'*.json',
112+
'conf.py',
113+
'Makefile',
114+
'make.bat',
115+
'*.jpg',
116+
'*.png',
117+
'*.gif',
118+
]
119+
106120

107121
[tool.setuptools.exclude-package-data]
108122
'*' = [

tasks.py

+56-55
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,77 @@
11
import glob
2+
import operator
23
import os
4+
import pkg_resources
5+
import platform
6+
import re
37
import shutil
48
import stat
5-
import sys
69
from pathlib import Path
710

8-
import tomli
911
from invoke import task
10-
from packaging.requirements import Requirement
11-
from packaging.version import Version
1212

13-
from mlblocks.discovery import add_primitives_path, add_pipelines_path
1413

15-
def _get_minimum_versions(dependencies, python_version):
16-
min_versions = {}
17-
for dependency in dependencies:
18-
if '@' in dependency:
19-
name, url = dependency.split(' @ ')
20-
min_versions[name] = f'{url}#egg={name}'
21-
continue
14+
COMPARISONS = {
15+
'>=': operator.ge,
16+
'>': operator.gt,
17+
'<': operator.lt,
18+
'<=': operator.le
19+
}
2220

23-
req = Requirement(dependency)
24-
if ';' in dependency:
25-
marker = req.marker
26-
if marker and not marker.evaluate({'python_version': python_version}):
27-
continue # python version does not match
2821

29-
if req.name not in min_versions:
30-
min_version = next((spec.version for spec in req.specifier if spec.operator in ('>=', '==')), None)
31-
if min_version:
32-
min_versions[req.name] = f'{req.name}=={min_version}'
33-
34-
elif '@' not in min_versions[req.name]:
35-
existing_version = Version(min_versions[req.name].split('==')[1])
36-
new_version = next((spec.version for spec in req.specifier if spec.operator in ('>=', '==')), existing_version)
37-
if new_version > existing_version:
38-
min_versions[req.name] = f'{req.name}=={new_version}'
39-
40-
return list(min_versions.values())
22+
@task
23+
def check_dependencies(c):
24+
c.run('python -m pip check')
4125

4226

4327
@task
44-
def install_minimum(c):
45-
with open('pyproject.toml', 'rb') as pyproject_file:
46-
pyproject_data = tomli.load(pyproject_file)
28+
def unit(c):
29+
c.run('python -m pytest --cov=sigllm --cov-report=xml')
4730

48-
dependencies = pyproject_data.get('project', {}).get('dependencies', [])
49-
python_version = '.'.join(map(str, sys.version_info[:2]))
50-
minimum_versions = _get_minimum_versions(dependencies, python_version)
5131

52-
if minimum_versions:
53-
c.run(f'python -m pip install {" ".join(minimum_versions)}')
32+
def _validate_python_version(line):
33+
is_valid = True
34+
for python_version_match in re.finditer(r"python_version(<=?|>=?|==)\'(\d\.?)+\'", line):
35+
python_version = python_version_match.group(0)
36+
comparison = re.search(r'(>=?|<=?|==)', python_version).group(0)
37+
version_number = python_version.split(comparison)[-1].replace("'", "")
38+
comparison_function = COMPARISONS[comparison]
39+
is_valid = is_valid and comparison_function(
40+
pkg_resources.parse_version(platform.python_version()),
41+
pkg_resources.parse_version(version_number),
42+
)
5443

55-
56-
@task
57-
def check_dependencies(c):
58-
c.run('python -m pip check')
44+
return is_valid
5945

6046

6147
@task
62-
def unit(c):
63-
c.run('python -m pytest --cov=sigllm --cov-report=xml')
48+
def install_minimum(c):
49+
with open('setup.py', 'r') as setup_py:
50+
lines = setup_py.read().splitlines()
51+
52+
versions = []
53+
started = False
54+
for line in lines:
55+
if started:
56+
if line == ']':
57+
started = False
58+
continue
59+
60+
line = line.strip()
61+
if _validate_python_version(line):
62+
requirement = re.match(r'[^>]*', line).group(0)
63+
requirement = re.sub(r"""['",]""", '', requirement)
64+
version = re.search(r'>=?(\d\.?)+\w*', line).group(0)
65+
if version:
66+
version = re.sub(r'>=?', '==', version)
67+
version = re.sub(r"""['",]""", '', version)
68+
requirement += version
69+
versions.append(requirement)
70+
71+
elif (line.startswith('install_requires = [')):
72+
started = True
73+
74+
c.run(f'python -m pip install {" ".join(versions)}')
6475

6576

6677
@task
@@ -72,17 +83,14 @@ def minimum(c):
7283

7384
@task
7485
def readme(c):
75-
pipeline_path = 'sigllm/pipelines/detector/gpt_detector.json'
7686
test_path = Path('tests/readme_test')
7787
if test_path.exists() and test_path.is_dir():
7888
shutil.rmtree(test_path)
7989

8090
cwd = os.getcwd()
8191
os.makedirs(test_path, exist_ok=True)
82-
os.makedirs(test_path / 'mlpipelines', exist_ok=True)
8392
shutil.copy('README.md', test_path / 'README.md')
8493
shutil.copy('tutorials/data.csv', test_path / 'data.csv')
85-
shutil.copy(pipeline_path, test_path / 'mlpipelines' / 'gpt_detector.json')
8694
os.chdir(test_path)
8795
c.run('rundoc run --single-session python3 -t python3 README.md')
8896
os.chdir(cwd)
@@ -102,15 +110,8 @@ def tutorials(c):
102110
@task
103111
def lint(c):
104112
check_dependencies(c)
105-
c.run('ruff check .')
106-
c.run('ruff format --check --diff .')
107-
108-
109-
@task
110-
def fix_lint(c):
111-
check_dependencies(c)
112-
c.run('ruff check --fix .')
113-
c.run('ruff format .')
113+
c.run('flake8 sigllm tests')
114+
c.run('isort -c --recursive sigllm tests')
114115

115116

116117
def remove_readonly(func, path, _):

0 commit comments

Comments
 (0)