Blame view

setup.py 2.6 KB
527116ca   Alain Klotz   first commit
1
2
3
4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# === To install with setup.py
ccef8678   Alain Klotz   first commit
5
6
# git https://gitlab.irap.omp.eu/aklotz/guitastro_device_deltatau.git
# cd guitastro_device_deltatau
527116ca   Alain Klotz   first commit
7
8
9
# python setup.py install
#
# === To check it is installed:
ccef8678   Alain Klotz   first commit
10
11
# Windows: pip freeze | findstr guitastro_device_deltatau
# Linux: pip freeze | grep guitastro_device_deltatau
527116ca   Alain Klotz   first commit
12
13
#
# === To uninstall:
ccef8678   Alain Klotz   first commit
14
# pip uninstall guitastro_device_deltatau
527116ca   Alain Klotz   first commit
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
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(
ccef8678   Alain Klotz   first commit
70
    name='guitastro_device_deltatau',
527116ca   Alain Klotz   first commit
71
    version=__version__,
ccef8678   Alain Klotz   first commit
72
    description='General Use of Instruments and Telescopes in ASTROnomy Device DeltaTau',
527116ca   Alain Klotz   first commit
73
74
    author='Alain klotz',
    author_email='aklotz@irap.omp.eu',
ccef8678   Alain Klotz   first commit
75
    url='https://gitlab.irap.omp.eu/aklotz/guitastro_device_deltatau.git',
527116ca   Alain Klotz   first commit
76
77
    install_requires=requirements,
    package_dir = {'': 'src'},
ccef8678   Alain Klotz   first commit
78
    packages=['guitastro_device_deltatau'],
527116ca   Alain Klotz   first commit
79
)