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

Allow modules to stub themselves out #374

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

flying-sheep
Copy link
Contributor

I currently rely on a hack to enable flit to get the version of a module with no dependencies installed.

This patch would allow me to just use if not os.environ.get('FLIT_GETTING_VERSION'): ...

pkg/_metadata.py

import traceback
from get_version import get_version
__version__ = get_version(__file__.replace('_metadata', '__init__'))

def within_flit():
    import traceback
    for frame in traceback.extract_stack():
        if frame.name == 'get_docstring_and_version_via_import':
            return True
    return False

pkg/__init__.py:

"""Your package docstring"""
	   
from ._metadata import __version__, within_flit
	   
if not within_flit():
    from .subpackage import thing

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.

1 participant