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

Function/Gallery example for outputting the versions of packages and their dependencies #7324

Open
DanRyanIrish opened this issue Nov 29, 2023 · 3 comments
Labels
Discussion An issue opened for, or undergoing discussion. Effort Low Requires a small time investment Examples Affects the Example Gallery Package Novice Requires little knowledge of the internal structure of SunPy Priority Low Slow action required

Comments

@DanRyanIrish
Copy link
Member

Provide a general description of the issue or problem.

Reproducibility of science results depends, in part, on using the same versions of the software packages used in the original analysis. Does a function exist outside SunPy that can take a script or jupyter notebook and extract the packages used and their dependencies, and then priint out the versions of all of those packages?

While such a function may be beyond the scope of SunPy, a gallery example should be added showing how to use it, if it exists.

If it doesn't exist, perhaps we should create it.

@Lollyrana
Copy link

One such tool is pipreqs, which is commonly used to generate a requirements.txt file for a Python project. This file contains a list of all the packages used along with their versions.

Example: reproduce_info_extractor.py

import os
import subprocess

def extract_reproduce_info(script_path):
"""
Extracts package information and versions from a Python script or Jupyter notebook.

Parameters:
- script_path (str): Path to the Python script or Jupyter notebook.

Returns:
- None: Prints the package information to the console.
"""
try:
    # Generate requirements.txt using pipreqs
    subprocess.run(['pipreqs', script_path])

    # Read and print the content of requirements.txt
    requirements_file = os.path.join(os.path.dirname(script_path), 'requirements.txt')
    with open(requirements_file, 'r') as file:
        print(file.read())
    
    # Optionally, you may want to clean up the generated requirements.txt file
    # os.remove(requirements_file)

except Exception as e:
    print(f"Error: {e}")

Example usage

if name == "main":
script_path = "path/to/your/script_or_notebook.py"
extract_reproduce_info(script_path)

@Rjchauhan18
Copy link

Rjchauhan18 commented Mar 4, 2024

Hello @DanRyanIrish sir , if this issue is still open , so can i work on it ?

While such a function may be beyond the scope of SunPy, a gallery example should be added showing how to use it, if it exists.

for gallery example in how to use it in docs.

@nabobalis
Copy link
Contributor

Hello @DanRyanIrish sir , if this issue is still open , so can i work on it ?

You are free to work on this issue.

While such a function may be beyond the scope of SunPy, a gallery example should be added showing how to use it, if it exists.

for gallery example in how to use it in docs.

I am not sure I follow, a gallery example I think would be the place to start with this?

@nabobalis nabobalis added Examples Affects the Example Gallery Discussion An issue opened for, or undergoing discussion. Package Novice Requires little knowledge of the internal structure of SunPy Effort Low Requires a small time investment Priority Low Slow action required labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion An issue opened for, or undergoing discussion. Effort Low Requires a small time investment Examples Affects the Example Gallery Package Novice Requires little knowledge of the internal structure of SunPy Priority Low Slow action required
Projects
None yet
Development

No branches or pull requests

4 participants