# Path: plumbing/dependencies.py
# def check_setup_py(path_of_setup):
#     """
#     Parses the required modules from a `setup.py` file and checks they are
#     importable and have the minimum required version installed.
# 
#     Some ideas for extracting dependency information from a `setup.py` file:
#     https://stackoverflow.com/questions/24236266/
#     https://stackoverflow.com/questions/27790297/
# 
#     Another option is to try the `prasesetup` package, but it is buggy
#     and won't even install via pip:
#     https://github.com/benfred/parsesetup/issues/3
# 
#     Note: In this method, the code in the setup.py will be evaluated.
# 
#     Other interesting projects:
#     https://pypi.org/project/requirements-parser/
# 
#     Typically you can use this function like this:
# 
#         >>> from plumbing.dependencies import check_setup_py
#         >>> check_setup_py('~/module_name/setup.py')
#     """
#     # Import packages #
#     from unittest import mock
#     import setuptools
#     from runpy import run_path
#     # Parse it #
#     from autopaths.file_path import FilePath
#     path_of_setup = FilePath(path_of_setup)
#     # Run the setup in a mock #
#     with mock.patch.object(setuptools, 'setup') as mock_setup:
#         run_path(path_of_setup)
#     # Retrieve arguments that were used in the call #
#     args, kwargs = mock_setup.call_args
#     requires     = kwargs['install_requires']
#     # Parse each requirement separately #
#     requires = [re.split(r'==|>=', req) for req in requires]
#     requires = [req if len(req) == 2 else (req[0], None) for req in requires]
#     requires = dict(requires)
#     # Loop #
#     for package, version in requires.items(): check_module(package, version)


import os
from plumbing.dependencies import check_setup_py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Written by Lucas Sinclair.
MIT Licensed.
Contact at www.sinclair.bio

Development script to test some of the methods in `plumbing`
and try out different things. This script can safely be ignored
and is meant simply as a sandbox.

Typically you would run this file from a command line like this:

     ipython3 -i -- ~/deploy/plumbing/test/dev/tmp_code.py
"""

# Built-in modules #

# Internal modules #

# Third party modules #

###############################################################################
path = os.path.expanduser("~/deploy/pacmill/setup.py")

# Path: plumbing/dependencies.py
# def check_setup_py(path_of_setup):
#     """
#     Parses the required modules from a `setup.py` file and checks they are
#     importable and have the minimum required version installed.
# 
#     Some ideas for extracting dependency information from a `setup.py` file:
#     https://stackoverflow.com/questions/24236266/
#     https://stackoverflow.com/questions/27790297/
# 
#     Another option is to try the `prasesetup` package, but it is buggy
#     and won't even install via pip:
#     https://github.com/benfred/parsesetup/issues/3
# 
#     Note: In this method, the code in the setup.py will be evaluated.
# 
#     Other interesting projects:
#     https://pypi.org/project/requirements-parser/
# 
#     Typically you can use this function like this:
# 
#         >>> from plumbing.dependencies import check_setup_py
#         >>> check_setup_py('~/module_name/setup.py')
#     """
#     # Import packages #
#     from unittest import mock
#     import setuptools
#     from runpy import run_path
#     # Parse it #
#     from autopaths.file_path import FilePath
#     path_of_setup = FilePath(path_of_setup)
#     # Run the setup in a mock #
#     with mock.patch.object(setuptools, 'setup') as mock_setup:
#         run_path(path_of_setup)
#     # Retrieve arguments that were used in the call #
#     args, kwargs = mock_setup.call_args
#     requires     = kwargs['install_requires']
#     # Parse each requirement separately #
#     requires = [re.split(r'==|>=', req) for req in requires]
#     requires = [req if len(req) == 2 else (req[0], None) for req in requires]
#     requires = dict(requires)
#     # Loop #
#     for package, version in requires.items(): check_module(package, version)


# Path: testing/dev/tmp_code.py
import os
from plumbing.dependencies import check_setup_py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Written by Lucas Sinclair.
MIT Licensed.
Contact at www.sinclair.bio

Development script to test some of the methods in `plumbing`
and try out different things. This script can safely be ignored
and is meant simply as a sandbox.

Typically you would run this file from a command line like this:

     ipython3 -i -- ~/deploy/plumbing/test/dev/tmp_code.py
"""

# Built-in modules #

# Internal modules #

# Third party modules #

###############################################################################
path = os.path.expanduser("~/deploy/pacmill/setup.py")

check_setup_py(path)