Skip to content

Commit

Permalink
Reorganize project to allow building Python package from the main rep…
Browse files Browse the repository at this point in the history
…ository
  • Loading branch information
althonos committed May 3, 2023
1 parent bd04910 commit 5ad505b
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 16 deletions.
145 changes: 143 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,143 @@
/target
/Cargo.lock

# Created by https://www.gitignore.io/api/rust,python
# Edit at https://www.gitignore.io/?templates=rust,python

callgrind.out.*

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

### Rust ###
# Generated by Cargo
# will have compiled files and executables
/target/
.cargo
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# cargo vendor
.cargo/config.toml
crates/

# End of https://www.gitignore.io/api/rust,python
14 changes: 14 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include setup.*
include COPYING
include CHANGELOG.md
include README.md
include pyproject.toml

exclude Cargo.toml
exclude Cargo.lock

recursive-include lightmotif *.rs Cargo.toml README.md
recursive-include lightmotif-py* *.rs Cargo.toml README.md *.py

include .cargo/config.toml
recursive-include crates *
2 changes: 1 addition & 1 deletion lightmotif-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build = "build.rs"

[lib]
crate-type = ["cdylib", "rlib"]
path = "lightmotif/lib/lib.rs"
path = "lightmotif/lib.rs"

[build-dependencies.built]
version = "0.6"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lightmotif-py/lightmotif/tests/test_dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
class TestDNAMotif(unittest.TestCase):

def test_calculate(self):
counts = lightmotif.create(["GTTGACCTTATCAAC", "GTTGATCCAGTCAAC"])
frequencies = counts.normalize(0.1)
motif = lightmotif.create(["GTTGACCTTATCAAC", "GTTGATCCAGTCAAC"])
frequencies = motif.counts.normalize(0.1)
pssm = frequencies.log_odds()

seq = lightmotif.EncodedSequence(SEQUENCE)
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = ['setuptools', 'setuptools_rust']
build-backend = "setuptools.build_meta"

13 changes: 9 additions & 4 deletions lightmotif-py/setup.cfg → setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author = Martin Larralde
author_email = [email protected]
home_page = https://github.com/althonos/lightmotif
description = PyO3 bindings and Python interface to lightmotif, a library for platform-accelerated biological motif scanning using position weight matrices.
long_description = file: README.md
long_description = file: lightmotif-py/README.md
long_description_content_type = text/markdown
license = MIT
platform = any
Expand Down Expand Up @@ -40,9 +40,13 @@ project_urls =

[options]
zip_safe = true
package_dir =
lightmotif = lightmotif-py
lightmotif.lib = lightmotif-py
lightmotif.tests = lightmotif-py
packages =
lightmotif
lightmotif._lib
lightmotif.lib
lightmotif.tests
test_suite = lightmotif.tests
python_requires = >=3.7
Expand All @@ -54,9 +58,10 @@ setup_requires =
lightmotif =
py.typed
*.pyi
lightmotif._lib =
lightmotif.lib =
*.rs
lightmotif.tests =
*.rs
requirements.txt

[bdist_wheel]
Expand Down Expand Up @@ -94,4 +99,4 @@ warn_unused_ignores = true
warn_return_any = true

[mypy-lightmotif.tests.*]
ignore_errors = True
ignore_errors = True
14 changes: 7 additions & 7 deletions lightmotif-py/setup.py → setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ def setup_temp_rustc_unix(self, toolchain, profile):

def get_dylib_ext_path(self, ext, module_name):
ext_path = _build_rust.get_dylib_ext_path(self, ext, module_name)
if self.inplace:
base = os.path.basename(ext_path)
folder = os.path.dirname(os.path.realpath(__file__))
prefix = os.path.sep.join(ext.name.split(".")[:-1])
ext_path = os.path.join(folder, prefix, base)
# if self.inplace:
# base = os.path.basename(ext_path)
# folder = os.path.dirname(os.path.realpath(__file__))
# prefix = os.path.sep.join(ext.name.split(".")[:-1])
# ext_path = os.path.join(folder, prefix, base)
return ext_path


# HACK: Use the `configparser` from Python to read the `Cargo.toml`
# manifest file (this... works) so that the package version
# can be extracted from there and synchronized everywhere.
parser = configparser.ConfigParser()
parser.read(os.path.join(os.path.dirname(__file__), "Cargo.toml"))
parser.read(os.path.join(os.path.dirname(__file__), "lightmotif-py", "Cargo.toml"))
version = parser.get("package", "version").strip('"')

setuptools.setup(
Expand All @@ -107,7 +107,7 @@ def get_dylib_ext_path(self, ext, module_name):
cmdclass=dict(sdist=sdist, build_rust=build_rust),
rust_extensions=[rust.RustExtension(
"lightmotif.lib",
path="Cargo.toml",
path=os.path.join("lightmotif-py", "Cargo.toml"),
binding=rust.Binding.PyO3,
strip=rust.Strip.Debug,
features=["extension-module"],
Expand Down

0 comments on commit 5ad505b

Please sign in to comment.