Use flit to package instead of setuptools

This commit is contained in:
skullY
2019-06-30 20:03:14 -07:00
parent 5d809df80c
commit e1e1aaf041
8 changed files with 141 additions and 144 deletions
+33
View File
@@ -0,0 +1,33 @@
[build-system]
requires = ["flit"]
build-backend = "flit.buildapi"
[tool.flit.metadata]
dist-name = "qmk"
module = "qmk_cli"
author = "skullydazed"
author-email = "skullydazed@gmail.com"
home-page = "https://github.com/qmk/qmk_cli"
classifiers = [
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Scientific/Engineering',
'Topic :: Software Development',
'Topic :: Utilities',
]
requires-python = ">=3.5"
requires = [
#"milc", #FIXME(skullydazed): Included in the repo for now.
"argcomplete",
"colorama",
#"halo"
]
[tool.flit.scripts]
qmk = "qmk_cli.script_qmk:main"
+3 -96
View File
@@ -1,98 +1,5 @@
#!/usr/bin/env python3
"""CLI wrapper for running QMK commands.
This program can be run from anywhere, with or without a qmk_firmware checkout. It provides a small set of subcommands for working with QMK and otherwise dispatches to the `qmk_firmware/bin/qmk` script for the repo you are currently in, or your default repo if you are not currently in a qmk_firmware checkout.
"""Wrapper to call the qmk cli script entrypoint.
"""
import argparse
import os
import subprocess
import sys
from glob import glob
from time import strftime
from functools import lru_cache
from importlib import import_module
from importlib.util import find_spec
from pathlib import Path
@lru_cache(maxsize=2)
def in_qmk_firmware():
"""Returns the path to the qmk_firmware we are currently in, or None if we are not inside qmk_firmware.
"""
cur_dir = Path.cwd()
while len(cur_dir.parents) > 0:
found_bin = cur_dir / 'bin' / 'qmk'
if found_bin.is_file():
command = [found_bin, '--version']
result = subprocess.run(command)
if result.returncode == 0:
return cur_dir
# Move up a directory before the next iteration
cur_dir = cur_dir / '..'
cur_dir = cur_dir.resolve()
def find_qmk_firmware():
"""Look for qmk_firmware in the usual places.
This function returns the path to qmk_firmware, or the default location if one does not exist.
FIXME(skullydazed): add config file support
"""
if in_qmk_firmware():
return in_qmk_firmware()
if 'QMK_HOME' in os.environ:
return Path(os.environ['QMK_HOME'])
return Path.home() / 'qmk_firmware'
def parse_args():
"""Process arguments outside milc.
"""
parser = argparse.ArgumentParser(description='CLI wrapper for running QMK commands.')
parser.add_argument('-H', '--home', help='Path to the qmk_firmware directory.')
parser.add_argument('subcommand', help='Subcommand to run')
parser.add_argument('subcommand_args', nargs=argparse.REMAINDER, help='Arguments to pass to the subcommand.')
args = parser.parse_args()
if args.home:
os.environ['QMK_HOME'] = args.home
return (args.subcommand, args.subcommand_args)
def main():
subcommand, subcommand_args = parse_args()
subcommand_module = 'qmk_cli.' + subcommand
sys.argv = ['qmk-'+subcommand] + subcommand_args[1:]
qmk_firmware = find_qmk_firmware()
qmk_bin = qmk_firmware / 'bin' / 'qmk'
os.environ['QMK_HOME'] = str(qmk_firmware)
try:
# Attempt to import the subcommand from qmk_cli first
import milc
import_module(subcommand_module)
milc.cli()
except ModuleNotFoundError as e:
# Check to make sure there's not a bad import statement in qmk_cli
if e.name != subcommand_module:
raise
# Dispatch to the underlying `qmk_firmware/bin/qmk`
if qmk_bin.is_file() and os.access(str(qmk_bin), os.X_OK):
argv = ['python3', str(qmk_bin)] + subcommand_args
os.execvp('python3', argv)
# Tell the user we can't continue
print('*** Could not locate qmk_firmware directory!')
exit(255)
if __name__ == '__main__':
main()
import qmk_cli.script_qmk
qmk_cli.script_qmk.main()
+3
View File
@@ -0,0 +1,3 @@
"""A program to help you work with qmk_firmware."""
__version__ = '0.0.1'
+1 -1
View File
@@ -7,7 +7,7 @@ import platform
import os
from pathlib import Path
from milc import cli
from qmk_cli.milc import cli
def check_qmk_firmware():
View File
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""CLI wrapper for running QMK commands.
This program can be run from anywhere, with or without a qmk_firmware checkout. It provides a small set of subcommands for working with QMK and otherwise dispatches to the `qmk_firmware/bin/qmk` script for the repo you are currently in, or your default repo if you are not currently in a qmk_firmware checkout.
"""
import argparse
import os
import subprocess
import sys
from glob import glob
from time import strftime
from functools import lru_cache
from importlib import import_module
from importlib.util import find_spec
from pathlib import Path
@lru_cache(maxsize=2)
def in_qmk_firmware():
"""Returns the path to the qmk_firmware we are currently in, or None if we are not inside qmk_firmware.
"""
cur_dir = Path.cwd()
while len(cur_dir.parents) > 0:
found_bin = cur_dir / 'bin' / 'qmk'
if found_bin.is_file():
command = [found_bin, '--version']
result = subprocess.run(command)
if result.returncode == 0:
return cur_dir
# Move up a directory before the next iteration
cur_dir = cur_dir / '..'
cur_dir = cur_dir.resolve()
def find_qmk_firmware():
"""Look for qmk_firmware in the usual places.
This function returns the path to qmk_firmware, or the default location if one does not exist.
FIXME(skullydazed): add config file support
"""
if in_qmk_firmware():
return in_qmk_firmware()
if 'QMK_HOME' in os.environ:
return Path(os.environ['QMK_HOME'])
return Path.home() / 'qmk_firmware'
def parse_args():
"""Process arguments outside milc.
"""
parser = argparse.ArgumentParser(description='CLI wrapper for running QMK commands.')
parser.add_argument('-H', '--home', help='Path to the qmk_firmware directory.')
parser.add_argument('subcommand', help='Subcommand to run')
parser.add_argument('subcommand_args', nargs=argparse.REMAINDER, help='Arguments to pass to the subcommand.')
args = parser.parse_args()
if args.home:
os.environ['QMK_HOME'] = args.home
return (args.subcommand, args.subcommand_args)
def main():
subcommand, subcommand_args = parse_args()
subcommand_module = 'qmk_cli.' + subcommand
sys.argv = ['qmk-'+subcommand] + subcommand_args[1:]
qmk_firmware = find_qmk_firmware()
qmk_bin = qmk_firmware / 'bin' / 'qmk'
os.environ['QMK_HOME'] = str(qmk_firmware)
try:
# Attempt to import the subcommand from qmk_cli first
import qmk_cli.milc
import_module(subcommand_module)
qmk_cli.milc.cli()
except ModuleNotFoundError as e:
# Check to make sure there's not a bad import statement in qmk_cli
if e.name != subcommand_module:
raise
# Dispatch to the underlying `qmk_firmware/bin/qmk`
if qmk_bin.is_file() and os.access(str(qmk_bin), os.X_OK):
argv = ['python3', str(qmk_bin), subcommand] + subcommand_args
os.execvp('python3', argv)
# Tell the user we can't continue
print('*** Could not locate qmk_firmware directory!')
exit(255)
if __name__ == '__main__':
main()
+3 -4
View File
@@ -1,4 +1,3 @@
# milc FIXME(skullydazed): Included in the repo for now.
argcomplete
colorama
#halo
--index-url https://pypi.python.org/simple/
-e .
-43
View File
@@ -1,43 +0,0 @@
#!/usr/bin/env python
# Special thanks to Hynek Schlawack for providing excellent documentation:
#
# https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
import os
from setuptools import setup, find_packages, Command
def read(*paths):
"""Build a file path from *paths* and return the contents."""
with open(os.path.join(*paths), 'r') as f:
return f.read()
setup(
name='qmk',
version='0.0.1',
description='Program to help you work with qmk_firmware.',
long_description=read('README.md'),
long_description_content_type='text/markdown',
url='https://github.com/qmk/qmk_cli',
license='MIT License',
author='skullydazed',
author_email='skullydazed@gmail.com',
install_requires=['argcomplete', 'colorama'],
packages=find_packages(),
py_modules=['milc'],
scripts=['qmk'],
include_package_data=True,
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Scientific/Engineering',
'Topic :: Software Development',
'Topic :: Utilities',
],
)