Skip to content

Commit ee0d6c4

Browse files
committed
BUGFIX : Fix hitchrunpy.
1 parent 1c35598 commit ee0d6c4

16 files changed

+182
-55
lines changed

.github/workflows/regression.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Regression
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
regression:
11+
timeout-minutes: 30
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: checkout repo
15+
uses: actions/checkout@v2
16+
17+
- name: ensure qemu installed so arm containers work
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install qemu-system-arm qemu-efi qemu-user-static -y
21+
22+
- name: build
23+
run: ./key.sh make
24+
25+
- name: regression
26+
run: ./key.sh regression

hitch/Dockerfile-hitch

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update
4+
RUN apt-get upgrade -y
5+
RUN apt-get install libuv1-dev -y
6+
RUN apt-get install curl -y
7+
RUN apt-get install git -y
8+
RUN apt-get install libreadline-dev -y
9+
RUN apt-get install libffi-dev -y
10+
RUN apt-get install python3-virtualenv -y
11+
RUN apt-get install virtualenv -y
12+
RUN apt-get install build-essential -y
13+
RUN apt-get install python3-dev -y
14+
RUN apt-get install zlib1g-dev -y
15+
RUN apt-get install zlib1g -y
16+
RUN apt-get install libbz2-dev -y
17+
ENV DEBIAN_FRONTEND=noninteractive
18+
RUN apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl -y
19+
20+
21+
22+
# Isolate system python packages from those used in project
23+
RUN virtualenv --python=python3 /venv
24+
RUN mkdir /src
25+
26+
WORKDIR /src
27+
COPY hitch/hitchreqs.txt /
28+
ENV LC_ALL=C.UTF-8
29+
ENV LANG=C.UTF-8
30+
RUN /venv/bin/pip install setuptools-rust
31+
RUN /venv/bin/python --version
32+
RUN /venv/bin/pip install -r /hitchreqs.txt

hitch/hitchreqs.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
hitchrun>=0.4.0
2-
hitchpylibrarytoolkit>=0.5.1
2+
hitchpylibrarytoolkit==0.5.0
33

hitch/hitchreqs.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ flake8==4.0.1
4040
# via hitchpylibrarytoolkit
4141
gitdb==4.0.9
4242
# via gitpython
43-
gitpython==3.1.24
43+
gitpython==3.1.20
4444
# via hitchpylibrarytoolkit
4545
hitchbuild==0.6.3
4646
# via
@@ -62,13 +62,13 @@ icommandlib==0.5.0
6262
# via hitchrunpy
6363
idna==3.3
6464
# via requests
65-
importlib-metadata==4.8.2
65+
importlib-metadata==4.2.0
6666
# via
6767
# keyring
6868
# twine
69-
ipython==7.30.0
69+
ipython==7.16.3
7070
# via hitchpylibrarytoolkit
71-
jedi==0.18.1
71+
jedi==0.17.2
7272
# via ipython
7373
jeepney==0.7.1
7474
# via
@@ -94,7 +94,7 @@ mypy-extensions==0.4.3
9494
# via black
9595
packaging==21.3
9696
# via bleach
97-
parso==0.8.2
97+
parso==0.7.1
9898
# via jedi
9999
path==16.2.0
100100
# via path.py
@@ -198,7 +198,7 @@ tomli==1.2.2
198198
# pep517
199199
tqdm==4.62.3
200200
# via twine
201-
traitlets==5.1.1
201+
traitlets==4.3.3
202202
# via
203203
# ipython
204204
# matplotlib-inline
@@ -210,7 +210,7 @@ typing-extensions==4.0.0
210210
# gitpython
211211
urllib3==1.26.7
212212
# via requests
213-
uvloop==0.16.0
213+
uvloop==0.14.0
214214
# via icommandlib
215215
wcwidth==0.2.5
216216
# via

hitch/key.py

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44
from hitchrun import expected
55
from strictyaml import Str, MapPattern, Map, Enum, Optional
66
from pathquery import pathquery
7-
from hitchrun import DIR
7+
from click import argument, group, pass_context
88
from hitchrunpy import ExamplePythonCode, HitchRunPyException
99
import hitchpylibrarytoolkit
1010
from templex import Templex
1111
import dirtemplate
1212
import colorama
13+
from path import Path
14+
15+
class Directories:
16+
gen = Path("/gen")
17+
key = Path("/src/hitch/")
18+
project = Path("/src/")
19+
share = Path("/gen")
20+
21+
22+
DIR = Directories()
23+
24+
25+
@group(invoke_without_command=True)
26+
@pass_context
27+
def cli(ctx):
28+
"""Integration test command line interface."""
29+
pass
30+
1331

