Skip to content

Commit

Permalink
Merge pull request #2 from ziadhany/main
Browse files Browse the repository at this point in the history
  • Loading branch information
TG1999 authored Mar 12, 2024
2 parents 9af8703 + eb78770 commit 1703774
Show file tree
Hide file tree
Showing 308 changed files with 29,453 additions and 111 deletions.
14 changes: 14 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FEDERATED_CODE_HOST=127.0.0.1
FEDERATED_CODE_PORT=8000
FEDERATED_CODE_DOMAIN=${FEDERATED_CODE_HOST}:${FEDERATED_CODE_PORT}

POSTGRES_HOST=127.0.0.1
POSTGRES_DB=federatedcode
POSTGRES_USER=federatedcode
POSTGRES_PASSWORD=federatedcode

FEDERATED_CODE_GIT_PATH=/home/ziad/new_vul
FEDERATED_CODE_CLIENT_ID=4SDoNYvLfOG2h8LNt1ksIwZ4BSx8fZPmPar8SXKJ
FEDERATED_CODE_CLIENT_SECRET=OrzhuzFcxeoaQ8wf1kXPyczmsh6DL10A3duTz1CuSxktvAxKlsjjiGqWUafbovZip75Kt7GmHIOouveRDER7bc41IVq29SvnTqUkFtJKCXcYArQf7WY3BiSPEOBwlw5F
FEDERATED_CODE_STATIC_ROOT=/var/federatedcode/static/
STATIC_ROOT=/var/federatedcode/static/
1 change: 0 additions & 1 deletion .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
runs-on: ubuntu-20.04

strategy:
max-parallel: 4
matrix:
python-version: [3.9]

Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: run tests

on: [push, pull_request]

env:
FEDERATED_CODE_HOST: 127.0.0.1
FEDERATED_CODE_PORT: 8000
FEDERATED_CODE_DOMAIN: 127.0.0.1:8000
POSTGRES_HOST: 127.0.0.1
POSTGRES_DB: federatedcode
POSTGRES_USER: federatedcode
POSTGRES_PASSWORD: federatedcode

jobs:
build:
runs-on: ubuntu-20.04

services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
ports:
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: make dev

