Skip to content

Commit e24b16b

Browse files
authored
Merge pull request #12 from abdoohossamm/test
Test
2 parents 7ffe4a6 + fe96443 commit e24b16b

File tree

6 files changed

+100
-12
lines changed

6 files changed

+100
-12
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Set up Python
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: '3.x'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
- name: Build package
34+
run: python -m build
35+
- name: Publish package
36+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37+
with:
38+
user: __token__
39+
password: ${{ secrets.PYPI_API_TOKEN }}

djcompiler/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from djcompiler.compiler.djcompiler import DjangoCompiler
22

3-
__version__ = "0.0.4"
3+
__version__ = "0.0.5"

djcompiler/compiler/djcompiler.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self,
2727
ignored_dirs: List[str] = None,
2828
build_directory: str = "build",
2929
other_files_needed: List[str] = None,
30+
other_dirs_needed: List[str] = None,
3031
ignored_files: List[str] = None,
3132
project_name: str = "",
3233
project_author: str = "author",
@@ -38,6 +39,7 @@ def __init__(self,
3839
:param ignored_dirs: list[str] -> a list of directories to ignore while building for example the env variables.
3940
:param build_directory: path to the build output directory.
4041
:param other_files_needed: files to copy to the build directory like the env file or manage.py script.
42+
:param other_dirs_needed: dirs to copy to the build directory like the static dir and media dir.
4143
:param c_dir: a path to the C files output.
4244
"""
4345
if ignored_dirs is None:
@@ -46,10 +48,13 @@ def __init__(self,
4648
ignored_files = []
4749
if other_files_needed is None:
4850
other_files_needed = []
51+
if other_dirs_needed is None:
52+
other_dirs_needed = []
4953
self.ignored_dirs = ignored_dirs
5054
self.ignored_files = ignored_files
5155
self.build_directory = build_directory
5256
self.other_files_needed = other_files_needed
57+
self.other_dirs_needed = other_dirs_needed
5358
self.project_name = project_name
5459
self.project_author = project_author
5560
self.project_version = project_version
@@ -115,9 +120,33 @@ def copy_migrations_to_build(self):
115120
print(f"building migration file {migration_path}")
116121
shutil.copytree(f"{dir_path}", migration_path)
117122

118-
def inital_python_modules(self):
123+
def copy_needed_dirs(self, dirs: list = None):
124+
if dirs is None:
125+
dirs = self.other_dirs_needed
126+
print("#################### Copy Needed Dirs ####################")
127+
for dir_path in dirs:
128+
build_dir_path: str = f"./{self.build_directory}/{dir_path}"
129+
if self.check_ignored_dirs(path_name=dir_path):
130+
continue
131+
try:
132+
shutil.copytree(f"{dir_path}", build_dir_path, dirs_exist_ok=True)
133+
print(f"Copy dir {dir_path} to build")
134+
except FileNotFoundError as e:
135+
print(f"Couldn't copy directory {dir_path} to build directory")
136+
137+
def python_modules_rules(self, path_name):
138+
ignore_build_dir = path_name.endswith(f"/{self.build_directory}")
139+
ignore_temp_dirs = f"./{self.build_directory}/temp." in f"{path_name}/"
140+
for dir in self.other_dirs_needed:
141+
ignore_other_needed_dirs = f"./{self.build_directory}/{dir}" in f"{path_name}/"
142+
if ignore_build_dir or ignore_temp_dirs or ignore_other_needed_dirs:
143+
return True
144+
return False
145+
146+
def initial_python_modules(self):
147+
print("#################### Initial Python Modules ####################")
119148
for path, subdirs, files in os.walk(f"./{self.build_directory}"):
120-
if path.endswith(f"/{self.build_directory}") or f"./{self.build_directory}/temp." in path:
149+
if self.python_modules_rules(path):
121150
continue
122151
f = open(f"{path}/__init__.py", "w")
123152
f.close()
@@ -128,18 +157,17 @@ def copy_needed_files(self, files: list = None):
128157
files = self.other_files_needed
129158
for file in files:
130159
try:
131-
shutil.copy(file, f"./{self.build_directory}")
160+
shutil.copy(file, f"./{self.build_directory}/{file}")
132161
except FileNotFoundError:
133162
print(f"file {file} not found")
134163
except FileExistsError:
135164
print(f"file {file} already copied")
136165

137-
def compile_project(self, ext_modules: Set[Extension] = None,
166+
def compile_modules(self, ext_modules: Set[Extension] = None,
138167
cython_dir: str = "cython",
139-
compiler_directives: dict = None
140-
) -> None:
168+
compiler_directives: dict = None) -> None:
141169
"""
142-
A function that compiles the django project
170+
A method that compile the python modules
143171
:param ext_modules: set[Extension]: not required -> files that should be compiled
144172
:param cython_dir: str -> the C files output dir.
145173
:param compiler_directives: dict -> extra compiler option [like the lanugae]
@@ -158,8 +186,27 @@ def compile_project(self, ext_modules: Set[Extension] = None,
158186
ext_modules=cythonize(ext_modules, build_dir=cython_dir,
159187
compiler_directives=compiler_directives,
160188
),
161-
162189
)
190+
191+
def compile_project(self) -> None:
192+
"""
193+
A method that compiles the django project
194+
the method runs:
195+
compile_modules()
196+
197+
copy_migrations_to_build()
198+
199+
initial_python_modules()
200+
201+
copy_needed_files()
202+
203+
copy_needed_dirs()
204+
205+
methods
206+
:return: None
207+
"""
208+
self.compile_modules()
163209
self.copy_migrations_to_build()
164-
self.inital_python_modules()
210+
self.initial_python_modules()
165211
self.copy_needed_files()
212+
self.copy_needed_dirs()

djcompiler/management/command/buildfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class BuildFile(BaseCommand):
1212
# Compiler data
1313
build_directory=build
1414
other_files_needed=manage.py .env __init__.py
15+
other_dirs_needed=static media
1516
ignored_files=manage.py compiler.py
1617
ignored_dirs=venv/ cython/ .git/ .idea/ build/ __pycache__/"""
1718

djcompiler/management/command/buildpy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class BuildPY(BaseCommand):
1515
project_version="1.0.0",
1616
build_directory="build",
1717
other_files_needed=["manage.py", ".env", "__init__.py"],
18+
other_dirs_needed=["static"]
1819
ignored_files=["manage.py", "setup.py", "compiler.py"]
1920
)
2021
ignored = compiler.initial_ignored_dirs + ["django_compiler/"]

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = djcompiler
3-
version = 0.0.4
3+
version = 0.0.5
44
url = https://github.com/abdoohossamm/djcompiler
55
author = Abdalrahman Hossam Eldin Mohamed
66
author_email = [email protected]
@@ -29,7 +29,7 @@ packages = find:
2929
include_package_data = True
3030
zip_safe = false
3131
install_requires =
32-
Cython >= 0.29.33
32+
Cython >= 0.29.34
3333
exclude = tests,testproject
3434

3535

0 commit comments

Comments
 (0)