setup.py 2.61 KB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# === To install with setup.py
# git https://gitlab.irap.omp.eu/aklotz/guitastro.git
# cd guitastro
# python setup.py install
#
# === To check it is installed:
# Windows: pip freeze | findstr guitastro
# Linux: pip freeze | grep guitastro
#
# === To uninstall:
# pip uninstall guitastro
#
from setuptools import setup, find_packages
import os

__version__ = '0.1'
python_cmd='python'

def copy_file(file_in, file_out):
    # used by generate_requirements
    with open(file_in, 'r') as fid:
        lines = fid.readlines()
    with open(file_out, 'w') as fid:
        fid.writelines(lines)

def compile_requirements(python_cmd='python', requirement_in_file='requirements.in'):
    # used by generate_requirements
    os.system('python -m pip install --no-input pip-tools')
    import piptools
    #infile = os.path.join(os.getcwd(), requirement_in_file)
    command = f"{python_cmd} -m piptools compile {requirement_in_file}"
    print(f"compile_requirements: {command}")
    os.system(command)
    root, ext = os.path.splitext(requirement_in_file)
    requirement_file = root + ".txt"
    print(f"compile_requirements: {requirement_file} is generated.")
    return requirement_file
 
def read_requirements(requirement_file='requirements.txt'):
    # used by generate_requirements
    requirements = []
    with open(requirement_file, 'r') as fid:
        lines = fid.readlines()
    for line in lines:
        line = line.strip()
        if len(line) < 1:
            continue
        if line[0] == "#":
            continue
        requirements.append(line)
    return requirements

def generate_requirements(python_cmd='python', requirement_gen = 'requirements'):
    # copy .in from install
    requirement_in_file = requirement_gen + ".in"
    copy_file(os.path.join('install', requirement_in_file), requirement_in_file)
    # compile .in
    requirement_file = compile_requirements(python_cmd, requirement_in_file)
    # read .txt
    requirements = read_requirements(requirement_file)
    os.remove(requirement_in_file)
    return requirements

requirements = generate_requirements(python_cmd, 'requirements')

setup(
    name='guitastro',
    version=__version__,
    description='General Use of Instruments and Telescopes in ASTROnomy',
    author='Alain klotz',
    author_email='aklotz@irap.omp.eu',
    url='https://gitlab.irap.omp.eu/aklotz/guitastro.git',
    install_requires=requirements,
    package_dir = {'': 'src'},
    packages=['guitastro'],
    package_data={'guitastro':['tests/data/*']},
    include_package_data=True,
)