- name: Run tests
run: make test
env:
GH_TOKEN: 1
FEDERATED_CODE_HOST: ${{ env.FEDERATED_CODE_HOST }}
FEDERATED_CODE_PORT: ${{ env.FEDERATED_CODE_PORT }}
FEDERATED_CODE_DOMAIN: ${{ env.FEDERATED_CODE_DOMAIN }}
POSTGRES_HOST: ${{ env.POSTGRES_HOST }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_PORT: ${{ env.POSTGRES_PORT }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ tcl

# Ignore Jupyter Notebook related temp files
.ipynb_checkpoints/
.env
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
FROM python:3.10
# Python settings: Force unbuffered stdout and stderr (i.e. they are flushed to terminal immediately)
ENV PYTHONUNBUFFERED 1
# Python settings: do not write pyc files
ENV PYTHONDONTWRITEBYTECODE 1

RUN pip install --upgrade pip

WORKDIR /federatedcode

COPY requirements.txt pyproject.toml /federatedcode/

RUN pip install -r requirements.txt

COPY . /federatedcode
47 changes: 41 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,39 @@
# See https://github.com/nexB/skeleton for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
include .env

# Python version can be specified with `$ PYTHON_EXE=python3.x make conf`
PYTHON_EXE?=python3
VENV=venv
ACTIVATE?=. ${VENV}/bin/activate;
MANAGE=${VENV}/bin/python manage.py

# Use sudo for postgres, but only on Linux
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
SUDO_POSTGRES=sudo -u postgres
else
SUDO_POSTGRES=
endif

dev:
@echo "-> Configure the development envt."
./configure --dev

envfile:
@echo "-> Create the .env file and generate a secret key"
@if test -f ${ENV_FILE}; then echo ".env file exists already"; exit 1; fi
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" > ${ENV_FILE}

isort:
@echo "-> Apply isort changes to ensure proper imports ordering"
${VENV}/bin/isort --sl -l 100 src tests setup.py
${VENV}/bin/isort --sl -l 100 tests setup.py

black:
@echo "-> Apply black code formatter"
${VENV}/bin/black -l 100 src tests setup.py
${VENV}/bin/black -l 100 tests setup.py

doc8:
@echo "-> Run doc8 validation"
Expand All @@ -35,9 +51,9 @@ check:
@echo "-> Run pycodestyle (PEP8) validation"
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache .
@echo "-> Run isort imports ordering validation"
@${ACTIVATE} isort --sl --check-only -l 100 setup.py src tests .
@${ACTIVATE} isort --sl --check-only -l 100 setup.py tests .
@echo "-> Run black validation"
@${ACTIVATE} black --check --check -l 100 src tests setup.py
@${ACTIVATE} black --check --check -l 100 tests setup.py

clean:
@echo "-> Clean the Python env"
Expand All @@ -49,6 +65,25 @@ test:

docs:
rm -rf docs/_build/
@${ACTIVATE} sphinx-build docs/ docs/_build/
@${ACTIVATE} sphinx-build docs/source docs/_build/

postgres:
@echo "-> Configure PostgreSQL database"
@echo "-> Create database user '${POSTGRES_DB}'"
${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb ${POSTGRES_DB} || true
${SUDO_POSTGRES} psql -c "alter user ${POSTGRES_USER} with encrypted password '${POSTGRES_PASSWORD}';" || true
@echo "-> Drop '${POSTGRES_DB}' database"
${SUDO_POSTGRES} dropdb ${POSTGRES_DB} || true
@echo "-> Create '${POSTGRES_DB}' database"
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=${POSTGRES_USER} ${POSTGRES_DB}
@$(MAKE) migrate

migrate:
@echo "-> Apply database migrations"
${MANAGE} migrate

run:
@echo "-> Starting development server"
${MANAGE} runserver

.PHONY: conf dev check valid black isort clean test docs
.PHONY: conf dev check valid black isort clean test docs envfile postgres migrate run
78 changes: 20 additions & 58 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,62 +1,24 @@
A Simple Python Project Skeleton
FederatedCode
================================
This repo attempts to standardize the structure of the Python-based project's
repositories using modern Python packaging and configuration techniques.
Using this `blog post`_ as inspiration, this repository serves as the base for
all new Python projects and is mergeable in existing repositories as well.

.. _blog post: https://blog.jaraco.com/a-project-skeleton-for-python-projects/

FederatedCode is a decentralized, federated metadata about software applications

Usage
=====

A brand new project
-------------------
.. code-block:: bash
git init my-new-repo
cd my-new-repo
git pull [email protected]:nexB/skeleton
# Create the new repo on GitHub, then update your remote
git remote set-url origin [email protected]:nexB/your-new-repo.git
From here, you can make the appropriate changes to the files for your specific project.

Update an existing project
---------------------------
.. code-block:: bash
cd my-existing-project
git remote add skeleton [email protected]:nexB/skeleton
git fetch skeleton
git merge skeleton/main --allow-unrelated-histories
This is also the workflow to use when updating the skeleton files in any given repository.

More usage instructions can be found in ``docs/skeleton-usage.rst``.


Release Notes
=============

- 2023-07-18:
- Add macOS-13 job in azure-pipelines.yml

- 2022-03-04:
- Synchronize configure and configure.bat scripts for sanity
- Update CI operating system support with latest Azure OS images
- Streamline utility scripts in etc/scripts/ to create, fetch and manage third-party dependencies
There are now fewer scripts. See etc/scripts/README.rst for details

- 2021-09-03:
- ``configure`` now requires pinned dependencies via the use of ``requirements.txt`` and ``requirements-dev.txt``
- ``configure`` can now accept multiple options at once
- Add utility scripts from scancode-toolkit/etc/release/ for use in generating project files
- Rename virtual environment directory from ``tmp`` to ``venv``
- Update README.rst with instructions for generating ``requirements.txt`` and ``requirements-dev.txt``,
as well as collecting dependencies as wheels and generating ABOUT files for them.

- 2021-05-11:
- Adopt new configure scripts from ScanCode TK that allows correct configuration of which Python version is used.
Getting started
-----------------

Quick Installation
===================
On a Debian system, use this::
sudo apt-get install python3-venv python3-dev postgresql libpq-dev build-essential
git clone https://github.com/nexB/federatedcode.git && cd federatedcode
make dev envfile postgres
make test
source venv/bin/activate
make run

Acknowledgements
^^^^^^^^^^^^^^^^
This project was funded through the NGI0 Entrust Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement No 101069594.

https://nlnet.nl/project/FederatedSoftwareMetadata/
6 changes: 3 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ CLI_ARGS=$1
################################

# Requirement arguments passed to pip and used by default or with --dev.
REQUIREMENTS="--editable . --constraint requirements.txt"
DEV_REQUIREMENTS="--editable .[testing] --constraint requirements.txt --constraint requirements-dev.txt"
DOCS_REQUIREMENTS="--editable .[docs] --constraint requirements.txt"
REQUIREMENTS="--editable . -r requirements.txt"
DEV_REQUIREMENTS="--editable .[testing] -r requirements.txt -r requirements-dev.txt"
DOCS_REQUIREMENTS="--editable .[docs] -r requirements.txt"

# where we create a virtualenv
VIRTUALENV_DIR=venv
Expand Down
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3'

services:
db:
image: postgres:16
env_file:
- docker.env
volumes:
- db_data:/var/lib/postgresql/data/
federatedcode:
build: .
command: /bin/sh -c "
apt-get update && apt-get install -y gunicorn &&
python manage.py collectstatic --no-input --verbosity 0 --clear &&
python manage.py migrate &&
gunicorn federatedcode.wsgi:application -u nobody -g nogroup --bind :8000 --timeout 600 --workers 8"
env_file:
- docker.env
expose:
- 8000
ports:
- "8000:8000"
volumes:
- static:/var/federatedcode/static/
- /etc/federatedcode/:/etc/federatedcode/
depends_on:
- db
nginx:
image: nginx
env_file:
- docker.env
volumes:
- ./etc/nginx/conf.d/:/etc/nginx/conf.d
depends_on:
- federatedcode
volumes:
db_data:
static:
federatedcode:

15 changes: 15 additions & 0 deletions docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FEDERATED_CODE_HOST=127.0.0.1
FEDERATED_CODE_PORT=8080
FEDERATED_CODE_DOMAIN=${FEDERATED_CODE_HOST}:${FEDERATED_CODE_PORT}

POSTGRES_HOST=db
POSTGRES_DB=purl-sync
POSTGRES_USER=purl-sync
POSTGRES_PASSWORD=purl-sync

FEDERATED_CODE_GIT_PATH=/
FEDERATED_CODE_CLIENT_ID=""
FEDERATED_CODE_CLIENT_SECRET=""
FEDERATED_CODE_STATIC_ROOT=/var/federatedcode/static/
STATIC_ROOT=/var/federatedcode/static/
NGINX_PORT=8080
13 changes: 7 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# -- Project information -----------------------------------------------------

project = "nexb-skeleton"
project = "federatedcode"
copyright = "nexB Inc. and others."
author = "AboutCode.org authors and contributors"

Expand All @@ -30,7 +30,7 @@
extensions = [
"sphinx.ext.intersphinx",
"sphinx_reredirects",
'sphinx_rtd_theme',
"sphinx_rtd_theme",
"sphinx_rtd_dark_mode",
"sphinx.ext.extlinks",
"sphinx_copybutton",
Expand All @@ -47,7 +47,10 @@

intersphinx_mapping = {
"aboutcode": ("https://aboutcode.readthedocs.io/en/latest/", None),
"scancode-workbench": ("https://scancode-workbench.readthedocs.io/en/develop/", None),
"scancode-workbench": (
"https://scancode-workbench.readthedocs.io/en/develop/",
None,
),
}


Expand Down Expand Up @@ -108,6 +111,4 @@

# -- Options for LaTeX output -------------------------------------------------

latex_elements = {
'classoptions': ',openany,oneside'
}
latex_elements = {"classoptions": ",openany,oneside"}
Loading

0 comments on commit 1703774

Please sign in to comment.