Skip to content

Commit 19c5613

Browse files
4418 p2 bug on glide pre commit hook poly prepare make sure we git add any docstrings added from poly prepare (#55)
* Fixed windows no deployables found bug * removed superfluous print * Fixed deployables not being staged properly * Added .venv to excluded directories * Bumped version up to 0.3.8.dev1
1 parent bd5729d commit 19c5613

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

polyapi/deployables.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,24 @@ class PolyDeployConfig(TypedDict):
112112

113113
def get_all_deployable_files_windows(config: PolyDeployConfig) -> List[str]:
114114
# Constructing the Windows command using dir and findstr
115-
include_pattern = " ".join(f"*.{f}" if "." in f else f"*.{f}" for f in config["include_files_or_extensions"]) or "*"
116-
exclude_pattern = '|'.join(config["exclude_dirs"])
117-
pattern = '|'.join(f"polyConfig: {name}" for name in config["type_names"]) or 'polyConfig'
115+
include_pattern = " ".join(f"*.{f}" for f in config["include_files_or_extensions"]) or "*"
116+
exclude_pattern = ' '.join(f"\\{f}" for f in config["exclude_dirs"])
117+
pattern = ' '.join(f"\\<polyConfig: {name}\\>" for name in config["type_names"]) or 'polyConfig'
118118

119-
exclude_command = f" | findstr /V /I \"{exclude_pattern}\"" if exclude_pattern else ''
120-
search_command = f" | findstr /M /I /F:/ /C:\"{pattern}\""
119+
# Using two regular quotes or two smart quotes throws "The syntax of the command is incorrect".
120+
# For some reason, starting with a regular quote and leaving the end without a quote works.
121+
exclude_command = f" | findstr /V /I \"{exclude_pattern}" if exclude_pattern else ''
122+
search_command = f" | findstr /M /I /F:/ {pattern}"
121123

122124
result = []
123125
for dir_path in config["include_dirs"]:
124-
dir_command = f"dir /S /P /B {include_pattern} {dir_path}"
126+
if dir_path is not '.':
127+
include_pattern = " ".join(f"{dir_path}*.{f}" for f in config["include_files_or_extensions"]) or "*"
128+
dir_command = f"dir {include_pattern} /S /P /B"
125129
full_command = f"{dir_command}{exclude_command}{search_command}"
126130
try:
127131
output = subprocess.check_output(full_command, shell=True, text=True)
128-
result.extend(output.strip().split('\r\n'))
132+
result.extend(output.strip().split('\n'))
129133
except subprocess.CalledProcessError:
130134
pass
131135
return result
@@ -154,7 +158,7 @@ def get_all_deployable_files(config: PolyDeployConfig) -> List[str]:
154158
if not config.get("include_files_or_extensions"):
155159
config["include_files_or_extensions"] = ["py"]
156160
if not config.get("exclude_dirs"):
157-
config["exclude_dirs"] = ["poly", "node_modules", "dist", "build", "output", ".vscode", ".poly", ".github", ".husky", ".yarn"]
161+
config["exclude_dirs"] = ["Lib", "node_modules", "dist", "build", "output", ".vscode", ".poly", ".github", ".husky", ".yarn", ".venv"]
158162

159163
is_windows = os.name == "nt"
160164
if is_windows:

polyapi/prepare.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import subprocess
34
from typing import List, Tuple, Literal
45
import requests
56

@@ -135,6 +136,18 @@ def prepare_deployables(lazy: bool = False, disable_docs: bool = False, disable_
135136
# NOTE: write_updated_deployable has side effects that update deployable.fileRevision which is in both this list and parsed_deployables
136137
for deployable in dirty_deployables:
137138
write_updated_deployable(deployable, disable_docs)
139+
# Re-stage any updated staged files.
140+
staged = subprocess.check_output('git diff --name-only --cached', shell=True, text=True, ).split('\n')
141+
rootPath = subprocess.check_output('git rev-parse --show-toplevel', shell=True, text=True).replace('\n', '')
142+
for deployable in dirty_deployables:
143+
try:
144+
deployableName = deployable["file"].replace('\\', '/').replace(f"{rootPath}/", '')
145+
if deployableName in staged:
146+
print(f'Staging {deployableName}')
147+
subprocess.run(['git', 'add', deployableName])
148+
except:
149+
print('Warning: File staging failed, check that all files are staged properly.')
150+
138151

139152
print("Poly deployments are prepared.")
140153
save_deployable_records(parsed_deployables)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
33

44
[project]
55
name = "polyapi-python"
6-
version = "0.3.8.dev0"
6+
version = "0.3.8.dev1"
77
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
88
authors = [{ name = "Dan Fellin", email = "[email protected]" }]
99
dependencies = [

0 commit comments

Comments
 (0)