Skip to content

Commit 12a4925

Browse files
authored
Merge pull request #20 from kcelebi/dev
Modifying Package Structure, adding GitHub Actions
2 parents 2d84bfd + bba3338 commit 12a4925

31 files changed

+310
-110
lines changed

.github/workflows/publish.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish to PyPI.org
2+
#on: workflow_dispatch
3+
on:
4+
release:
5+
types: [published]
6+
jobs:
7+
pypi:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
- run: python3 -m pip install --upgrade build && python3 -m build
15+
- name: Publish package
16+
uses: pypa/gh-action-pypi-publish@release/v1
17+
with:
18+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/release.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Create a new patch release
2+
on: workflow_dispatch
3+
jobs:
4+
github:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v3
9+
- name: Create new patch release
10+
run: .github/workflows/scripts/release.py
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

.github/workflows/scripts/release.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
import json
3+
import subprocess
4+
5+
6+
def get_last_version() -> str:
7+
"""Return the version number of the last release."""
8+
json_string = (
9+
subprocess.run(
10+
["gh", "release", "view", "--json", "tagName"],
11+
check=True,
12+
stdout=subprocess.PIPE,
13+
stderr=subprocess.PIPE,
14+
)
15+
.stdout.decode("utf8")
16+
.strip()
17+
)
18+
19+
return json.loads(json_string)["tagName"]
20+
21+
22+
def bump_patch_number(version_number: str) -> str:
23+
"""Return a copy of `version_number` with the patch number incremented."""
24+
major, minor, patch = version_number.split(".")
25+
return f"{major}.{minor}.{int(patch) + 1}"
26+
27+
28+
def create_new_patch_release():
29+
"""Create a new patch release on GitHub."""
30+
try:
31+
last_version_number = get_last_version()
32+
except subprocess.CalledProcessError as err:
33+
'''if err.stderr.decode("utf8").startswith("HTTP 404:"):
34+
# The project doesn't have any releases yet.
35+
new_version_number = "0.0.1"
36+
else:
37+
raise'''
38+
new_version_number = "0.0.1"
39+
else:
40+
new_version_number = bump_patch_number(last_version_number)
41+
42+
subprocess.run(
43+
["gh", "release", "create", "--generate-notes", new_version_number],
44+
check=True,
45+
)
46+
47+
48+
if __name__ == "__main__":
49+
create_new_patch_release()

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ riscv_assembler/prjtest.pybuild
33
dist
44
riscv_assembler.egg-info
55
build
6+
.pytest_cache/
7+
__pycache__/

setup.py renamed to deprc_setup.py

File renamed without changes.

riscv_assembler/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.
-402 Bytes
Binary file not shown.
-407 Bytes
Binary file not shown.
-266 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-4.31 KB
Binary file not shown.
-2.54 KB
Binary file not shown.
Binary file not shown.
-6.51 KB
Binary file not shown.
-5.96 KB
Binary file not shown.

riscv_assembler/parse.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

setup.cfg

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[metadata]
2+
name = riscv-assembler
3+
author = Kaya Celebi
4+
author_email = kayacelebi17@gmail.com
5+
description = RISC-V Assembly code assembler package for Python.
6+
long_description = file: README.md
7+
long_description_content_type = text/markdown
8+
url = https://github.com/kcelebi/riscv-assembler
9+
project_urls =
10+
Bug Tracker = https://github.com/kcelebi/riscv-assembler/issues
11+
Changelog = https://github.com/kcelebi/riscv-assembler/releases
12+
classifiers =
13+
Programming Language :: Python :: 3
14+
License :: OSI Approved :: MIT License
15+
Intended Audience :: Developers
16+
17+
[options]
18+
package_dir =
19+
= src
20+
packages = find:
21+
python_requires = >=3.6
22+
install_requires =
23+
bitstring
24+
25+
[options.packages.find]
26+
where = src
27+
28+
[options.package_data]
29+
* = data/*.dat
30+
31+
[options.entry_points]
32+
console_scripts =
33+
riscv_assembler = riscv_assembler.app:entry_point

src/riscv_assembler/__init__.py

Whitespace-only changes.

riscv_assembler/convert.py renamed to src/riscv_assembler/convert.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
- Update tests
1313
'''
1414

15-
from riscv_assembler.instr_arr import *
16-
from riscv_assembler.parse import *
15+
from src.riscv_assembler.instr_arr import *
16+
from src.riscv_assembler.parse import *
1717

1818
__all__ = ['AssemblyConverter']
1919

@@ -45,6 +45,9 @@ def clone(self):
4545
hex_mode = self.__hex_mode
4646
)
4747

48+
def __call__(self, *args):
49+
return self.convert(*args)
50+
4851
def __check_output_mode(self, x) -> str:
4952
mod = ''.join(sorted(x.split()))
5053
assert mod in ['a', 'f', 'p', None], "Output Mode needs to be one of a(rray), f(ile), p(rint), or None."
@@ -110,15 +113,16 @@ def convert(self, input : str, file : str = None):
110113
return output
111114
elif self.__output_mode == 'f':
112115
assert file != None, "For output mode to file, need to provided file name."
113-
self.write_to_file(output, file)
116+
AssemblyConverter.write_to_file(output, file)
114117
return
115118
elif self.__output_mode == 'p':
116119
print(output)
117120
return
118121

119122
raise NotImplementedError()
120123

121-
def write_to_file(self, output : list, file : str) -> None:
124+
@staticmethod
125+
def write_to_file(output : list, file : str) -> None:
122126
extension = file[-4:]
123127

124128
if extension == '.bin':
@@ -159,4 +163,3 @@ def apply_nibble(output : list) -> list:
159163
def apply_hex(output : list) -> list:
160164
raise NotImplementedError()
161165
return ...
162-
File renamed without changes.

riscv_assembler/instr_arr.py renamed to src/riscv_assembler/instr_arr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ def compute_instr(self, instr, imm, rd):
170170

171171
@staticmethod
172172
def immediate(imm):
173-
mod_imm = format(((1 << 20) - 1) & int(imm), '013b')
174-
return mod_imm[20-20] + mod_imm[20-10:20-1] + mod_imm[20-11] + mod_imm[20-19:20-12]
173+
mod_imm = format(((1 << 21) - 1) & int(imm), '021b')
174+
return mod_imm[20-20] + mod_imm[20-10:20-0] + mod_imm[20-11] + mod_imm[20-19:20-11]
175175

176176
class InstructionParser:
177177
def organize(self, *args):

0 commit comments

Comments
 (0)