1432

1533
toolkit = hitchpylibrarytoolkit.ProjectToolkit(
@@ -58,9 +76,13 @@ def set_up(self):
5876
fullpath.dirname().makedirs()
5977
fullpath.write_text(content)
6078

61-
self.python = hitchpylibrarytoolkit.project_build(
62-
"hitchrunpy", self.path, self.given["runner python version"]
63-
).bin.python
79+
80+
self.pylibrary = hitchpylibrarytoolkit.PyLibraryBuild(
81+
"hitchrunpy",
82+
self.path,
83+
).with_python_version(self.given.get("python_version", "3.7.0"))
84+
self.pylibrary.ensure_built()
85+
self.python = self.pylibrary.bin.python
6486

6587
def _story_friendly_output(self, content):
6688
return "\n".join(
@@ -81,8 +103,8 @@ def _setup_code(self):
81103
return (
82104
self.given.get("setup", "")
83105
.replace("/path/to/working_dir", self.path.working_dir)
84-
.replace("/path/to/share_dir/", self.path.share)
85-
.replace("/path/to/build_dir/", self.path.state)
106+
.replace("/path/to/share_dir", self.path.state)
107+
.replace("/path/to/build_dir", self.path.state)
86108
.replace("{{ pyver }}", self.given["working python version"])
87109
)
88110

@@ -108,27 +130,26 @@ def run(self, code, will_output=None, raises=None):
108130
self.path.profile.joinpath("{0}.dat".format(self.story.slug))
109131
)
110132

111-
result = (
112-
to_run.expect_exceptions().run() if raises is not None else to_run.run()
113-
)
133+
if raises is None:
134+
result = to_run.run()
114135

115-
actual_output = self._story_friendly_output(result.output)
136+
actual_output = self._story_friendly_output(result.output)
116137

117-
if will_output is not None:
118-
try:
119-
Templex(will_output).assert_match(actual_output)
120-
except AssertionError:
121-
if self.settings.get("rewrite"):
122-
self.current_step.update(**{"will output": actual_output})
123-
else:
124-
raise
138+
if will_output is not None:
139+
try:
140+
Templex(will_output).assert_match(actual_output)
141+
except AssertionError:
142+
if self.settings.get("rewrite"):
143+
self.current_step.update(**{"will output": actual_output})
144+
else:
145+
raise
125146

126-
if raises is not None:
147+
else:
127148
exception_type = raises.get("type")
128149
message = raises.get("message")
129150

130151
try:
131-
result = self.example_py_code.expect_exceptions().run()
152+
result = to_run.expect_exceptions().run()
132153
result.exception_was_raised(exception_type)
133154
exception_message = self._story_friendly_output(
134155
result.exception.message
@@ -145,7 +166,7 @@ def run(self, code, will_output=None, raises=None):
145166
@no_stacktrace_for(AssertionError)
146167
def file_in_working_dir_contains(self, filename, contents):
147168
assert (
148-
self.path.working_dir.joinpath(filename).bytes().decode("utf8") == contents
169+
self.path.state.joinpath("..", "working", "working").joinpath(filename).bytes().decode("utf8") == contents
149170
)
150171

151172
@no_stacktrace_for(AssertionError)
@@ -154,12 +175,13 @@ def file_in_dir_contains(self, filename, contents):
154175

155176
@no_stacktrace_for(AssertionError)
156177
def file_written_by_code_contains(self, filename, contents):
178+
filepath = self.path.state / "working" / filename
157179
try:
158-
Templex(contents).assert_match(self.path.state.joinpath(filename).text())
180+
Templex(contents).assert_match(filepath.text())
159181
except AssertionError:
160182
if self.settings.get("rewrite"):
161183
self.current_step.update(
162-
contents=self.path.state.joinpath(filename).text()
184+
contents=filepath.text()
163185
)
164186
else:
165187
raise
@@ -174,16 +196,18 @@ def _storybook(settings):
174196
return StoryCollection(pathquery(DIR.key).ext("story"), Engine(DIR, settings))
175197

176198

177-
@expected(HitchStoryException)
178-
def bdd(*words):
199+
@cli.command()
200+
@argument("words", nargs=-1)
201+
def bdd(words):
179202
"""
180203
Run test with words.
181204
"""
182205
_storybook({"rewrite": False}).shortcut(*words).play()
183206

184207

185-
@expected(HitchStoryException)
186-
def rbdd(*words):
208+
@cli.command()
209+
@argument("words", nargs=-1)
210+
def rbdd(words):
187211
"""
188212
Run executable spec and rewrite if output has changed.
189213
"""
@@ -192,7 +216,7 @@ def rbdd(*words):
192216
).shortcut(*words).play()
193217

194218

195-
@expected(HitchStoryException)
219+
@cli.command()
196220
def regressfile(filename):
197221
"""
198222
Run all stories in filename 'filename'.
@@ -202,16 +226,18 @@ def regressfile(filename):
202226
).in_filename(filename).ordered_by_name().play().report()
203227

204228

229+
@cli.command()
205230
def regression():
206231
"""
207232
Regression test - run all tests and linter.
208233
"""
209-
lint()
234+
#toolkit.lint(exclude=["__init__.py"])
210235
StoryCollection(
211236
pathquery(DIR.key).ext("story"), Engine(DIR, {})
212237
).ordered_by_name().play()
213238

214239

240+
@cli.command()
215241
def rewriteall():
216242
"""
217243
Run regression tests with story rewriting on.
@@ -221,38 +247,45 @@ def rewriteall():
221247
).ordered_by_name().play().report()
222248

