setup.py
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
70
71
72
73
74
75
76
77
78
79
80
81
#!/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,
)