Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Install dependencies
run: |
pip install setuptools==69.5.1 wheel
pip install setuptools wheel
pip install -r requirements.txt

# Static analysis tools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regression-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Install dependencies
run: |
pip install setuptools==69.5.1 wheel
pip install setuptools wheel
pip install -r requirements.txt

- name: Run normal tests
Expand Down
14 changes: 7 additions & 7 deletions lean/commands/library/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ def _is_pypi_file_compatible(file: Dict[str, Any], required_python_version) -> b
:param required_python_version: the Python version to check compatibility for
:return: True if the file is compatible with the given Python version, False if not
"""
from pkg_resources import Requirement
from packaging.requirements import Requirement

major, minor, patch = required_python_version.version
major, minor = required_python_version.major, required_python_version.minor
if file["python_version"] not in [f"py{major}", f"py{major}{minor}", f"cp{major}", f"cp{major}{minor}", "source"]:
return False

if file["requires_python"] is not None:
requires_python = file["requires_python"].rstrip(",")
if str(required_python_version) not in Requirement.parse(f"python{requires_python}").specifier:
if str(required_python_version) not in Requirement(f"python{requires_python}").specifier:
return False

return True
Expand All @@ -135,7 +135,7 @@ def _get_pypi_package(name: str, version: Optional[str], python_version: str) ->
"""
from json import loads
from dateutil.parser import isoparse
from distutils.version import StrictVersion
from packaging.version import Version

response = container.http_client.get(f"https://pypi.org/pypi/{name}/json", raise_for_status=False)

Expand All @@ -148,7 +148,7 @@ def _get_pypi_package(name: str, version: Optional[str], python_version: str) ->
pypi_data = loads(response.text)
name = pypi_data["info"]["name"]

required_python_version = StrictVersion(python_version)
required_python_version = Version(python_version)

last_compatible_version = None
last_compatible_version_upload_time = None
Expand Down Expand Up @@ -187,7 +187,7 @@ def _add_python_package_to_requirements(requirements_file: Path, name: str, vers
:param name: the name of the package
:param version: the version of the package
"""
from pkg_resources import Requirement
from packaging.requirements import Requirement

if not requirements_file.is_file():
requirements_file.touch()
Expand All @@ -199,7 +199,7 @@ def _add_python_package_to_requirements(requirements_file: Path, name: str, vers

for line in requirements_lines:
try:
requirement = Requirement.parse(line)
requirement = Requirement(line)
if requirement.name.lower() == name.lower():
new_lines.append(f"{name}=={version}")
requirement_added = True
Expand Down
4 changes: 2 additions & 2 deletions lean/commands/library/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _remove_pypi_package_from_python_project(project_dir: Path, name: str) -> No
:param project_dir: the path to the project directory
:param name: the name of the library to remove
"""
from pkg_resources import Requirement
from packaging.requirements import Requirement

logger = container.logger
path_manager = container.path_manager
Expand All @@ -80,7 +80,7 @@ def _remove_pypi_package_from_python_project(project_dir: Path, name: str) -> No

for line in requirements_content.splitlines():
try:
requirement = Requirement.parse(line)
requirement = Requirement(line)
if requirement.name.lower() != name.lower():
new_lines.append(line)
except ValueError:
Expand Down
4 changes: 2 additions & 2 deletions lean/components/docker/lean_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,12 @@ def _concat_python_requirements(self, requirements_files: List[Path]) -> str:
:param requirements_files: the paths to the requirements.txt files
:return: the normalized requirements from all given requirements.txt files
"""
from pkg_resources import Requirement
from packaging.requirements import Requirement
requirements = []
for file in requirements_files:
for line in file.read_text(encoding="utf-8").splitlines():
try:
requirements.append(Requirement.parse(line))
requirements.append(Requirement(line))
except ValueError:
pass

Expand Down
4 changes: 2 additions & 2 deletions lean/components/util/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def generate_rider_config(self, project_dir: Path) -> bool:
:param project_dir: the directory of the project
:return: True if the configuration was generated successfully or changes where made, False if otherwise.
"""
from pkg_resources import resource_string
from importlib.resources import files

ssh_dir = Path("~/.lean/ssh").expanduser()

Expand All @@ -717,7 +717,7 @@ def generate_rider_config(self, project_dir: Path) -> bool:
file_name = ssh_dir / name
if not file_name.exists() or file_name.stat().st_size == 0:
with (ssh_dir / name).open("wb+") as file:
file.write(resource_string("lean", f"ssh/{name}"))
file.write((files("lean") / "ssh" / name).read_bytes())

made_changes = False
# Find Rider's global configuration directory for versions < 2022
Expand Down
4 changes: 2 additions & 2 deletions lean/components/util/update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def warn_if_cli_outdated(self, force: bool = False) -> None:
return

latest_version = response.json()["info"]["version"]
from distutils.version import StrictVersion
from packaging.version import Version

if StrictVersion(latest_version) > StrictVersion(current_version):
if Version(latest_version) > Version(current_version):
self._logger.warn(f"A new release of the Lean CLI is available ({current_version} -> {latest_version})")
self._logger.warn("Run `pip install --upgrade lean` to update to the latest version")

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file contains development dependencies
# Production dependencies are stored in setup.py

setuptools==69.5.1
setuptools
-e .

wheel
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_stubs_version_range() -> str:
"python-dateutil>=2.8.2",
"lxml>=4.9.0",
"joblib>=1.1.0",
"setuptools",
"packaging",
f"quantconnect-stubs{get_stubs_version_range()}",
"cryptography>=41.0.4",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def test_lean_shows_help_when_called_without_arguments() -> None:
result = CliRunner().invoke(lean, [])

assert result.exit_code == 0
assert "Usage: lean [OPTIONS] COMMAND [ARGS]..." in result.output
assert "Usage: lean [OPTIONS]" in result.output


def test_lean_shows_help_when_called_with_help_option() -> None:
result = CliRunner().invoke(lean, ["--help"])

assert result.exit_code == 0
assert "Usage: lean [OPTIONS] COMMAND [ARGS]..." in result.output
assert "Usage: lean [OPTIONS]" in result.output


def test_lean_shows_error_when_running_unknown_command() -> None:
Expand Down
Loading