Skip to content

Commit

Permalink
Merge pull request #12 from abdoohossamm/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
abdoohossamm authored May 7, 2023
2 parents 7ffe4a6 + fe96443 commit e24b16b
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 12 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion djcompiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from djcompiler.compiler.djcompiler import DjangoCompiler

__version__ = "0.0.4"
__version__ = "0.0.5"
65 changes: 56 additions & 9 deletions djcompiler/compiler/djcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self,
ignored_dirs: List[str] = None,
build_directory: str = "build",
other_files_needed: List[str] = None,
other_dirs_needed: List[str] = None,
ignored_files: List[str] = None,
project_name: str = "",
project_author: str = "author",
Expand All @@ -38,6 +39,7 @@ def __init__(self,
:param ignored_dirs: list[str] -> a list of directories to ignore while building for example the env variables.
:param build_directory: path to the build output directory.
:param other_files_needed: files to copy to the build directory like the env file or manage.py script.
:param other_dirs_needed: dirs to copy to the build directory like the static dir and media dir.
:param c_dir: a path to the C files output.
"""
if ignored_dirs is None:
Expand All @@ -46,10 +48,13 @@ def __init__(self,
ignored_files = []
if other_files_needed is None:
other_files_needed = []
if other_dirs_needed is None:
other_dirs_needed = []
self.ignored_dirs = ignored_dirs
self.ignored_files = ignored_files
self.build_directory = build_directory
self.other_files_needed = other_files_needed
self.other_dirs_needed = other_dirs_needed
self.project_name = project_name
self.project_author = project_author
self.project_version = project_version
Expand Down Expand Up @@ -115,9 +120,33 @@ def copy_migrations_to_build(self):
print(f"building migration file {migration_path}")
shutil.copytree(f"{dir_path}", migration_path)

def inital_python_modules(self):
def copy_needed_dirs(self, dirs: list = None):
if dirs is None:
dirs = self.other_dirs_needed
print("#################### Copy Needed Dirs ####################")
for dir_path in dirs:
build_dir_path: str = f"./{self.build_directory}/{dir_path}"
if self.check_ignored_dirs(path_name=dir_path):
continue
try:
shutil.copytree(f"{dir_path}", build_dir_path, dirs_exist_ok=True)
print(f"Copy dir {dir_path} to build")
except FileNotFoundError as e:
print(f"Couldn't copy directory {dir_path} to build directory")

def python_modules_rules(self, path_name):
ignore_build_dir = path_name.endswith(f"/{self.build_directory}")
ignore_temp_dirs = f"./{self.build_directory}/temp." in f"{path_name}/"
for dir in self.other_dirs_needed:
ignore_other_needed_dirs = f"./{self.build_directory}/{dir}" in f"{path_name}/"
if ignore_build_dir or ignore_temp_dirs or ignore_other_needed_dirs:
return True
return False

def initial_python_modules(self):
print("#################### Initial Python Modules ####################")
for path, subdirs, files in os.walk(f"./{self.build_directory}"):
if path.endswith(f"/{self.build_directory}") or f"./{self.build_directory}/temp." in path:
if self.python_modules_rules(path):
continue
f = open(f"{path}/__init__.py", "w")
f.close()
Expand All @@ -128,18 +157,17 @@ def copy_needed_files(self, files: list = None):
files = self.other_files_needed
for file in files:
try:
shutil.copy(file, f"./{self.build_directory}")
shutil.copy(file, f"./{self.build_directory}/{file}")
except FileNotFoundError:
print(f"file {file} not found")
except FileExistsError:
print(f"file {file} already copied")

def compile_project(self, ext_modules: Set[Extension] = None,
def compile_modules(self, ext_modules: Set[Extension] = None,
cython_dir: str = "cython",
compiler_directives: dict = None
) -> None:
compiler_directives: dict = None) -> None:
"""
A function that compiles the django project
A method that compile the python modules
:param ext_modules: set[Extension]: not required -> files that should be compiled
:param cython_dir: str -> the C files output dir.
:param compiler_directives: dict -> extra compiler option [like the lanugae]
Expand All @@ -158,8 +186,27 @@ def compile_project(self, ext_modules: Set[Extension] = None,
ext_modules=cythonize(ext_modules, build_dir=cython_dir,
compiler_directives=compiler_directives,
),

)

def compile_project(self) -> None:
"""
A method that compiles the django project
the method runs:
compile_modules()
copy_migrations_to_build()
initial_python_modules()
copy_needed_files()
copy_needed_dirs()
methods
:return: None
"""
self.compile_modules()
self.copy_migrations_to_build()
self.inital_python_modules()
self.initial_python_modules()
self.copy_needed_files()
self.copy_needed_dirs()
1 change: 1 addition & 0 deletions djcompiler/management/command/buildfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BuildFile(BaseCommand):
# Compiler data
build_directory=build
other_files_needed=manage.py .env __init__.py
other_dirs_needed=static media
ignored_files=manage.py compiler.py
ignored_dirs=venv/ cython/ .git/ .idea/ build/ __pycache__/"""

Expand Down
1 change: 1 addition & 0 deletions djcompiler/management/command/buildpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BuildPY(BaseCommand):
project_version="1.0.0",
build_directory="build",
other_files_needed=["manage.py", ".env", "__init__.py"],
other_dirs_needed=["static"]
ignored_files=["manage.py", "setup.py", "compiler.py"]
)
ignored = compiler.initial_ignored_dirs + ["django_compiler/"]
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = djcompiler
version = 0.0.4
version = 0.0.5
url = https://github.com/abdoohossamm/djcompiler
author = Abdalrahman Hossam Eldin Mohamed
author_email = [email protected]
Expand Down Expand Up @@ -29,7 +29,7 @@ packages = find:
include_package_data = True
zip_safe = false
install_requires =
Cython >= 0.29.33
Cython >= 0.29.34
exclude = tests,testproject


Expand Down

0 comments on commit e24b16b

Please sign in to comment.