Here are the steps to build PYC-only python distribution. We shall create the build.py file, which on compilation creates pyc-only python distribution of the 'project' directory.
Steps:
3. Run the build.py script.
4. A project.tar.gz file will be created within the same directory.
5. Untar the file using -xvzf command, you should be able to see only .pyc files in the distribution.
Steps:
- Lets create a build.py file in the same directory that we have project folder.
- Include the following code in the build.py:
import os
import compileall
#Removes all open files from project directory.
command1='find . -name "*.py~" -exec rm -rf {} \;'
#compiles all .py files in project directory and creates corresponding file's .pyc
compileall.compile_dir('./project')
#creates a tar.gz file which excludes all .py files
command2='tar -zcvf project.tar project --exclude project/\*/\*.py --exclude project/\*.py --exclude ''exclude files/directory which are irrelevant''
#removes .pyc created in actual project directory.
command3='find . -name "*.pyc" -exec rm -rf {} \;'
#use below command if you do not want to remove any particular files in the path.
#command3='find . ! -name build.py -name "*.py" -exec rm -rf {} \;'
#Execute the commands
os.system(command1)
os.system(command2)
os.system(command3)
3. Run the build.py script.
4. A project.tar.gz file will be created within the same directory.
5. Untar the file using -xvzf command, you should be able to see only .pyc files in the distribution.
No comments:
Post a Comment