Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deps conversion #422

Merged
merged 7 commits into from
Nov 3, 2022
Merged
Changes from 3 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
30 changes: 18 additions & 12 deletions shub/deploy.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
from __future__ import absolute_import
import os

import glob
import json
import os
import shutil
import tempfile
import json
from six.moves.urllib.parse import urljoin
from typing import AnyStr, Optional, Union

import click
import toml
# Not used in code but needed in runtime, don't remove!
import setuptools
import setuptools.msvc # noqa
import toml
alexandresgf marked this conversation as resolved.
Show resolved Hide resolved
from six.moves.urllib.parse import urljoin

from shub.config import (list_targets_callback, load_shub_config,
SH_IMAGES_REGISTRY)
from shub.config import (SH_IMAGES_REGISTRY, list_targets_callback,
load_shub_config)
alexandresgf marked this conversation as resolved.
Show resolved Hide resolved
from shub.exceptions import (BadParameterException, NotFoundException,
ShubException)
from shub.image.upload import upload_cmd
from shub.utils import (create_default_setup_py, create_scrapinghub_yml_wizard,
inside_project, make_deploy_request, run_python)
from shub.image.upload import upload_cmd


HELP = """
Deploy the current folder's Scrapy project to Scrapy Cloud.
Expand Down Expand Up @@ -169,7 +170,8 @@ def _get_pipfile_requirements(tmpdir=None):
from pipenv.utils.indexes import prepare_pip_source_args
except ImportError:
try:
from pipenv.utils import convert_deps_to_pip, prepare_pip_source_args
from pipenv.utils import (convert_deps_to_pip,
prepare_pip_source_args)
alexandresgf marked this conversation as resolved.
Show resolved Hide resolved
except ImportError:
raise ImportError('You need pipenv installed to deploy with Pipfile')
try:
Expand All @@ -193,11 +195,15 @@ def _get_pipfile_requirements(tmpdir=None):
return open(_add_sources(convert_deps_to_pip(deps), _sources=sources.encode(), tmpdir=tmpdir), 'rb')


def _add_sources(_reqs_file, _sources, tmpdir=None):
def _add_sources(_requirements: Union[str, list], _sources: bytes, tmpdir: Optional[AnyStr] = None) -> str:
tmp = tempfile.NamedTemporaryFile(delete=False, suffix="-requirements.txt", dir=tmpdir)
tmp.write(_sources + b'\n')
with open(_reqs_file, 'rb') as f:
tmp.write(f.read())
# Keep backward compatibility with pipenv<=2022.8.30
if isinstance(_requirements, list):
tmp.write('\n'.join(_requirements).encode('utf-8'))
else:
with open(_requirements, 'rb') as f:
tmp.write(f.read())
tmp.flush()
tmp.close()
return tmp.name
Expand Down