Skip to content

Commit

Permalink
added open source acknowledgements to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Nov 13, 2024
1 parent 6130a5e commit 6a68dfa
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 706 deletions.
113 changes: 113 additions & 0 deletions caimira/docs/mkdocs/docs/open_source_acknowledgments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Open Source Acknowledgments

# Disclaimer

The following list includes the open-source dependencies used in this project, along with their respective licenses. It covers both the core dependencies explicitly specified in the project's requirements, as well as their transitive dependencies (dependencies of dependencies).

Including transitive dependencies is essential to acknowledge the full spectrum of open-source contributions that contribute to the functionality of this project. It also ensures compliance with open-source licenses and recognizes the efforts of all contributors, even those indirectly involved.

## CAiMIRA tool is Open Source

??? "Back-end (Python) Dependencies"
??? "Front-end (JavaScript) Dependencies"

#### jQuery 3.5.1

- License: MIT License(https://github.com/jquery/jquery/blob/main/LICENSE.txt)

#### jQuery Colorbox

- License: [MIT License](https://github.com/jackmoore/colorbox/blob/1.6.4/LICENSE.md)

#### ScrollMagic

- License: [MIT License](https://github.com/janpaepke/ScrollMagic/blob/v2.0.5/LICENSE.md)

#### Twitter Bootstrap 4.5.3

- License: [MIT License](https://github.com/twbs/bootstrap/blob/v4.5.3/LICENSE)

#### d3.js

- License: [ISC License](https://github.com/d3/d3/blob/v7.8.5/LICENSE)


??? "Other references"

#### Arve

- Endpoint: `https://www.arveair.com/terms-and-conditions/`

#### Rest Countries

- License: [MP License 2.0](https://gitlab.com/restcountries/restcountries/-/blob/master/LICENSE?ref_type=heads)

#### WHO COVID-19 Global Data

- Endpoint: `https://covid19.who.int/WHO-COVID-19-global-data.csv`

#### ArcGIS Geocode

- Endpoint: `https://geocode.arcgis.com`

#### View Hub Resources

- Endpoint: `https://view-hub.org/resources`

#### CERN Web Analytics

- Endpoint: `https://webanalytics.web.cern.ch/`

#### Zenodo Badge

- Endpoint: `https://zenodo.org/badge/DOI/10.5281/zenodo.6520431.svg`
- Description: Zenodo itself does not impose any specific license on the content that is deposited. Instead, it allows the depositor to choose the license for their content. This means that the permissiveness of the Zenodo badge (with the DOI) depends entirely on the license chosen by the person depositing the content.

#### Swiss COVID-19 Data

- Endpoint: `https://www.covid19.admin.ch/en/epidemiologic/case/d/development?epiRelDev=abs`

### License Distribution

![License Distribution](license_distribution.png)

### License information

The list of open-source dependencies provided here includes licenses for both direct dependencies and dependencies of dependencies. This comprehensive list covers a wide range of licenses, each with its own terms and conditions. Below is a summary of the most frequently encountered licenses along with their descriptions and usage:

1. **MIT License**
- The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT). It is a short and simple license that allows developers to use, modify, and distribute the software for both commercial and non-commercial purposes.

2. **Apache License, Version 2.0**
- The Apache License, Version 2.0 is a widely used open-source software license that allows users to use the software for any purpose, to distribute it, to modify it, and to distribute modified versions of the software under the terms of the license.

3. **Berkeley Software Distribution License (BSDL)**
- The BSD License is a family of permissive free software licenses that allow users to do anything they want with the source code, as long as they include the original copyright and license notice in any copy of the code or substantial portion of it.

4. **Mozilla Public License 2.0 (MPL)**
- The Mozilla Public License is a free and open-source software license developed and maintained by the Mozilla Foundation. It is a copyleft license, which means that derived works can only be distributed under the same license terms.

5. **Python Software Foundation Licene (PSFL)**
- The Python Software Foundation License (PSFL) is a BSD-style, permissive software license which is compatible with the GNU General Public License (GPL).[1] Its primary use is for distribution of the Python project software and its documentation. Since the license is permissive, it allows proprietization of the derivations.

6. **Internet Systems Consourtium License (ISCL)**
- The ISC license is a permissive free software license published by the Internet Software Consortium, now called Internet Systems Consortium (ISC). It is functionally equivalent to the simplified BSD and MIT licenses.

7. **Historical Permission Notice and Disclaimer License (HPND)**
- The Historical Permission Notice and Disclaimer (HPND) is an open source license, approved by the Open Source Initiative (OSI) and verified as GPL-compatible by the Free Software Foundation. The license can be almost functionally identical to the new, 3-clause BSD License (if the option for the no-promotion clause is exercised), or the MIT License (if the option for the no-promotion clause is not exercised).

8. **GNU General Public License 2.0 or later (GPL-2.0-or-later)**

- The GNU General Public License (GPL) is a copyleft license that allows users to modify and distribute software. Any modified versions must also be distributed under the GPL. The "or later" part means that the software can be distributed under any later version of the GPL as well. GPL ensures that software remains free and open-source.

9. **GNU Lesser General Public License 2.1 or later (LGPL-2.1-or-later)**

- The GNU Lesser General Public License (LGPL) is a more permissive version of the GPL, specifically intended for software libraries. It allows proprietary software to link to LGPL-licensed libraries without requiring the proprietary software itself to be open-source. Like the GPL, the LGPL requires modifications to the LGPL-licensed software to be released under the LGPL.

10. **Expat License (also known as MIT License)**

- The Expat License is an open-source license that is functionally identical to the MIT License. It is a permissive license that allows users to modify and distribute the software. The Expat license is commonly used in projects like XML parsing libraries and other lightweight open-source software.

11. **Dual License**

- A dual license means that the software is distributed under two different licenses, and the user can choose which one to comply with. This is commonly used to provide a more permissive license for open-source usage and a more restrictive commercial license for proprietary use. For example, a project may be available under both the MIT License and the GPL.
189 changes: 177 additions & 12 deletions caimira/docs/style_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,51 @@

import re
import os
import subprocess
import matplotlib.pyplot as plt
from collections import Counter

def get_package_info():
"""
Retrieves package details (name, version, license, and homepage) for each installed package.
Uses pip show to get detailed information.
"""
# Get the list of installed packages using pip freeze
packages = subprocess.check_output(["pip", "freeze"]).decode().splitlines()

package_details = []
for package in packages:
package_name = package.split("==")[0]
try:
# Get detailed info about each package
info = subprocess.check_output(["pip", "show", package_name]).decode().splitlines()

details = {
"name": package_name,
"version": "",
"license": "",
"homepage": ""
}

for line in info:
if line.startswith("Version:"):
details["version"] = line.split(":", 1)[1].strip()
elif line.startswith("License:"):
details["license"] = line.split(":", 1)[1].strip()
elif line.startswith("Home-page:"):
details["homepage"] = line.split(":", 1)[1].strip()

# Append the details for the current package
package_details.append(details)
except subprocess.CalledProcessError:
print(f"Error retrieving details for package: {package_name}")

return package_details


def update_markdown_references(md_file_path):
"""
Updates a Markdown file by adding headers for class definitions and modifying internal links.
Updates the code markdown file by adding headers for class definitions and modifying internal links.
"""
# Read the original Markdown file
with open(md_file_path, 'r') as file:
Expand All @@ -20,35 +61,159 @@ def update_markdown_references(md_file_path):

# For each found class definition
for match in class_matches:
class_name = match[0] # Class name (e.g., 'Interval' or 'ConcentrationModel')

# Class name (e.g., 'Interval' or 'ConcentrationModel')
class_name = match[0]

# Create the header for this class
header = f"## {class_name} Class\n"

# Check if the header already exists in the file
if header not in md_content:
# If the header does not exist, insert it before the class definition
md_content = md_content.replace(f"### *class* {class_name}", header + f"### *class* {class_name}")
md_content = md_content.replace(
f"### *class* {class_name}", header + f"### *class* {class_name}")

# Replace references like #models.models.ClassName with #className-class
md_content = md_content.replace(f"#models.models.{class_name}", f"#{class_name.lower()}-class")
md_content = md_content.replace(
f"#models.models.{class_name}", f"#{class_name.lower()}-class")

# Write the updated content back to the file
with open(md_file_path, 'w') as file:
file.write(md_content)
print(f"Markdown file '{md_file_path}' updated successfully.")


def unify_license(license_str):
"""
Returns an unified license version.
"""
license_map = {
'MIT': 'MIT',
'MIT License': 'MIT',
'MIT license': 'MIT',
'MIT-CMU': 'MIT',
'http://www.opensource.org/licenses/mit-license.php': 'MIT',
'BSD': 'BSD-3-Clause',
'BSD-3-Clause': 'BSD-3-Clause',
'BSD 3-Clause License': 'BSD-3-Clause',
'BSD 3-Clause': 'BSD-3-Clause',
'BSD-2-Clause': 'BSD-2-Clause',
'BSD License': 'BSD-3-Clause',
'new BSD License': 'BSD-3-Clause',
'Modified BSD License': 'BSD-3-Clause',
'BSD 2-Clause License': 'BSD-2-Clause',
'Apache 2.0': 'Apache-2.0',
'Apache Software License': 'Apache-2.0',
'Apache 2.0 License': 'Apache-2.0',
'Apache License, Version 2.0': 'Apache-2.0',
'Apache 2.0 license': 'Apache-2.0',
'Apache-2.0': 'Apache-2.0',
'Apache Software License 2.0': 'Apache-2.0',
'MPL-2.0': 'MPL-2.0',
'MPL 2.0': 'MPL-2.0',
'GPL-2.0-or-later': 'GPL-2.0-or-later',
'LGPL-2.1-or-later': 'LGPL-2.1-or-later',
'ISC license': 'ISC',
'Expat license': 'Expat',
'MIT OR Apache-2.0': 'Dual License',
'Dual License': 'Dual License',
'UNKNOWN': 'Unknown'
}

return license_map.get(license_str, 'Custom')


def add_python_dependencies_section(md_file_path, package_details):
"""
Adds the Python package dependencies section to the Open Source Acknowledgments Markdown file.
"""
# Section header for Python dependencies
dependencies_section = '\n\n'
for package in package_details:
package_url = f"https://pypi.org/project/{package['name']}/{package['version']}/"
package_title = f" #### [{package['name']} {package['version']}]({package_url})"
if package["license"]:
license_text = f" - License: {unify_license(package['license'])}"
else:
license_text = " - License: Unknown"

dependencies_section += f"{package_title}\n\n{license_text}\n\n"

# Read the current content of the Markdown file
with open(md_file_path, 'r') as file:
md_content = file.read()

# Regex to find the "Back-end (Python) Dependencies" section
section_pattern = re.compile(
r'(?<=\?\?\? "Back-end \(Python\) Dependencies")(.*?)(?=\n\?\?\?|\Z)', re.DOTALL)

match = section_pattern.search(md_content)
if match:
updated_content = md_content[:match.start(1)] + dependencies_section + md_content[match.end(1):]
else:
raise ValueError("Error: '??? \"Back-end (Python) Dependencies\"' section not found in the file.")

with open(md_file_path, 'w') as file:
file.write(updated_content)

print(f"Markdown file '{md_file_path}' updated with Python dependencies section.")


def generate_license_distribution_pie_chart(package_details, output_image_path):
"""
Generates a pie chart showing the distribution of licenses from the package details.
The chart is saved to the specified output image path.
"""
try:
licenses = [unify_license(pkg["license"]) for pkg in package_details if pkg["license"]]
license_counts = Counter(licenses)

# Create labels and sizes for the pie chart
labels = list(license_counts.keys())
sizes = list(license_counts.values())

# Create the pie chart
plt.figure(figsize=(8, 8), dpi=300)
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)
plt.axis('equal')

# Save and show the pie chart
plt.savefig(output_image_path, dpi=300)
plt.close()

print(f"License distribution pie chart saved to {output_image_path}")

except Exception as e:
print(f"Error generating license distribution chart: {e}")




def main():
# Path to the markdown file to be updated
md_file_path = 'sphinx/_build/markdown/index.md'
# Path to the index.md markdown file to be updated
index_file_path = 'sphinx/_build/markdown/index.md'

if os.path.isfile(index_file_path):
update_markdown_references(index_file_path)
else:
print(f"File '{index_file_path}' does not exist, skipping update.")

# Path to the open source acknowledgements markdown file to be updated
acknowledgements_file_path = 'mkdocs/docs/open_source_acknowledgments.md'

# Check if the markdown file exists before attempting updates
if os.path.isfile(md_file_path):
update_markdown_references(md_file_path)
if os.path.isfile(acknowledgements_file_path):
# Retrieve package details
package_details = get_package_info()

# Write the dependencies in the file
add_python_dependencies_section(acknowledgements_file_path, package_details)

# Generate the pie chart
output_image_path = 'mkdocs/docs/license_distribution.png'
generate_license_distribution_pie_chart(package_details, output_image_path)
else:
print(f"File '{md_file_path}' does not exist, skipping update.")
print(f"File '{acknowledgements_file_path}' does not exist, skipping update.")


if __name__ == "__main__":
main()

Loading

0 comments on commit 6a68dfa

Please sign in to comment.