223249

250+
@cli.command()
224251
def reformat():
225252
"""
226253
Reformat using black and then relint.
227254
"""
228255
toolkit.reformat()
229256

230257

258+
@cli.command()
231259
def lint():
232260
"""
233261
Lint project code and hitch code.
234262
"""
235263
toolkit.lint(exclude=["__init__.py"])
236264

237265

266+
@cli.command()
238267
def deploy(version):
239268
"""
240269
Deploy to pypi as specified version.
241270
"""
242271
hitchpylibrarytoolkit.deploy(version)
243272

244273

245-
@expected(dirtemplate.exceptions.DirTemplateException)
274+
@cli.command()
246275
def docgen():
247276
"""
248277
Build documentation.
249278
"""
250279
toolkit.docgen(Engine(DIR, {}))
251280

252281

253-
@expected(dirtemplate.exceptions.DirTemplateException)
282+
@cli.command()
254283
def readmegen():
255284
"""
256285
Build documentation.
257286
"""
258287
toolkit.readmegen(Engine(DIR, {}))
288+
289+
290+
if __name__ == "__main__":
291+
cli()

hitch/story/basic.story

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ Setup code:
5050
)).with_setup_code("exampletext = 'exampletext'")\
5151
.run()
5252
- File in working dir contains:
53-
filename: working/examplefile
53+
filename: examplefile
5454
contents: exampletext

hitch/story/environment-vars.story

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ Run with environment variables:
1414
' handle.write(os.environ["MYVAR"])\n'
1515
)).run()
1616
- File in working dir contains:
17-
filename: working/examplefile
17+
filename: examplefile
1818
contents: myenvironmentvar

hitch/story/exception.story

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ Exceptions:
5757
\ [[ DIM ]][[ RED ]]None[[ RESET ALL ]]\n[[ RED ]]This should happen[[\
5858
\ RESET FORE ]]"
5959
Expect any kind of exception:
60-
with:
61-
working python version: 2.7.14
6260
steps:
6361
- Run:
6462
code: |

hitch/story/hitchrunpy.story

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ hitchrunpy:
88
import hitchbuildpy
99
import hitchbuild
1010

11+
BUILD_DIR = "/path/to/build_dir/.."
12+
1113
virtualenv = hitchbuildpy.VirtualenvBuild(
12-
name="py{{ pyver }}",
13-
base_python=hitchbuildpy.PyenvBuild("{{ pyver }}").with_build_path(
14-
'/path/to/share_dir/'
14+
"/path/to/build_dir/../py{{ pyver }}",
15+
base_python=hitchbuildpy.PyenvBuild(
16+
'/path/to/share_dir/../pyenv{{ pyver }}',
17+
"{{ pyver }}",
1518
),
16-
).with_build_path("/path/to/build_dir/")
19+
)
1720

18-
virtualenv.ensure_built()
21+
virtualenv.verify()
1922

2023
pyrunner = ExamplePythonCode(
2124
virtualenv.bin.python,

hitch/story/quickstart.story

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Run code until completion:
88
' handle.write("exampletext")'
99
)).run()
1010
- File in working dir contains:
11-
filename: working/examplefile
11+
filename: examplefile
1212
contents: exampletext

0 commit comments

Comments
 (0)