-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathzato_environment.py
1328 lines (1009 loc) · 52.6 KB
/
zato_environment.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Copyright (C) 2024, Zato Source s.r.o. https://zato.io
Licensed under AGPLv3, see LICENSE.txt for terms and conditions.
"""
# stdlib
import glob
import logging
import os
import platform
import sys
from pathlib import Path
from subprocess import check_output, PIPE, Popen
from sys import version as py_version
# ################################################################################################################################
# ################################################################################################################################
if 0:
from zato.common.typing_ import any_, strlist, strnone # type: ignore
# ################################################################################################################################
# ################################################################################################################################
log_format = '%(asctime)s - %(levelname)s - %(name)s:%(lineno)d - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=log_format)
logger = logging.getLogger('zato')
# ################################################################################################################################
# ################################################################################################################################
platform_system = platform.system().lower()
is_windows = 'windows' in platform_system
is_linux = 'linux' in platform_system # noqa: E272
# ################################################################################################################################
# ################################################################################################################################
if '3.8' in py_version:
setuptools_version = '57.4.0'
else:
setuptools_version = '75.6.0'
pip_deps_windows = f'setuptools=={setuptools_version} wheel'
pip_deps_non_windows = f'setuptools=={setuptools_version} wheel pip'
pip_deps = pip_deps_windows if is_windows else pip_deps_non_windows
# ################################################################################################################################
# ################################################################################################################################
zato_command_template_linux = r"""
#!{bin_dir}/python
# To prevent an attribute error in pyreadline\py3k_compat.py
# AttributeError: module 'collections' has no attribute 'Callable'
try:
import collections
collections.Callable = collections.abc.Callable
except AttributeError:
pass
# Zato
from zato.cli.zato_command import main
if __name__ == '__main__':
# stdlib
import re
import sys
# This is needed by SUSE
sys.path.append(r'{base_dir}/lib64/python3.6/site-packages/')
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
""".strip() # noqa: W605
zato_command_template_windows = r"""
@echo off
"{bundled_python_dir}\python.exe" "\\?\{code_dir}\\zato-cli\\src\\zato\\cli\\_run_zato.py" %*
""".strip() # noqa: W605
# ################################################################################################################################
# ################################################################################################################################
class EnvironmentManager:
def __init__(self, base_dir:'str', bin_dir:'str') -> 'None':
self.base_dir = base_dir
self.bin_dir = bin_dir
self.pip_options = ''
self.eggs_dir = 'invalid-self.eggs_dir'
self.bundle_ext_dir = 'invalid-bundle_ext_dir'
self.site_packages_dir = 'invalid-site_packages_dir'
self.pip_pyz_path = 'invalid-pip_pyz_path'
self.python_command = 'invalid-python_command'
self.pip_command = 'invalid-pip_command'
self.bundled_python_dir = 'invalid-bundled_python_dir'
self.zato_reqs_path = 'invalid-zato_reqs_path'
self.code_dir = 'invalid-code_dir'
self._set_up_pip_flags()
self._set_up_dir_and_attr_names()
# ################################################################################################################################
def _get_linux_distro_name(self) -> 'str':
# Short-cut for non-Linux systems
if not is_linux:
return ''
# If we are here, it means that we are under a Linux distribution and we assume
# that the file exists per https://www.freedesktop.org/software/systemd/man/os-release.html
# By default, we do not have it
distro_name = ''
data = open('/etc/os-release').read()
data = data.splitlines()
for line in data:
if line.startswith('PRETTY_NAME'):
line = line.split('=')
distro_name = line[1]
distro_name = distro_name.replace('"', '')
distro_name = distro_name.lower()
break
logger.info('Linux distribution found -> `%s`', distro_name)
return distro_name
# ################################################################################################################################
def _set_up_pip_flags(self) -> 'None':
#
# Under RHEL, pip install may not have the '--no-warn-script-location' flag.
# At the same time, under RHEL, we need to use --no-cache-dir.
#
linux_distro = self._get_linux_distro_name()
is_rhel = 'red hat' in linux_distro or 'centos' in linux_distro
# Explicitly ignore the non-existing option and add a different one..
if is_rhel:
self.pip_options = '--no-cache-dir'
# .. or make use of it.
else:
self.pip_options = '--no-warn-script-location'
# ################################################################################################################################
def _set_up_dir_and_attr_names(self) -> 'None':
# This needs to be checked in runtime because we do not know
# under what Python version we are are going to run.
py_version = '{}.{}'.format(sys.version_info.major, sys.version_info.minor)
logger.info('Python version maj.min -> %s', py_version)
logger.info('Python self.base_dir -> %s', self.base_dir)
self.bundle_ext_dir = os.path.join(self.base_dir, '..')
self.bundle_ext_dir = os.path.abspath(self.bundle_ext_dir)
logger.info('Bundle ext. dir -> %s', self.bundle_ext_dir)
# This will exist only under Windows
if is_windows:
# Dynamically check what our current embedded Python's directory is ..
self.bundled_python_dir = self.get_bundled_python_version(self.bundle_ext_dir, 'windows')
# Under Linux, the path to site-packages contains the Python version but it does not under Windows.
# E.g. ~/src-zato/lib/python3.8/site-packages vs. C:\src-zato\lib\site-packages
if is_linux:
python_version_dir = 'python' + py_version
py_lib_dir = os.path.join('lib', python_version_dir)
else:
py_lib_dir = os.path.join(self.bundled_python_dir, 'lib')
py_lib_dir = os.path.abspath(py_lib_dir)
logger.info('Python lib dir -> %s', py_lib_dir)
self.site_packages_dir = os.path.join(py_lib_dir, 'site-packages')
self.site_packages_dir = os.path.abspath(self.site_packages_dir)
logger.info('Python site-packages dir -> %s', self.site_packages_dir)
self.eggs_dir = os.path.join(self.base_dir, 'eggs')
self.eggs_dir = os.path.abspath(self.eggs_dir)
logger.info('Python eggs dir -> %s', self.eggs_dir)
if is_windows:
# This is always in the same location
self.pip_pyz_path = os.path.join(self.bundle_ext_dir, 'pip', 'pip.pyz')
# .. and build the full Python command now.
self.python_command = os.path.join(self.bundled_python_dir, 'python.exe')
# We are now ready to build the full pip command ..
self.pip_command = f'{self.python_command} {self.pip_pyz_path}'
# .. and the install prefix as well.
self.pip_install_prefix = f'--prefix {self.bundled_python_dir}'
# Where we keep our own requirements
self.zato_reqs_path = os.path.join(self.base_dir, '..', '..', 'requirements.txt')
self.zato_reqs_path = os.path.abspath(self.zato_reqs_path)
# Where the zato-* packages are (the "code" directory)
self.code_dir = os.path.join(self.bundle_ext_dir, '..')
self.code_dir = os.path.abspath(self.code_dir)
else:
# These are always in the same location
self.pip_command = os.path.join(self.bin_dir, 'pip')
self.python_command = os.path.join(self.bin_dir, 'python')
self.code_dir = self.base_dir
self.zato_reqs_path = os.path.join(self.base_dir, 'requirements.txt')
# This is not used under Linux
self.pip_install_prefix = ''
# ################################################################################################################################
def get_bundled_python_version(self, bundle_ext_dir:'str', os_type:'str') -> 'str':
python_parent_dir = f'python-{os_type}'
python_parent_dir = os.path.join(bundle_ext_dir, python_parent_dir)
# We want to ignore any names other than ones matching this pattern
pattern = os.path.join(python_parent_dir, 'python-*')
results = []
for item in glob.glob(pattern):
results.append(item)
if not results:
raise Exception(f'No bundled Python version found matching pattern: `{pattern}`')
if len(results) > 1:
raise Exception(f'Too many results found matching pattern: `{pattern}` -> `{results}`')
# If we are here, it means that we have exactly one result that we can return to our caller
result = results[0]
return result
# ################################################################################################################################
def _create_symlink(self, from_:'str', to:'str') -> 'None':
try:
os.symlink(from_, to)
except FileExistsError:
# It is not an issue if it exists, likely install.sh/.bat ran twice.
pass
else:
logger.info('Symlinked from `%s` to `%s`', from_, to)
# ################################################################################################################################
def _create_executable(self, path:'str', data:'str') -> 'None':
f = open(path, 'w')
_ = f.write(data)
f.close()
logger.info('Created file `%s`', path)
# .. and make it executable.
os.chmod(path, 0o740)
logger.info('Made file executable `%s`', path)
# ################################################################################################################################
def run_command(
self,
command:'str',
exit_on_error:'bool'=True,
needs_stdout:'bool'=False,
needs_stderr:'bool'=False,
log_stderr:'bool'=True,
use_check_output:'bool'=False
) -> 'str | None':
logger.info('Running `%s`', command)
# Turn what is possibly a multi-line command into a list of arguments ..
command = command.strip()
command_split = command.split()
func = self._run_check_output if use_check_output else self._run_popen
return func(command_split, exit_on_error, needs_stdout, needs_stderr, log_stderr)
# ################################################################################################################################
def _run_check_output(
self,
command:'strlist',
exit_on_error:'bool'=True,
needs_stdout:'bool'=False,
needs_stderr:'bool'=False,
log_stderr:'bool'=True
) -> 'any_':
# This will be potentially returned to our caller
stdout = b''
# Run the command ..
try:
stdout = check_output(command) # type: bytes
except Exception as e:
stderr = e.args
if log_stderr:
logger.warning(stderr)
if exit_on_error:
sys.exit(1)
else:
if needs_stderr:
return stderr
else:
if needs_stdout:
return stdout.decode('utf8')
# ################################################################################################################################
def _run_popen(
self,
command:'str | strlist',
exit_on_error:'bool'=True,
needs_stdout:'bool'=False,
needs_stderr:'bool'=False,
log_stderr:'bool'=True
) -> 'strnone':
# This will be potentially returned to our caller
stdout = None
# Run the command ..
process = Popen(command, stderr=PIPE, stdout=PIPE if needs_stdout else None)
# .. and wait until it completes.
while True:
stderr = process.stderr.readline() # type: ignore
if needs_stdout:
stdout = process.stdout.readline() # type: ignore
stdout = stdout.strip()
stdout = stdout.decode('utf8')
if stderr:
stderr = stderr.strip()
stderr = stderr.decode('utf8')
if log_stderr:
logger.warning(stderr)
if exit_on_error:
process.kill()
sys.exit(1)
else:
if needs_stderr:
return stderr
if process.poll() is not None:
break
if needs_stdout:
return stdout
# ################################################################################################################################
def pip_install_core_pip(self) -> 'None':
# Set up the command ..
command = '{pip_command} install {pip_install_prefix} {pip_options} -U {pip_deps}'.format(**{
'pip_command': self.pip_command,
'pip_install_prefix': self.pip_install_prefix,
'pip_options': self.pip_options,
'pip_deps': pip_deps,
})
# .. and run it.
_ = self.run_command(command, exit_on_error=True)
# ################################################################################################################################
def pip_install_requirements_by_path(self, reqs_path:'str', exit_on_error:'bool'=False) -> 'None':
if not os.path.exists(reqs_path):
logger.info('Skipped user-defined requirements.txt. No such path `%s`.', reqs_path)
return
# Set up the command ..
command = """
{pip_command}
-v
install
{pip_install_prefix}
{pip_options}
-r {reqs_path}
""".format(**{
'pip_command': self.pip_command,
'pip_install_prefix': self.pip_install_prefix,
'pip_options': self.pip_options,
'reqs_path': reqs_path
})
# .. and run it.
_ = self.run_command(command, exit_on_error=exit_on_error)
# ################################################################################################################################
def pip_install_zato_requirements(self) -> 'None':
# Install our own requirements
self.pip_install_requirements_by_path(self.zato_reqs_path, exit_on_error=False)
# ################################################################################################################################
def run_pip_install_zato_packages(self, packages:'strlist', allow_editable:'bool'=True) -> 'None':
# All the -e arguments that pip will receive
pip_args = []
# This is used everywhere except with Cython
if allow_editable:
pip_args.append('--use-pep517')
# Build the arguments
for name in packages:
package_path = os.path.join(self.code_dir, name)
arg = '-e {}'.format(package_path)
pip_args.append(arg)
# Build the command ..
command = '{pip_command} install {pip_install_prefix} --no-warn-script-location {pip_args}'.format(**{
'pip_command': self.pip_command,
'pip_install_prefix': self.pip_install_prefix,
'pip_args': ' '.join(pip_args)
})
# .. and run it.
_ = self.run_command(command, exit_on_error=False)
# ################################################################################################################################
def pip_install_standalone_requirements(self) -> 'None':
# These cannot be installed via requirements.txt
packages = [
'cython==3.1.0a1',
'pyOpenSSL==23.0.0',
'zato-ext-bunch==1.2',
]
# This needs to be installed here rather than via requirements.txt
if not is_windows:
packages.append('posix-ipc==1.0.0')
for package in packages:
# Set up the command ..
command = '{pip_command} install {pip_install_prefix} --no-warn-script-location {package}'.format(**{
'pip_command': self.pip_command,
'pip_install_prefix': self.pip_install_prefix,
'package': package,
})
# .. and run it.
_ = self.run_command(command, exit_on_error=True)
# ################################################################################################################################
def pip_install_zato_packages(self) -> 'None':
# Note that zato-common must come first.
editable_packages = [
'zato-common',
'zato-agent',
'zato-broker',
'zato-cli',
'zato-client',
'zato-distlock',
'zato-hl7',
'zato-lib',
'zato-scheduler',
'zato-server',
'zato-web-admin',
'zato-zmq',
'zato-sso',
'zato-testing',
]
non_editable_packages = [
'zato-cy'
]
self.run_pip_install_zato_packages(editable_packages)
self.run_pip_install_zato_packages(non_editable_packages, allow_editable=False)
# ################################################################################################################################
def pip_uninstall(self) -> 'None':
# Packages that will be uninstalled, e.g. no longer needed
packages = [
'imbox',
'pycrypto',
'python-keyczar',
]
# Build the command ..
command = '{} uninstall -y -qq {}'.format(self.pip_command, ' '.join(packages))
# .. and run it.
_ = self.run_command(command, exit_on_error=False)
# ################################################################################################################################
def pip_install(self) -> 'None':
self.pip_install_core_pip()
self.pip_install_standalone_requirements()
self.pip_install_zato_requirements()
self.pip_install_zato_packages()
self.pip_uninstall()
# ################################################################################################################################
def update_git_revision(self) -> 'None':
# This is where we will store our last git commit ID
revision_file_path = os.path.join(self.base_dir, 'release-info', 'revision.txt')
# Make sure the underlying git command runs in our git repository ..
os.chdir(self.base_dir)
# Build the command ..
command = 'git log -n 1 --pretty=format:%H --no-color'
# .. run the command to get our latest commit ID ..
commit_id = self.run_command(command, needs_stdout=True, use_check_output=True)
# .. and store it in an external file for 'zato --version' and other tools to use.
f = open(revision_file_path, 'w')
f.write(commit_id) # type: ignore
f.close()
logger.info('Git commit ID -> `%s`', commit_id)
# ################################################################################################################################
def add_eggs_symlink(self) -> 'None':
if not is_windows:
self._create_symlink(self.site_packages_dir, self.eggs_dir)
# ################################################################################################################################
def add_extlib_to_sys_path(self, extlib_dir:'Path') -> 'None':
# This file contains entries that, in runtime, will be found in sys.path
easy_install_path = os.path.join(self.site_packages_dir, 'easy-install.pth')
# .. add the path to easy_install ..
f = open(easy_install_path, 'a')
_ = f.write(extlib_dir.as_posix())
_ = f.write(os.linesep)
f.close()
# ################################################################################################################################
def add_extlib(self) -> 'None':
# This is where external depdendencies can be kept
extlib_dir_path = os.path.join(self.base_dir, 'extlib')
# For backward compatibility, this will point to extlib
extra_paths_dir = os.path.join(self.base_dir, 'zato_extra_paths')
# Build a Path object ..
extlib_dir = Path(extlib_dir_path)
# .. create the underlying directory ..
extlib_dir.mkdir(exist_ok=True)
# .. add the path to easy_install ..
self.add_extlib_to_sys_path(extlib_dir)
# .. and symlink it for backward compatibility.
if not is_windows:
self._create_symlink(extlib_dir_path, extra_paths_dir)
# ################################################################################################################################
def add_py_command(self) -> 'None':
# This is where will will save it
command_name = 'py.bat' if is_windows else 'py'
py_command_path = os.path.join(self.bin_dir, command_name)
# There will be two versions, one for Windows and one for other systems
#
# Windows
#
if is_windows:
template = ''
template += '"{}" %*'
# Non-Windows
else:
template = ''
template += '#!/bin/sh'
template += '\n'
template += '"{}" "$@"'
# Add the full path to the OS-specific template ..
data = template.format(self.python_command)
# .. and add the file to the system.
self._create_executable(py_command_path, data)
# ################################################################################################################################
def add_zato_command(self) -> 'None':
# Differentiate between Windows and other systems as the extension is needed under the former
command_name = 'zato.bat' if is_windows else 'zato'
if is_windows:
command_name = 'zato.bat'
template = zato_command_template_windows
template_kwargs = {
'code_dir': self.code_dir,
'bundled_python_dir': self.bundled_python_dir,
}
else:
command_name = 'zato'
template = zato_command_template_linux
template_kwargs = {
'base_dir': self.base_dir,
'bin_dir': self.bin_dir,
}
# This is where the command file will be created
command_path = os.path.join(self.bin_dir, command_name)
# Build the full contents of the command file ..
data = template.format(**template_kwargs)
# .. and add the file to the file system.
self._create_executable(command_path, data)
# ################################################################################################################################
def copy_patches(self) -> 'None':
# Where our patches can be found
patches_dir = os.path.join(self.code_dir, 'patches')
# Where to copy them to
dest_dir = self.site_packages_dir
logger.info('Copying patches from %s -> %s', patches_dir, dest_dir)
# Recursively copy all the patches, overwriting any files found
_ = copy_tree(patches_dir, dest_dir, preserve_symlinks=True, verbose=1)
logger.info('Copied patches from %s -> %s', patches_dir, dest_dir)
# ################################################################################################################################
def install(self) -> 'None':
# self.update_git_revision()
self.pip_install()
self.add_eggs_symlink()
self.add_extlib()
self.add_py_command()
self.add_zato_command()
self.copy_patches()
# ################################################################################################################################
def update(self) -> 'None':
self.update_git_revision()
self.pip_install()
self.copy_patches()
# ################################################################################################################################
def runtime_setup_with_env_variables(self) -> 'None':
# In this step, we need to look up any possible custom pip requirements
# that we already know that are defined through environment variables.
python_reqs = os.environ.get('ZATO_PYTHON_REQS', '')
# OK, we have some requirements files to install packages from ..
if python_reqs:
# .. support multiple files on input ..
python_reqs = python_reqs.split(':')
# .. and install them now.
for path in python_reqs:
self.pip_install_requirements_by_path(path)
# This step is similar but instead of installing dependencies from pip requirements,
# we add to sys.path entire directories where runtime user code can be found.
extlib_dir = os.environ.get('ZATO_EXTLIB_DIR', '')
# OK, we have some requirements files to install packages from ..
if extlib_dir:
# .. support multiple files on input ..
extlib_dir = extlib_dir.split(':')
# .. and install them now.
for path in extlib_dir:
self.add_extlib_to_sys_path(Path(path))
# ################################################################################################################################
# ################################################################################################################################
# The code below is copied from Python 3.10 under the Python Software License.
"""
A. HISTORY OF THE SOFTWARE
==========================
Python was created in the early 1990s by Guido van Rossum at Stichting
Mathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands
as a successor of a language called ABC. Guido remains Python's
principal author, although it includes many contributions from others.
In 1995, Guido continued his work on Python at the Corporation for
National Research Initiatives (CNRI, see https://www.cnri.reston.va.us)
in Reston, Virginia where he released several versions of the
software.
In May 2000, Guido and the Python core development team moved to
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
year, the PythonLabs team moved to Digital Creations, which became
Zope Corporation. In 2001, the Python Software Foundation (PSF, see
https://www.python.org/psf/) was formed, a non-profit organization
created specifically to own Python-related Intellectual Property.
Zope Corporation was a sponsoring member of the PSF.
All Python releases are Open Source (see https://opensource.org for
the Open Source Definition). Historically, most, but not all, Python
releases have also been GPL-compatible; the table below summarizes
the various releases.
Release Derived Year Owner GPL-
from compatible? (1)
0.9.0 thru 1.2 1991-1995 CWI yes
1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
1.6 1.5.2 2000 CNRI no
2.0 1.6 2000 BeOpen.com no
1.6.1 1.6 2001 CNRI yes (2)
2.1 2.0+1.6.1 2001 PSF no
2.0.1 2.0+1.6.1 2001 PSF yes
2.1.1 2.1+2.0.1 2001 PSF yes
2.1.2 2.1.1 2002 PSF yes
2.1.3 2.1.2 2002 PSF yes
2.2 and above 2.1.1 2001-now PSF yes
Footnotes:
(1) GPL-compatible doesn't mean that we're distributing Python under
the GPL. All Python licenses, unlike the GPL, let you distribute
a modified version without making your changes open source. The
GPL-compatible licenses make it possible to combine Python with
other software that is released under the GPL; the others don't.
(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
because its license has a choice of law clause. According to
CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
is "not incompatible" with the GPL.
Thanks to the many outside volunteers who have worked under Guido's
direction to make these releases possible.
B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
===============================================================
Python software and documentation are licensed under the
Python Software Foundation License Version 2.
Starting with Python 3.8.6, examples, recipes, and other code in
the documentation are dual licensed under the PSF License Version 2
and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses.
The licenses are listed with code falling under that license.
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
--------------------------------------------
1. This LICENSE AGREEMENT is between the Python Software Foundation
("PSF"), and the Individual or Organization ("Licensee") accessing and
otherwise using this software ("Python") in source or binary form and
its associated documentation.
2. Subject to the terms and conditions of this License Agreement, PSF hereby
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
analyze, test, perform and/or display publicly, prepare derivative works,
distribute, and otherwise use Python alone or in any derivative version,
provided, however, that PSF's License Agreement and PSF's notice of copyright,
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
All Rights Reserved" are retained in Python alone or in any derivative version
prepared by Licensee.
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python.
4. PSF is making Python available to Licensee on an "AS IS"
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between PSF and
Licensee. This License Agreement does not grant permission to use PSF
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.
8. By copying, installing or otherwise using Python, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
-------------------------------------------
BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
Individual or Organization ("Licensee") accessing and otherwise using
this software in source or binary form and its associated
documentation ("the Software").
2. Subject to the terms and conditions of this BeOpen Python License
Agreement, BeOpen hereby grants Licensee a non-exclusive,
royalty-free, world-wide license to reproduce, analyze, test, perform
and/or display publicly, prepare derivative works, distribute, and
otherwise use the Software alone or in any derivative version,
provided, however, that the BeOpen Python License is retained in the
Software, alone or in any derivative version prepared by Licensee.
3. BeOpen is making the Software available to Licensee on an "AS IS"
basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
5. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
6. This License Agreement shall be governed by and interpreted in all
respects by the law of the State of California, excluding conflict of
law provisions. Nothing in this License Agreement shall be deemed to
create any relationship of agency, partnership, or joint venture
between BeOpen and Licensee. This License Agreement does not grant
permission to use BeOpen trademarks or trade names in a trademark
sense to endorse or promote products or services of Licensee, or any
third party. As an exception, the "BeOpen Python" logos available at
http://www.pythonlabs.com/logos.html may be used according to the
permissions granted on that web page.
7. By copying, installing or otherwise using the software, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
---------------------------------------
1. This LICENSE AGREEMENT is between the Corporation for National
Research Initiatives, having an office at 1895 Preston White Drive,
Reston, VA 20191 ("CNRI"), and the Individual or Organization
("Licensee") accessing and otherwise using Python 1.6.1 software in
source or binary form and its associated documentation.
2. Subject to the terms and conditions of this License Agreement, CNRI
hereby grants Licensee a nonexclusive, royalty-free, world-wide
license to reproduce, analyze, test, perform and/or display publicly,
prepare derivative works, distribute, and otherwise use Python 1.6.1
alone or in any derivative version, provided, however, that CNRI's
License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
1995-2001 Corporation for National Research Initiatives; All Rights
Reserved" are retained in Python 1.6.1 alone or in any derivative
version prepared by Licensee. Alternately, in lieu of CNRI's License
Agreement, Licensee may substitute the following text (omitting the
quotes): "Python 1.6.1 is made available subject to the terms and
conditions in CNRI's License Agreement. This Agreement together with
Python 1.6.1 may be located on the internet using the following
unique, persistent identifier (known as a handle): 1895.22/1013. This
Agreement may also be obtained from a proxy server on the internet
using the following URL: http://hdl.handle.net/1895.22/1013".
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python 1.6.1 or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python 1.6.1.
4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. This License Agreement shall be governed by the federal
intellectual property law of the United States, including without
limitation the federal copyright law, and, to the extent such
U.S. federal law does not apply, by the law of the Commonwealth of
Virginia, excluding Virginia's conflict of law provisions.
Notwithstanding the foregoing, with regard to derivative works based
on Python 1.6.1 that incorporate non-separable material that was
previously distributed under the GNU General Public License (GPL), the
law of the Commonwealth of Virginia shall govern this License
Agreement only as to issues arising under or with respect to
Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
License Agreement shall be deemed to create any relationship of
agency, partnership, or joint venture between CNRI and Licensee. This
License Agreement does not grant permission to use CNRI trademarks or
trade name in a trademark sense to endorse or promote products or
services of Licensee, or any third party.
8. By clicking on the "ACCEPT" button where indicated, or by copying,
installing or otherwise using Python 1.6.1, Licensee agrees to be
bound by the terms and conditions of this License Agreement.
ACCEPT
CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
--------------------------------------------------
Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
The Netherlands. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.