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

feat: auto-download missing dependencies #51

Closed
wants to merge 1 commit into from
Closed

Conversation

mtshiba
Copy link
Owner

@mtshiba mtshiba commented Sep 9, 2023

Fixes #50.

I don't like the idea, but I have made it so that pylyzer automatically downloads files from GitHub if it can't find the dependencies.

If some good alternative idea proves viable, I will close this PR.

@h5rdly
Copy link

h5rdly commented Sep 12, 2023

I've put this together from a few chatGPT queries -

from setuptools.command.sdist import sdist
from setuptools.command.install import install
import subprocess
import urllib.request

class CustomSDist(sdist):

    def run(self):
        # Download the script here before creating the source distribution
        self.download_script()
        sdist.run(self)

    def download_script(self):
        script_url = "https://github.com/username/repo/raw/main/script_to_download.py"  # Replace with the actual URL
        script_filename = "my_package/script_to_download.py"  # Relative path within your package

        try:
            # Download the script using urllib
            urllib.request.urlretrieve(script_url, script_filename)
        except Exception as e:
            print(f"Error downloading the script: {e}")


class CustomInstall(install):

    def run(self):
        install.run(self)
        subprocess.call(['python', 'script_to_download.py'])

setup(
    # ...
    cmdclass={'install': CustomInstall, 'sdist': CustomSDist},

This is an addition to setup.py. The script is downloaded when you call the sdist command, so that the user already has it inside the package when he runs pip install.

Perhaps this could assist with an alternative?

Cheers,
Eli

@mtshiba
Copy link
Owner Author

mtshiba commented Sep 12, 2023

Thanks for the suggestion. However, the problem was already solved in #53. I have incorporated the resource into the package, similar to your approach.

I forgot to close the PR, which caused some confusion. My apologies.

@mtshiba mtshiba closed this Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pip install pylyzer to install erg as well
2 participants