Skip to content

Commit

Permalink
add pyinstaller spec file and adopt certs_file function
Browse files Browse the repository at this point in the history
  • Loading branch information
ediskandarov committed Nov 4, 2015
1 parent 485ec3b commit 4d5294c
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*pyo
*~
*egg-info*
/build
/dist
44 changes: 44 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,48 @@ You can also install the `in-development version`_ of transifex-client
with ``pip install transifex-client==dev`` or ``easy_install
transifex-client==dev``.


Build transifex-client for Windows
==================================

1. Download transifex-client sources via git or github archive.

a. ``git clone https://github.com/transifex/transifex-client.git``
b. Download and unpack https://github.com/transifex/transifex-client/archive/master.zip

2. Download and install Python_.

At this step choose right version of python: 2 or 3 and x86 or x86-64 instruction set.

Make sure pip marked for installation(default for latest installers).

3. Install PyInstaller_.

Suppose that Python installed to ``C:\\Program Files\\Python35-32``

Make ``python.exe`` accessible via PATH environment variable or cd to directory containing python.exe.

::

python -m pip install pyinstaller

This command will install ``PyInstaller`` package and its dependencies.

4. Build ``transifex-client`` distribution.

Change directory to transifex-client folder and run command:

::

python -m PyInstaller contrib/tx.spec
# or
pyinstaller contrib/tx.spec

5. ``tx.exe``

``dist/tx.exe`` will be created as the result of build process.


.. _in-development version: http://github.com/transifex/transifex-client/tarball/master#egg=transifex-client-dev
.. _Python: https://www.python.org/downloads/windows/
.. _PyInstaller: http://www.pyinstaller.org
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ install:
build_script:
# Build the compiled extension
#- "%CMD_IN_ENV% python setup.py build"
- pyinstaller tx.spec
- pyinstaller contrib/tx.spec

test_script:
# Run the project tests
#- "%CMD_IN_ENV% python setup.py nosetests"
- bash contrib/test_win_build.sh

after_test:
# If tests are successful, create binary packages for the project.
Expand Down
18 changes: 18 additions & 0 deletions contrib/test_win_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
HOST="https://www.transifex.com"
USER=$TRANSIFEX_USER
PASSWORD=$TRANSIFEX_PASSWORD
TX=`pwd`"/dist/tx.exe"

# Exit on fail
set -e

rm -rf txci
git clone https://github.com/diegobz/txci.git
cd txci
rm -rf .tx
$TX init --host=$HOST --user=$USER --pass=$PASSWORD
$TX set --auto-local -r txci.test -s en 'locale/<lang>/LC_MESSAGES/django.po' -t PO --execute
$TX push -s
$TX pull -l pt_BR -f

# $TX delete -f
Binary file added contrib/tx.ico
Binary file not shown.
29 changes: 29 additions & 0 deletions contrib/tx.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- mode: python -*-

block_cipher = None
added_files = [
('../txclib/cacert.pem', 'txclib'),
]

a = Analysis(['../tx'],
binaries=None,
datas=added_files,
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
excludes=None,
win_no_prefer_redirects=None,
win_private_assemblies=None,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='tx',
debug=False,
strip=None,
upx=False,
console=True , icon='contrib/tx.ico')
20 changes: 0 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@

install_requires = []
extra_args = {}
import platform
if platform.system() == 'Windows':
from py2exe.build_exe import py2exe as build_exe

class MediaCollector(build_exe):
# See http://crazedmonkey.com/blog/python/pkg_resources-with-py2exe.html
def copy_extensions(self, extensions):
build_exe.copy_extensions(self, extensions)
self.copy_file(
'txclib/cacert.pem',
os.path.join(self.collect_dir, 'txclib/cacert.pem')
)
self.compiled_files.append('txclib/cacert.pem')

extra_args = {
'console': ['tx'],
'options': {'py2exe': {'bundle_files': 1}},
'zipfile': None,
'cmdclass': {'py2exe': MediaCollector},
}

setup(
name="transifex-client",
Expand Down
14 changes: 14 additions & 0 deletions txclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ class HttpNotFound(Exception):
pass


def get_base_dir():
"""PyInstaller Run-time Operation.
http://pythonhosted.org/PyInstaller/#run-time-operation
"""
if getattr(sys, 'frozen', False):
# we are running in a bundle
basedir = sys._MEIPASS
else:
# we are running in a normal Python environment
basedir = os.path.dirname(os.path.abspath(__file__))
return basedir


def find_dot_tx(path=os.path.curdir, previous=None):
"""Return the path where .tx folder is found.
Expand Down
14 changes: 1 addition & 13 deletions txclib/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@ def user_agent_identifier():

def certs_file():
if platform.system() == 'Windows':
# Workaround py2exe and resource_filename incompatibility.
# Store the content in the filesystem permanently.
app_dir = os.path.join(
os.getenv('appdata', os.path.expanduser('~')), 'transifex-client'
)
if not os.path.exists(app_dir):
os.mkdir(app_dir)
ca_file = os.path.join(app_dir, 'cacert.pem')
if not os.path.exists(ca_file):
content = resource_string(__name__, 'cacert.pem')
with open(ca_file, 'w') as f:
f.write(content)
return ca_file
return os.path.join(txclib.utils.get_base_dir(), 'txclib', 'cacert.pem')
else:
POSSIBLE_CA_BUNDLE_PATHS = [
# Red Hat, CentOS, Fedora and friends
Expand Down

0 comments on commit 4d5294c

Please sign in to comment.