Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tp1_SORROCHE_loic #45

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e29d028
Adds function to "say hello"
rgt-yncrea Sep 19, 2022
001ab4a
Creates a decimal to binary converter
rgt-yncrea Sep 19, 2022
cd3b000
Adds a binary to decimal converter
rgt-yncrea Sep 19, 2022
96a3f84
Improves speed of conversion
rgt-yncrea Sep 19, 2022
ff5f0fa
Adds some documentation to converters
rgt-yncrea Sep 19, 2022
4c1e33d
Adds some input values check
rgt-yncrea Sep 19, 2022
c098a3b
Checks that only bits are passed to conv
rgt-yncrea Sep 19, 2022
2435632
Refactors bits verification
rgt-yncrea Sep 19, 2022
cb3af7e
Fixes bits check
rgt-yncrea Sep 19, 2022
7a6358a
Adds UT for converter
rgt-yncrea Sep 22, 2022
9d3866f
Fix converter bugs
rgt-yncrea Sep 22, 2022
8d24243
Merge pull request #1 from solDace/decimal-binary-converter
solDace Sep 29, 2022
03d74d1
Merge branch 'main' into dev
solDace Sep 29, 2022
305c0f2
Merge pull request #2 from solDace/dev
solDace Sep 29, 2022
acb13fd
Create python-publish.yml
solDace Sep 29, 2022
005823e
Create __init__.py
solDace Sep 29, 2022
11e2ea9
Create example.py
solDace Sep 29, 2022
a3463d1
Update example.py
solDace Sep 29, 2022
9dddf14
Create LICENSE
solDace Sep 29, 2022
6102561
Create pyproject.toml
solDace Sep 29, 2022
b97029f
Create README.md
solDace Sep 29, 2022
9ab0f06
Create test
solDace Sep 29, 2022
8fda273
Delete test
solDace Sep 29, 2022
2de89ad
Create test
solDace Sep 29, 2022
86fdadf
Rename test_main.py to packaging_tutorial/tests/test_main.py
solDace Sep 29, 2022
3e04e41
Delete test
solDace Sep 29, 2022
efa37da
Update and rename test_converter.py to packaging_tutorial/tests/test_…
solDace Sep 29, 2022
bb19550
Update pyproject.toml
solDace Sep 29, 2022
feed976
Update README.md
solDace Sep 29, 2022
1d5ac2a
Update LICENSE
solDace Sep 29, 2022
b56de73
Rename packaging_tutorial/tests/test_converter.py to test_converter.py
solDace Sep 29, 2022
3c60c3a
Rename packaging_tutorial/tests/test_main.py to test_main.py
solDace Sep 29, 2022
81b760a
Rename packaging_tutorial/src/example_package_YOUR_USERNAME_HERE/__in…
solDace Sep 29, 2022
254a1b8
Rename packaging_tutorial/src/example_package_YOUR_USERNAME_HERE/exam…
solDace Sep 29, 2022
94022f3
Rename converter.py to packaging_tutorial/src/example_package_loic_S/…
solDace Sep 29, 2022
5bb7121
Update test_converter.py
solDace Sep 29, 2022
6806308
Update test_converter.py
solDace Sep 29, 2022
80f2850
Update test_converter.py
solDace Sep 29, 2022
b56826c
Rename packaging_tutorial/pyproject.toml to pyproject.toml
solDace Sep 29, 2022
459fab1
Delete LICENSE
solDace Sep 29, 2022
1eab82a
Delete README.md
solDace Sep 29, 2022
912dd18
Rename packaging_tutorial/src/example_package_loic_S/__init__.py to s…
solDace Sep 29, 2022
1893588
Rename packaging_tutorial/src/example_package_loic_S/converter.py to …
solDace Sep 29, 2022
48aa292
Rename packaging_tutorial/src/example_package_loic_S/example.py to sr…
solDace Sep 29, 2022
b046a7e
Update test_converter.py
solDace Sep 29, 2022
fcf422e
Update pyproject.toml
solDace Sep 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
9 changes: 7 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from converter import dec_to_bin, bin_to_dec


def say_hello():
print("Say Hello !")
print("Hello")


if __name__ == '__main__':
say_hello()
print(*dec_to_bin(256))
print(bin_to_dec([1, 0, 1, 0, 0, 1]))
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "example_package_loic_S"
version = "0.0.1"
authors = [
{ name="Example Author", email="[email protected]" },
]
description = "A small example package"
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://github.com/pypa/sampleproject"
"Bug Tracker" = "https://github.com/pypa/sampleproject/issues"
1 change: 1 addition & 0 deletions src/example_package_loic_S/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

35 changes: 35 additions & 0 deletions src/example_package_loic_S/converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import List


def dec_to_bin(n: int) -> List[int]:
"""
Converts a positive integer to binary
:param n: int, decimal integer to convert to binary
:return: Binary translation of input number, as a list of 0s and 1
"""
if n < 0:
raise ValueError("n should be positive")

bit = [0 if n % 2 == 0 else 1]
return bit if n <= 1 else dec_to_bin(n >> 1) + bit


def bin_to_dec(bits_array: List[int]) -> int:
"""
Converts a list of 0s and 1s to its corresponding decimal representation
:param bits_array: list of 0s and 1s to convert
:return: int
"""
if not inputs_is_bits(bits_array):
raise ValueError("input should contain only bits (0 or 1)")

ba = bits_array.copy()
ba.reverse()
return sum([(1 << i) * m for i, m in enumerate(ba)])


def inputs_is_bits(bits_array):
for b in bits_array:
if b not in [0, 1]:
return False
return True
2 changes: 2 additions & 0 deletions src/example_package_loic_S/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def add_one(number):
return number + 1
31 changes: 31 additions & 0 deletions test_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from unittest import TestCase

from src.example_package_loic_S.converter import dec_to_bin, bin_to_dec


class TestConverter(TestCase):
def test_dec_to_bin_even(self):
n = 10
expected = [1, 0, 1, 0]
self.assertListEqual(expected, dec_to_bin(n))

def test_dec_to_bin_odd(self):
n = 37
expected = [1, 0, 0, 1, 0, 1]
self.assertListEqual(expected, dec_to_bin(n))

def test_bin_to_dec_odd(self):
bits = [1, 0, 0, 1, 0, 1]
expected = 37
self.assertEqual(expected, bin_to_dec(bits))

def test_bin_to_dec_even(self):
bits = [1, 0, 1, 0]
expected = 10
self.assertEqual(expected, bin_to_dec(bits))

def test_reverse(self):
n = 135
self.assertEqual(n, bin_to_dec(dec_to_bin(n)))