Skip to content

Commit

Permalink
Remove PyWin32 dependency, update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Apr 21, 2023
1 parent 5e14500 commit 72c5768
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v2

- name: Set up Python 3.8
uses: actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5 # v4.2.0
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
with:
python-version: 3.8

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v2

- name: Set up Python
uses: actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5 # v4.2.0
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
with:
python-version: 3.8

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v2
- name: Set up Python 3.8
uses: actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5 # v4.2.0
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
with:
python-version: 3.8
- name: Install Pip Dependencies
Expand Down
2 changes: 1 addition & 1 deletion plan_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME = 'PLAN-Tools'
VERSION = 0.5
VERSION = 0.6
35 changes: 24 additions & 11 deletions plan_tools/entry_point.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from shutil import copyfile
from os import chmod, path, stat, symlink
from os import chmod, path, stat, symlink, fdopen, unlink
from pathlib import Path
from platform import system
from site import USER_BASE, getusersitepackages
from subprocess import check_call
from sys import argv
from sysconfig import get_path
from tempfile import mkstemp
from typing import List


Expand Down Expand Up @@ -80,21 +82,32 @@ def add_desktop_icon(self) -> int:
return 0

def write_desktop_file(self, desktop_file: Path, target_exe: Path, scripts_dir: Path, icon_file: Path):
icon_file_string = icon_file if icon_file.exists() else ''
icon_file_string: str = str(icon_file) if icon_file.exists() else ''
if system() == 'Windows':
self.desktop_file_data_check = {'exe': target_exe, 'cwd': scripts_dir, 'icon': icon_file_string}
if self.test_mode:
return
else: # pragma: no cover
# maybe someday we could actually test this in CI
# noinspection PyUnresolvedReferences
from win32com.client import Dispatch
shell = Dispatch('WScript.Shell')
s = shell.CreateShortCut(str(desktop_file))
s.Targetpath = str(target_exe)
s.WorkingDirectory = str(scripts_dir)
s.IconLocation = str(icon_file_string)
s.save()
def escape_path(path_: Path) -> str:
return str(path_).replace('\\', '/')

shortcut_path = escape_path(desktop_file)
target = escape_path(target_exe)
working_dir = escape_path(scripts_dir)
js_content = f'''
var sh = WScript.CreateObject("WScript.Shell");
var shortcut = sh.CreateShortcut("{shortcut_path}");
shortcut.TargetPath = "{target}";
shortcut.WorkingDirectory = "{working_dir}";
shortcut.IconLocation = "{icon_file_string}";
shortcut.Save();'''
script_fd, script_path = mkstemp('.js')
try:
with fdopen(script_fd, 'w') as f:
f.write(js_content)
check_call([R'wscript.exe', script_path])
finally:
unlink(script_path)
elif system() == 'Linux':
desktop_file_contents = f"""[Desktop Entry]
Name={self.pretty_link_name}
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ flake8
nose
sphinx
wheel
pypiwin32; sys_platform == 'win32'
11 changes: 3 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,21 @@
with codecs.open(os.path.join(this_dir, 'README.md'), encoding='utf-8') as i_file:
long_description = i_file.read()

install_requires = []
if system() == 'Windows':
install_requires.append('pypiwin32')

setup(
name=NAME,
version=VERSION,
packages=find_packages(exclude=['test', 'tests', 'test.*']),
url='https://github.com/Myoldmopar/PlanTools',
license='',
author='Edwin Lee',
author_email='',
license='ModifiedBSD',
author='Edwin Lee, for NREL, for United States Department of Energy',
description='A set of tools to help with Pip Links And Nonsense',
long_description=long_description,
long_description_content_type='text/markdown',
test_suite='nose.collector',
tests_require=['nose'],
keywords='energyplus',
include_package_data=True, # use /MANIFEST.in file for declaring package data
install_requires=install_requires,
install_requires=[],
entry_points={
'console_scripts': [
'plan_tool=plan_tools.runner:cli',
Expand Down

0 comments on commit 72c5768

Please sign in to comment.